aboutsummaryrefslogtreecommitdiffstats
path: root/_examples
diff options
context:
space:
mode:
authorFilip Navara <filip.navara@gmail.com>2019-05-07 12:26:55 +0200
committerFilip Navara <filip.navara@gmail.com>2019-05-07 12:26:55 +0200
commit0073a49b9575c2e64676485ca5126641510c6db5 (patch)
treed2ee1e6a8b798e2bb35eb0e71c5d870cb35a38a8 /_examples
parentd8471a32b6c3ab4521ee47db4c7f7b78f0a8363b (diff)
downloadgo-git-0073a49b9575c2e64676485ca5126641510c6db5.tar.gz
Allow non-.git path for ls example
Signed-off-by: Filip Navara <filip.navara@gmail.com>
Diffstat (limited to '_examples')
-rw-r--r--_examples/ls/main.go8
1 files changed, 6 insertions, 2 deletions
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) {