From: Russ Cox Date: Thu, 13 Oct 2016 17:45:31 +0000 (-0400) Subject: cmd/go: accept plain file for .vcs (instead of directory) X-Git-Tag: go1.8beta1~840 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9a97c3bfe41d1ed768ea3bd3d8f0f52b8a51bb62;p=gostls13.git 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/cmd/go/vcs.go b/src/cmd/go/vcs.go index 8a8ee4d349..06251a938d 100644 --- a/src/cmd/go/vcs.go +++ b/src/cmd/go/vcs.go @@ -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 } } diff --git a/src/cmd/go/vcs_test.go b/src/cmd/go/vcs_test.go index 9d84751398..798f6683a6 100644 --- a/src/cmd/go/vcs_test.go +++ b/src/cmd/go/vcs_test.go @@ -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", }, }, { @@ -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{