Skip to content

Commit

Permalink
s/vcsDirs/vcsContents/ because they are not always directories.
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed May 5, 2019
1 parent e7ba0ab commit b88534d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func withFakeGitBackend(t *testing.T, block func(*testing.T, string, *_cloneArgs
},
}
GitBackend = tmpBackend
vcsDirsMap[".git"] = tmpBackend
defer func() { GitBackend = originalGitBackend; vcsDirsMap[".git"] = originalGitBackend }()
vcsContentsMap[".git"] = tmpBackend
defer func() { GitBackend = originalGitBackend; vcsContentsMap[".git"] = originalGitBackend }()

block(t, tmpRoot, &cloneArgs, &updateArgs)
}
Expand Down
24 changes: 12 additions & 12 deletions local_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,36 +126,36 @@ func (repo *LocalRepository) VCS() *VCSBackend {
return repo.vcsBackend
}

var vcsDirsMap = map[string]*VCSBackend{
var vcsContentsMap = map[string]*VCSBackend{
".git/svn": GitsvnBackend,
".git": GitBackend,
".svn": SubversionBackend,
".hg": MercurialBackend,
"_darcs": DarcsBackend,
".fslckout": FossilBackend,
"_FOSSIL_": FossilBackend,
".fslckout": FossilBackend, // file
"_FOSSIL_": FossilBackend, // file
"CVS": cvsDummyBackend,
".bzr": BazaarBackend,
}

var vcsDirs = make([]string, 0, len(vcsDirsMap))
var vcsContents = make([]string, 0, len(vcsContentsMap))

func init() {
for k := range vcsDirsMap {
vcsDirs = append(vcsDirs, k)
for k := range vcsContentsMap {
vcsContents = append(vcsContents, k)
}
// Sort in order of length.
// This is to check git/svn before git.
sort.Slice(vcsDirs, func(i, j int) bool {
return len(vcsDirs[i]) > len(vcsDirs[j])
sort.Slice(vcsContents, func(i, j int) bool {
return len(vcsContents[i]) > len(vcsContents[j])
})
}

func findVCSBackend(fpath string) *VCSBackend {
for _, d := range vcsDirs {
fi, err := os.Stat(filepath.Join(fpath, d))
if err == nil && fi.IsDir() {
return vcsDirsMap[d]
for _, d := range vcsContents {
_, err := os.Stat(filepath.Join(fpath, d))
if err == nil {
return vcsContentsMap[d]
}
}
return nil
Expand Down

0 comments on commit b88534d

Please sign in to comment.