]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: accept plain file for .vcs (instead of directory)
authorRuss Cox <rsc@golang.org>
Thu, 13 Oct 2016 17:45:31 +0000 (13:45 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 17 Oct 2016 17:05:39 +0000 (17:05 +0000)
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 <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/vcs.go
src/cmd/go/vcs_test.go

index 8a8ee4d3494685ab044d830c46c2f3097de7ffb4..06251a938d4084bcf84b716f3ef1d6aadd6fbe4f 100644 (file)
@@ -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
                        }
                }
index 9d8475139884cc6c7f60b18fe2900a4675cb4419..798f6683a6619cc22f4133c21ae7a4a69337887d 100644 (file)
@@ -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{