Skip to content

Commit

Permalink
cmd/go: accept plain file for .vcs (instead of directory)
Browse files Browse the repository at this point in the history
Sometimes .git is a plain file; maybe others will follow.
This CL matches CL 21430, made in x/tools/go/vcs.

The change in the Swift test case makes the test case
pass by changing the test to match current behavior,
which I assume is better than the reverse.
(The test only runs locally and without -short, so the
builders are not seeing this particular failure.)

For #10322.

Change-Id: Iccd08819a01c5609a2880b9d8a99af936e20faff
Reviewed-on: https://go-review.googlesource.com/30948
Run-TryBot: Russ Cox <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
rsc committed Oct 17, 2016
1 parent d26b066 commit 9a97c3b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/cmd/go/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ func vcsFromDir(dir, srcRoot string) (vcs *vcsCmd, root string, err error) {
origDir := dir
for len(dir) > len(srcRoot) {
for _, vcs := range vcsList {
if fi, err := os.Stat(filepath.Join(dir, "."+vcs.cmd)); err == nil && fi.IsDir() {
if _, err := os.Stat(filepath.Join(dir, "."+vcs.cmd)); err == nil {
return vcs, filepath.ToSlash(dir[len(srcRoot)+1:]), nil
}
}
Expand Down
22 changes: 17 additions & 5 deletions src/cmd/go/vcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestRepoRootForImportPath(t *testing.T) {
"git.openstack.org/openstack/swift.git",
&repoRoot{
vcs: vcsGit,
repo: "https://git.openstack.org/openstack/swift",
repo: "https://git.openstack.org/openstack/swift.git",
},
},
{
Expand Down Expand Up @@ -174,11 +174,23 @@ func TestFromDir(t *testing.T) {
}
defer os.RemoveAll(tempDir)

for _, vcs := range vcsList {
for j, vcs := range vcsList {
dir := filepath.Join(tempDir, "example.com", vcs.name, "."+vcs.cmd)
err := os.MkdirAll(dir, 0755)
if err != nil {
t.Fatal(err)
if j&1 == 0 {
err := os.MkdirAll(dir, 0755)
if err != nil {
t.Fatal(err)
}
} else {
err := os.MkdirAll(filepath.Dir(dir), 0755)
if err != nil {
t.Fatal(err)
}
f, err := os.Create(dir)
if err != nil {
t.Fatal(err)
}
f.Close()
}

want := repoRoot{
Expand Down

0 comments on commit 9a97c3b

Please sign in to comment.