diff options
author | John Cai <jcai@gitlab.com> | 2023-02-17 01:01:59 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2023-03-04 00:51:09 +0300 |
commit | d47eef8f6b234b30d4034e1c5d2febad83e373af (patch) | |
tree | a7c9a8280b8b6be79ca7b1ef61bf06a157eba9ad | |
parent | 9bae0c4c236ef5d5a2f707cd369c458dd16816bf (diff) |
lstree: Rewrite path if it's "."
When we call git-ls-stree(1), we use the form <treeish>:<path>. When "."
is used for <path>, git rejects it as an invalid object. Fix this by,
automatically rewriting "." to "" since callers might pass in ".".
-rw-r--r-- | internal/git/lstree/list_entries.go | 7 | ||||
-rw-r--r-- | internal/gitaly/service/commit/tree_entries.go | 4 |
2 files changed, 6 insertions, 5 deletions
diff --git a/internal/git/lstree/list_entries.go b/internal/git/lstree/list_entries.go index d8cb5acc5..d5f693cb0 100644 --- a/internal/git/lstree/list_entries.go +++ b/internal/git/lstree/list_entries.go @@ -50,10 +50,15 @@ func ListEntries( ) } + relativePath := cfg.RelativePath + if relativePath == "." { + relativePath = "" + } + var stderr bytes.Buffer cmd, err := repo.Exec(ctx, git.Command{ Name: "ls-tree", - Args: []string{fmt.Sprintf("%s:%s", treeish, cfg.RelativePath)}, + Args: []string{fmt.Sprintf("%s:%s", treeish, relativePath)}, Flags: flags, }, git.WithStderr(&stderr)) if err != nil { diff --git a/internal/gitaly/service/commit/tree_entries.go b/internal/gitaly/service/commit/tree_entries.go index b1aa9e111..3c62cfa07 100644 --- a/internal/gitaly/service/commit/tree_entries.go +++ b/internal/gitaly/service/commit/tree_entries.go @@ -98,10 +98,6 @@ func (s *server) sendTreeEntries( // git-ls-tree(1) is worse than using a long-lived catfile process. We thus fall back to // using catfile readers to answer these non-recursive queries. if recursive { - if path == "." { - path = "" - } - rootTreeInfo, err := repo.ResolveRevision(ctx, git.Revision(revision+"^{tree}")) if err != nil { if errors.Is(err, git.ErrReferenceNotFound) { |