From 0073a49b9575c2e64676485ca5126641510c6db5 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Tue, 7 May 2019 12:26:55 +0200 Subject: Allow non-.git path for ls example Signed-off-by: Filip Navara --- _examples/ls/main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to '_examples/ls/main.go') diff --git a/_examples/ls/main.go b/_examples/ls/main.go index bbd40d5..bb686f1 100644 --- a/_examples/ls/main.go +++ b/_examples/ls/main.go @@ -31,9 +31,15 @@ func main() { // We instantiate a new repository targeting the given path (the .git folder) fs := osfs.New(path) + if _, err := fs.Stat(git.GitDirName); err == nil { + fs, err = fs.Chroot(git.GitDirName) + CheckIfError(err) + } + s := filesystem.NewStorageWithOptions(fs, cache.NewObjectLRUDefault(), filesystem.Options{KeepDescriptors: true}) r, err := git.Open(s, fs) CheckIfError(err) + defer s.Close() // Resolve revision into a sha1 commit, only some revisions are resolved // look at the doc to get more details @@ -73,8 +79,6 @@ func main() { line := strings.Split(rev.Message, "\n") fmt.Println(path, hash[:7], line[0]) } - - s.Close() } func getCommitNodeIndex(r *git.Repository, fs billy.Filesystem) (commitgraph.CommitNodeIndex, io.ReadCloser) { -- cgit