Skip to content

Commit

Permalink
Merge pull request #61 from motemen/fix-list-symlink
Browse files Browse the repository at this point in the history
Fix an issue of listing with directories containing symlinks
  • Loading branch information
motemen committed Aug 6, 2015
2 parents e53e2eb + 50ab65c commit 2a1f032
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion local_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ var vcsDirs = []string{".git", ".svn", ".hg", "_darcs"}
func walkLocalRepositories(callback func(*LocalRepository)) {
for _, root := range localRepositoryRoots() {
filepath.Walk(root, func(path string, fileInfo os.FileInfo, err error) error {
if err != nil || fileInfo == nil || fileInfo.IsDir() == false {
if err != nil || fileInfo == nil || (fileInfo.IsDir() == false && fileInfo.Mode()&os.ModeSymlink == 0) {
// ghq.root can contain regular files.
if root == filepath.Dir(path) {
return nil
Expand Down
31 changes: 31 additions & 0 deletions local_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
. "github.com/onsi/gomega"
"io/ioutil"
"path/filepath"
"testing"
)

Expand Down Expand Up @@ -68,3 +70,32 @@ func TestLocalRepositoryRoots(t *testing.T) {

Expect(localRepositoryRoots()).To(Equal([]string{"/path/to/ghqroot"}))
}

// https://gist.github.com/kyanny/c231f48e5d08b98ff2c3
func TestList_Symlink(t *testing.T) {
RegisterTestingT(t)

root, err := ioutil.TempDir("", "")
Expect(err).To(BeNil())

symDir, err := ioutil.TempDir("", "")
Expect(err).To(BeNil())

_localRepositoryRoots = []string{root}

err = os.MkdirAll(filepath.Join(root, "github.com", "atom", "atom", ".git"), 0777)
Expect(err).To(BeNil())

err = os.MkdirAll(filepath.Join(root, "github.com", "zabbix", "zabbix", ".git"), 0777)
Expect(err).To(BeNil())

err = os.Symlink(symDir, filepath.Join(root, "github.com", "ghq"))
Expect(err).To(BeNil())

paths := []string{}
walkLocalRepositories(func(repo *LocalRepository) {
paths = append(paths, repo.RelPath)
})

Expect(paths).To(HaveLen(2))
}

0 comments on commit 2a1f032

Please sign in to comment.