Skip to content

Commit 9a97c3b

Browse files
committed
cmd/go: accept plain file for .vcs (instead of directory)
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]>
1 parent d26b066 commit 9a97c3b

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/cmd/go/vcs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ func vcsFromDir(dir, srcRoot string) (vcs *vcsCmd, root string, err error) {
500500
origDir := dir
501501
for len(dir) > len(srcRoot) {
502502
for _, vcs := range vcsList {
503-
if fi, err := os.Stat(filepath.Join(dir, "."+vcs.cmd)); err == nil && fi.IsDir() {
503+
if _, err := os.Stat(filepath.Join(dir, "."+vcs.cmd)); err == nil {
504504
return vcs, filepath.ToSlash(dir[len(srcRoot)+1:]), nil
505505
}
506506
}

src/cmd/go/vcs_test.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestRepoRootForImportPath(t *testing.T) {
102102
"git.openstack.org/openstack/swift.git",
103103
&repoRoot{
104104
vcs: vcsGit,
105-
repo: "https://git.openstack.org/openstack/swift",
105+
repo: "https://git.openstack.org/openstack/swift.git",
106106
},
107107
},
108108
{
@@ -174,11 +174,23 @@ func TestFromDir(t *testing.T) {
174174
}
175175
defer os.RemoveAll(tempDir)
176176

177-
for _, vcs := range vcsList {
177+
for j, vcs := range vcsList {
178178
dir := filepath.Join(tempDir, "example.com", vcs.name, "."+vcs.cmd)
179-
err := os.MkdirAll(dir, 0755)
180-
if err != nil {
181-
t.Fatal(err)
179+
if j&1 == 0 {
180+
err := os.MkdirAll(dir, 0755)
181+
if err != nil {
182+
t.Fatal(err)
183+
}
184+
} else {
185+
err := os.MkdirAll(filepath.Dir(dir), 0755)
186+
if err != nil {
187+
t.Fatal(err)
188+
}
189+
f, err := os.Create(dir)
190+
if err != nil {
191+
t.Fatal(err)
192+
}
193+
f.Close()
182194
}
183195

184196
want := repoRoot{

0 commit comments

Comments
 (0)