Delete old git.NewCommand() and use it as git.NewCommandContext() (#18552)
This commit is contained in:
parent
8ae5e6d7fd
commit
3043eb36bf
74 changed files with 258 additions and 263 deletions
|
@ -40,13 +40,13 @@ func (repo *Repository) GetMergeBase(tmpRemote, base, head string) (string, stri
|
|||
if tmpRemote != "origin" {
|
||||
tmpBaseName := RemotePrefix + tmpRemote + "/tmp_" + base
|
||||
// Fetch commit into a temporary branch in order to be able to handle commits and tags
|
||||
_, err := NewCommandContext(repo.Ctx, "fetch", tmpRemote, base+":"+tmpBaseName).RunInDir(repo.Path)
|
||||
_, err := NewCommand(repo.Ctx, "fetch", tmpRemote, base+":"+tmpBaseName).RunInDir(repo.Path)
|
||||
if err == nil {
|
||||
base = tmpBaseName
|
||||
}
|
||||
}
|
||||
|
||||
stdout, err := NewCommandContext(repo.Ctx, "merge-base", "--", base, head).RunInDir(repo.Path)
|
||||
stdout, err := NewCommand(repo.Ctx, "merge-base", "--", base, head).RunInDir(repo.Path)
|
||||
return strings.TrimSpace(stdout), base, err
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string,
|
|||
|
||||
// We have a common base - therefore we know that ... should work
|
||||
if !fileOnly {
|
||||
logs, err := NewCommandContext(repo.Ctx, "log", baseCommitID+separator+headBranch, prettyLogFormat).RunInDirBytes(repo.Path)
|
||||
logs, err := NewCommand(repo.Ctx, "log", baseCommitID+separator+headBranch, prettyLogFormat).RunInDirBytes(repo.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -146,14 +146,14 @@ func (repo *Repository) GetDiffNumChangedFiles(base, head string, directComparis
|
|||
separator = ".."
|
||||
}
|
||||
|
||||
if err := NewCommandContext(repo.Ctx, "diff", "-z", "--name-only", base+separator+head).
|
||||
if err := NewCommand(repo.Ctx, "diff", "-z", "--name-only", base+separator+head).
|
||||
RunInDirPipeline(repo.Path, w, stderr); err != nil {
|
||||
if strings.Contains(stderr.String(), "no merge base") {
|
||||
// git >= 2.28 now returns an error if base and head have become unrelated.
|
||||
// previously it would return the results of git diff -z --name-only base head so let's try that...
|
||||
w = &lineCountWriter{}
|
||||
stderr.Reset()
|
||||
if err = NewCommandContext(repo.Ctx, "diff", "-z", "--name-only", base, head).RunInDirPipeline(repo.Path, w, stderr); err == nil {
|
||||
if err = NewCommand(repo.Ctx, "diff", "-z", "--name-only", base, head).RunInDirPipeline(repo.Path, w, stderr); err == nil {
|
||||
return w.numLines, nil
|
||||
}
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ func GetDiffShortStat(ctx context.Context, repoPath string, args ...string) (num
|
|||
"--shortstat",
|
||||
}, args...)
|
||||
|
||||
stdout, err := NewCommandContext(ctx, args...).RunInDir(repoPath)
|
||||
stdout, err := NewCommand(ctx, args...).RunInDir(repoPath)
|
||||
if err != nil {
|
||||
return 0, 0, 0, err
|
||||
}
|
||||
|
@ -238,27 +238,27 @@ func (repo *Repository) GetDiffOrPatch(base, head string, w io.Writer, patch, bi
|
|||
|
||||
// GetDiff generates and returns patch data between given revisions, optimized for human readability
|
||||
func (repo *Repository) GetDiff(base, head string, w io.Writer) error {
|
||||
return NewCommandContext(repo.Ctx, "diff", "-p", base, head).
|
||||
return NewCommand(repo.Ctx, "diff", "-p", base, head).
|
||||
RunInDirPipeline(repo.Path, w, nil)
|
||||
}
|
||||
|
||||
// GetDiffBinary generates and returns patch data between given revisions, including binary diffs.
|
||||
func (repo *Repository) GetDiffBinary(base, head string, w io.Writer) error {
|
||||
if CheckGitVersionAtLeast("1.7.7") == nil {
|
||||
return NewCommandContext(repo.Ctx, "diff", "-p", "--binary", "--histogram", base, head).
|
||||
return NewCommand(repo.Ctx, "diff", "-p", "--binary", "--histogram", base, head).
|
||||
RunInDirPipeline(repo.Path, w, nil)
|
||||
}
|
||||
return NewCommandContext(repo.Ctx, "diff", "-p", "--binary", "--patience", base, head).
|
||||
return NewCommand(repo.Ctx, "diff", "-p", "--binary", "--patience", base, head).
|
||||
RunInDirPipeline(repo.Path, w, nil)
|
||||
}
|
||||
|
||||
// GetPatch generates and returns format-patch data between given revisions, able to be used with `git apply`
|
||||
func (repo *Repository) GetPatch(base, head string, w io.Writer) error {
|
||||
stderr := new(bytes.Buffer)
|
||||
err := NewCommandContext(repo.Ctx, "format-patch", "--binary", "--stdout", base+"..."+head).
|
||||
err := NewCommand(repo.Ctx, "format-patch", "--binary", "--stdout", base+"..."+head).
|
||||
RunInDirPipeline(repo.Path, w, stderr)
|
||||
if err != nil && bytes.Contains(stderr.Bytes(), []byte("no merge base")) {
|
||||
return NewCommandContext(repo.Ctx, "format-patch", "--binary", "--stdout", base, head).
|
||||
return NewCommand(repo.Ctx, "format-patch", "--binary", "--stdout", base, head).
|
||||
RunInDirPipeline(repo.Path, w, nil)
|
||||
}
|
||||
return err
|
||||
|
@ -267,7 +267,7 @@ func (repo *Repository) GetPatch(base, head string, w io.Writer) error {
|
|||
// GetDiffFromMergeBase generates and return patch data from merge base to head
|
||||
func (repo *Repository) GetDiffFromMergeBase(base, head string, w io.Writer) error {
|
||||
stderr := new(bytes.Buffer)
|
||||
err := NewCommandContext(repo.Ctx, "diff", "-p", "--binary", base+"..."+head).
|
||||
err := NewCommand(repo.Ctx, "diff", "-p", "--binary", base+"..."+head).
|
||||
RunInDirPipeline(repo.Path, w, stderr)
|
||||
if err != nil && bytes.Contains(stderr.Bytes(), []byte("no merge base")) {
|
||||
return repo.GetDiffBinary(base, head, w)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue