mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Change git.cmd to RunWithContext (#18693)
Change all `cmd...Pipeline` commands to `cmd.RunWithContext`. #18553 Co-authored-by: Martin Scholz <martin.scholz@versasec.com>
This commit is contained in:
		@@ -93,7 +93,13 @@ func createTemporaryRepo(ctx context.Context, pr *models.PullRequest) (string, e
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var outbuf, errbuf strings.Builder
 | 
			
		||||
	if err := git.NewCommand(ctx, "remote", "add", "-t", pr.BaseBranch, "-m", pr.BaseBranch, "origin", baseRepoPath).RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
	if err := git.NewCommand(ctx, "remote", "add", "-t", pr.BaseBranch, "-m", pr.BaseBranch, "origin", baseRepoPath).
 | 
			
		||||
		RunWithContext(&git.RunContext{
 | 
			
		||||
			Timeout: -1,
 | 
			
		||||
			Dir:     tmpBasePath,
 | 
			
		||||
			Stdout:  &outbuf,
 | 
			
		||||
			Stderr:  &errbuf,
 | 
			
		||||
		}); err != nil {
 | 
			
		||||
		log.Error("Unable to add base repository as origin [%s -> %s]: %v\n%s\n%s", pr.BaseRepo.FullName(), tmpBasePath, err, outbuf.String(), errbuf.String())
 | 
			
		||||
		if err := models.RemoveTemporaryPath(tmpBasePath); err != nil {
 | 
			
		||||
			log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err)
 | 
			
		||||
@@ -103,7 +109,13 @@ func createTemporaryRepo(ctx context.Context, pr *models.PullRequest) (string, e
 | 
			
		||||
	outbuf.Reset()
 | 
			
		||||
	errbuf.Reset()
 | 
			
		||||
 | 
			
		||||
	if err := git.NewCommand(ctx, "fetch", "origin", "--no-tags", "--", pr.BaseBranch+":"+baseBranch, pr.BaseBranch+":original_"+baseBranch).RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
	if err := git.NewCommand(ctx, "fetch", "origin", "--no-tags", "--", pr.BaseBranch+":"+baseBranch, pr.BaseBranch+":original_"+baseBranch).
 | 
			
		||||
		RunWithContext(&git.RunContext{
 | 
			
		||||
			Timeout: -1,
 | 
			
		||||
			Dir:     tmpBasePath,
 | 
			
		||||
			Stdout:  &outbuf,
 | 
			
		||||
			Stderr:  &errbuf,
 | 
			
		||||
		}); err != nil {
 | 
			
		||||
		log.Error("Unable to fetch origin base branch [%s:%s -> base, original_base in %s]: %v:\n%s\n%s", pr.BaseRepo.FullName(), pr.BaseBranch, tmpBasePath, err, outbuf.String(), errbuf.String())
 | 
			
		||||
		if err := models.RemoveTemporaryPath(tmpBasePath); err != nil {
 | 
			
		||||
			log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err)
 | 
			
		||||
@@ -113,7 +125,13 @@ func createTemporaryRepo(ctx context.Context, pr *models.PullRequest) (string, e
 | 
			
		||||
	outbuf.Reset()
 | 
			
		||||
	errbuf.Reset()
 | 
			
		||||
 | 
			
		||||
	if err := git.NewCommand(ctx, "symbolic-ref", "HEAD", git.BranchPrefix+baseBranch).RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
	if err := git.NewCommand(ctx, "symbolic-ref", "HEAD", git.BranchPrefix+baseBranch).
 | 
			
		||||
		RunWithContext(&git.RunContext{
 | 
			
		||||
			Timeout: -1,
 | 
			
		||||
			Dir:     tmpBasePath,
 | 
			
		||||
			Stdout:  &outbuf,
 | 
			
		||||
			Stderr:  &errbuf,
 | 
			
		||||
		}); err != nil {
 | 
			
		||||
		log.Error("Unable to set HEAD as base branch [%s]: %v\n%s\n%s", tmpBasePath, err, outbuf.String(), errbuf.String())
 | 
			
		||||
		if err := models.RemoveTemporaryPath(tmpBasePath); err != nil {
 | 
			
		||||
			log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err)
 | 
			
		||||
@@ -131,7 +149,13 @@ func createTemporaryRepo(ctx context.Context, pr *models.PullRequest) (string, e
 | 
			
		||||
		return "", fmt.Errorf("Unable to head base repository to temporary repo [%s -> tmpBasePath]: %v", pr.HeadRepo.FullName(), err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := git.NewCommand(ctx, "remote", "add", remoteRepoName, headRepoPath).RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
	if err := git.NewCommand(ctx, "remote", "add", remoteRepoName, headRepoPath).
 | 
			
		||||
		RunWithContext(&git.RunContext{
 | 
			
		||||
			Timeout: -1,
 | 
			
		||||
			Dir:     tmpBasePath,
 | 
			
		||||
			Stdout:  &outbuf,
 | 
			
		||||
			Stderr:  &errbuf,
 | 
			
		||||
		}); err != nil {
 | 
			
		||||
		log.Error("Unable to add head repository as head_repo [%s -> %s]: %v\n%s\n%s", pr.HeadRepo.FullName(), tmpBasePath, err, outbuf.String(), errbuf.String())
 | 
			
		||||
		if err := models.RemoveTemporaryPath(tmpBasePath); err != nil {
 | 
			
		||||
			log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err)
 | 
			
		||||
@@ -151,7 +175,13 @@ func createTemporaryRepo(ctx context.Context, pr *models.PullRequest) (string, e
 | 
			
		||||
	} else {
 | 
			
		||||
		headBranch = pr.GetGitRefName()
 | 
			
		||||
	}
 | 
			
		||||
	if err := git.NewCommand(ctx, "fetch", "--no-tags", remoteRepoName, headBranch+":"+trackingBranch).RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
	if err := git.NewCommand(ctx, "fetch", "--no-tags", remoteRepoName, headBranch+":"+trackingBranch).
 | 
			
		||||
		RunWithContext(&git.RunContext{
 | 
			
		||||
			Timeout: -1,
 | 
			
		||||
			Dir:     tmpBasePath,
 | 
			
		||||
			Stdout:  &outbuf,
 | 
			
		||||
			Stderr:  &errbuf,
 | 
			
		||||
		}); err != nil {
 | 
			
		||||
		if err := models.RemoveTemporaryPath(tmpBasePath); err != nil {
 | 
			
		||||
			log.Error("CreateTempRepo: RemoveTemporaryPath: %s", err)
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user