Refactor git command stderr handling (#36402)
And clean up legacy fragile & incorrect logic
This commit is contained in:
@@ -287,10 +287,9 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com
|
||||
prHeadRef := pr.GetGitHeadRefName()
|
||||
|
||||
// Check if the pull request is merged into BaseBranch
|
||||
if _, err := gitrepo.RunCmdString(ctx, pr.BaseRepo,
|
||||
gitcmd.NewCommand("merge-base", "--is-ancestor").
|
||||
AddDynamicArguments(prHeadRef, pr.BaseBranch)); err != nil {
|
||||
if strings.Contains(err.Error(), "exit status 1") {
|
||||
cmd := gitcmd.NewCommand("merge-base", "--is-ancestor").AddDynamicArguments(prHeadRef, pr.BaseBranch)
|
||||
if err := gitrepo.RunCmdWithStderr(ctx, pr.BaseRepo, cmd); err != nil {
|
||||
if gitcmd.IsErrorExitCode(err, 1) {
|
||||
// prHeadRef is not an ancestor of the base branch
|
||||
return nil, nil
|
||||
}
|
||||
@@ -315,7 +314,7 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com
|
||||
objectFormat := git.ObjectFormatFromName(pr.BaseRepo.ObjectFormatName)
|
||||
|
||||
// Get the commit from BaseBranch where the pull request got merged
|
||||
mergeCommit, err := gitrepo.RunCmdString(ctx, pr.BaseRepo,
|
||||
mergeCommit, _, err := gitrepo.RunCmdString(ctx, pr.BaseRepo,
|
||||
gitcmd.NewCommand("rev-list", "--ancestry-path", "--merges", "--reverse").
|
||||
AddDynamicArguments(prHeadCommitID+".."+pr.BaseBranch))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user