diff options
author | Filip Navara <filip.navara@gmail.com> | 2019-05-07 12:26:55 +0200 |
---|---|---|
committer | Filip Navara <filip.navara@gmail.com> | 2019-05-07 12:26:55 +0200 |
commit | 0073a49b9575c2e64676485ca5126641510c6db5 (patch) | |
tree | d2ee1e6a8b798e2bb35eb0e71c5d870cb35a38a8 /_examples | |
parent | d8471a32b6c3ab4521ee47db4c7f7b78f0a8363b (diff) | |
download | go-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.go | 8 |
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) { |