Skip to content

Sanitize and Escape refs in git backend (#21464) #21463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Oct 15, 2022
5 changes: 2 additions & 3 deletions modules/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

// GitVersionRequired is the minimum Git version required
const GitVersionRequired = "2.0.0"
const GitVersionRequired = "2.24.0"

var (
// GitExecutable is the command name of git
Expand Down Expand Up @@ -117,8 +117,7 @@ func VersionInfo() string {
}
format := "%s"
args := []interface{}{gitVersion.Original()}
// Since git wire protocol has been released from git v2.18
if setting.Git.EnableAutoGitWireProtocol && CheckGitVersionAtLeast("2.18") == nil {
if setting.Git.EnableAutoGitWireProtocol {
format += ", Wire Protocol %s Enabled"
args = append(args, "Version 2") // for focus color
}
Expand Down
7 changes: 4 additions & 3 deletions modules/git/repo_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (repo *Repository) searchCommits(id SHA1, opts SearchCommitsOptions) ([]*Co
// add previous arguments except for --grep and --all
hashCmd.AddArguments(args...)
// add keyword as <commit>
hashCmd.AddArguments(v)
hashCmd.AddArguments("--end-of-options", v)

// search with given constraints for commit matching sha hash of v
hashMatching, _, err := hashCmd.RunStdBytes(&RunOpts{Dir: repo.Path})
Expand Down Expand Up @@ -208,9 +208,10 @@ func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (
}()
go func() {
stderr := strings.Builder{}
err := NewCommand(repo.Ctx, "log", revision, "--follow",
err := NewCommand(repo.Ctx, "log", prettyLogFormat, "--follow",
"--max-count="+strconv.Itoa(setting.Git.CommitsRangeSize*page),
prettyLogFormat, "--", file).
"--end-of-options", revision,
"--", file).
Run(&RunOpts{
Dir: repo.Path,
Stdout: stdoutWriter,
Expand Down
2 changes: 1 addition & 1 deletion modules/git/repo_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
if len(branch) == 0 {
args = append(args, "--branches=*")
} else {
args = append(args, "--first-parent", branch)
args = append(args, "--first-parent", "--", branch)
}

stderr := new(strings.Builder)
Expand Down