Skip to content

Commit

Permalink
Merge pull request #168 from motemen/root-behavior
Browse files Browse the repository at this point in the history
even if the GHQ_ROOT directory doesn't exist, don't raise an error
  • Loading branch information
Songmu authored May 10, 2019
2 parents 2aeefa5 + 4485572 commit 249d74b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 20 additions & 1 deletion list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,26 @@ func TestDoList_unknownRoot(t *testing.T) {
os.Setenv("GHQ_ROOT", "/path/to/unknown-ghq")

err := newApp().Run([]string{"ghq", "list"})
if !os.IsNotExist(xerrors.Unwrap(err)) {
if err != nil {
t.Errorf("error should be nil, but: %s", err)
}
}

func TestDoList_notPermittedRoot(t *testing.T) {
defer func(orig []string) { _localRepositoryRoots = orig }(_localRepositoryRoots)
defer func(orig string) { os.Setenv("GHQ_ROOT", orig) }(os.Getenv("GHQ_ROOT"))
tmpdir := newTempDir(t)
defer func(dir string) {
os.Chmod(dir, 0755)
os.RemoveAll(dir)
}(tmpdir)

_localRepositoryRoots = nil
os.Setenv("GHQ_ROOT", tmpdir)
os.Chmod(tmpdir, 0000)

err := newApp().Run([]string{"ghq", "list"})
if !os.IsPermission(xerrors.Unwrap(err)) {
t.Errorf("error should be ErrNotExist, but: %s", err)
}
}
3 changes: 3 additions & 0 deletions local_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ func walkLocalRepositories(callback func(*LocalRepository)) error {
for _, root := range roots {
if err := filepath.Walk(root, func(fpath string, fi os.FileInfo, err error) error {
if err != nil || fi == nil {
if err == nil || os.IsNotExist(err) {
return nil
}
return err
}
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
Expand Down

0 comments on commit 249d74b

Please sign in to comment.