Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 0073a49

Browse files
committed
Allow non-.git path for ls example
Signed-off-by: Filip Navara <[email protected]>
1 parent d8471a3 commit 0073a49

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

_examples/ls/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@ func main() {
3131

3232
// We instantiate a new repository targeting the given path (the .git folder)
3333
fs := osfs.New(path)
34+
if _, err := fs.Stat(git.GitDirName); err == nil {
35+
fs, err = fs.Chroot(git.GitDirName)
36+
CheckIfError(err)
37+
}
38+
3439
s := filesystem.NewStorageWithOptions(fs, cache.NewObjectLRUDefault(), filesystem.Options{KeepDescriptors: true})
3540
r, err := git.Open(s, fs)
3641
CheckIfError(err)
42+
defer s.Close()
3743

3844
// Resolve revision into a sha1 commit, only some revisions are resolved
3945
// look at the doc to get more details
@@ -73,8 +79,6 @@ func main() {
7379
line := strings.Split(rev.Message, "\n")
7480
fmt.Println(path, hash[:7], line[0])
7581
}
76-
77-
s.Close()
7882
}
7983

8084
func getCommitNodeIndex(r *git.Repository, fs billy.Filesystem) (commitgraph.CommitNodeIndex, io.ReadCloser) {

0 commit comments

Comments
 (0)