mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 11:28:24 +00:00 
			
		
		
		
	Move some functions to gitrepo package (#35543)
Refactor Git command functions to use WithXXX methods instead of exposing RunOpts. This change simplifies reuse across gitrepo and improves consistency, encapsulation, and maintainability of command options. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		| @@ -281,9 +281,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 := gitcmd.NewCommand("merge-base", "--is-ancestor"). | ||||
| 		AddDynamicArguments(prHeadRef, pr.BaseBranch). | ||||
| 		RunStdString(ctx, &gitcmd.RunOpts{Dir: pr.BaseRepo.RepoPath()}); err != nil { | ||||
| 	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") { | ||||
| 			// prHeadRef is not an ancestor of the base branch | ||||
| 			return nil, nil | ||||
| @@ -309,9 +309,9 @@ 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 := gitcmd.NewCommand("rev-list", "--ancestry-path", "--merges", "--reverse"). | ||||
| 		AddDynamicArguments(prHeadCommitID+".."+pr.BaseBranch). | ||||
| 		RunStdString(ctx, &gitcmd.RunOpts{Dir: pr.BaseRepo.RepoPath()}) | ||||
| 	mergeCommit, err := gitrepo.RunCmdString(ctx, pr.BaseRepo, | ||||
| 		gitcmd.NewCommand("rev-list", "--ancestry-path", "--merges", "--reverse"). | ||||
| 			AddDynamicArguments(prHeadCommitID+".."+pr.BaseBranch)) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("git rev-list --ancestry-path --merges --reverse: %w", err) | ||||
| 	} else if len(mergeCommit) < objectFormat.FullLength() { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user