diff --git a/internal/gitaly/service/commit/last_commit_for_path.go b/internal/gitaly/service/commit/last_commit_for_path.go index 5c6a1cbce9480c0d36c8b4831151c6e757a1bed7..92800b416014365ba3959fc53772d1c564f54836 100644 --- a/internal/gitaly/service/commit/last_commit_for_path.go +++ b/internal/gitaly/service/commit/last_commit_for_path.go @@ -29,6 +29,8 @@ func (s *server) lastCommitForPath(ctx context.Context, in *gitalypb.LastCommitF path = "." } + safePath := "./" + path + repo := in.GetRepository() c, err := catfile.New(ctx, s.gitCmdFactory, repo) if err != nil { @@ -48,7 +50,7 @@ func (s *server) lastCommitForPath(ctx context.Context, in *gitalypb.LastCommitF options.LiteralPathspecs = true } - commit, err := log.LastCommitForPath(ctx, s.gitCmdFactory, c, repo, git.Revision(in.GetRevision()), path, options) + commit, err := log.LastCommitForPath(ctx, s.gitCmdFactory, c, repo, git.Revision(in.GetRevision()), safePath, options) if log.IsNotFound(err) { return &gitalypb.LastCommitForPathResponse{}, nil } diff --git a/internal/gitaly/service/commit/list_last_commits_for_tree.go b/internal/gitaly/service/commit/list_last_commits_for_tree.go index 7c4adc05971cff9787e60ea133570d28489e3475..d5b8d747cde77814dd18a70dac6f27ce0a9116cc 100644 --- a/internal/gitaly/service/commit/list_last_commits_for_tree.go +++ b/internal/gitaly/service/commit/list_last_commits_for_tree.go @@ -122,11 +122,13 @@ func (s *server) newLSTreeParser(in *gitalypb.ListLastCommitsForTreeRequest, str path = "." } + safePath := "./" + path + opts := git.ConvertGlobalOptions(in.GetGlobalOptions()) cmd, err := s.gitCmdFactory.New(stream.Context(), in.GetRepository(), git.SubCmd{ Name: "ls-tree", Flags: []git.Option{git.Flag{Name: "-z"}, git.Flag{Name: "--full-name"}}, - Args: []string{in.GetRevision(), path}, + Args: []string{in.GetRevision(), safePath}, }, opts...) if err != nil { return nil, nil, err