Skip to content

Commit b44548a

Browse files
committed
go/vcs: accept plain file for .vcs (instead of directory)
Sometimes .git is a plain file; maybe others will follow. Fixes golang/go#10322. Change-Id: Id57424998c207080c3ed5826b1e5e091fa26aad5 Reviewed-on: https://go-review.googlesource.com/21430 Run-TryBot: Russ Cox <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent a2b1312 commit b44548a

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

go/vcs/vcs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func FromDir(dir, srcRoot string) (vcs *Cmd, root string, err error) {
347347
origDir := dir
348348
for len(dir) > len(srcRoot) {
349349
for _, vcs := range vcsList {
350-
if fi, err := os.Stat(filepath.Join(dir, "."+vcs.Cmd)); err == nil && fi.IsDir() {
350+
if _, err := os.Stat(filepath.Join(dir, "."+vcs.Cmd)); err == nil {
351351
return vcs, filepath.ToSlash(dir[len(srcRoot)+1:]), nil
352352
}
353353
}

go/vcs/vcs_test.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,23 @@ func TestFromDir(t *testing.T) {
5656
}
5757
defer os.RemoveAll(tempDir)
5858

59-
for _, vcs := range vcsList {
59+
for j, vcs := range vcsList {
6060
dir := filepath.Join(tempDir, "example.com", vcs.Name, "."+vcs.Cmd)
61-
err := os.MkdirAll(dir, 0755)
62-
if err != nil {
63-
t.Fatal(err)
61+
if j&1 == 0 {
62+
err := os.MkdirAll(dir, 0755)
63+
if err != nil {
64+
t.Fatal(err)
65+
}
66+
} else {
67+
err := os.MkdirAll(filepath.Dir(dir), 0755)
68+
if err != nil {
69+
t.Fatal(err)
70+
}
71+
f, err := os.Create(dir)
72+
if err != nil {
73+
t.Fatal(err)
74+
}
75+
f.Close()
6476
}
6577

6678
want := RepoRoot{

0 commit comments

Comments
 (0)