mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +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:
		@@ -188,35 +188,65 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Switch off LFS process (set required, clean and smudge here also)
 | 
			
		||||
	if err := gitConfigCommand().AddArguments("filter.lfs.process", "").RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
	if err := gitConfigCommand().AddArguments("filter.lfs.process", "").
 | 
			
		||||
		RunWithContext(&git.RunContext{
 | 
			
		||||
			Timeout: -1,
 | 
			
		||||
			Dir:     tmpBasePath,
 | 
			
		||||
			Stdout:  &outbuf,
 | 
			
		||||
			Stderr:  &errbuf,
 | 
			
		||||
		}); err != nil {
 | 
			
		||||
		log.Error("git config [filter.lfs.process -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
 | 
			
		||||
		return "", fmt.Errorf("git config [filter.lfs.process -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
 | 
			
		||||
	}
 | 
			
		||||
	outbuf.Reset()
 | 
			
		||||
	errbuf.Reset()
 | 
			
		||||
 | 
			
		||||
	if err := gitConfigCommand().AddArguments("filter.lfs.required", "false").RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
	if err := gitConfigCommand().AddArguments("filter.lfs.required", "false").
 | 
			
		||||
		RunWithContext(&git.RunContext{
 | 
			
		||||
			Timeout: -1,
 | 
			
		||||
			Dir:     tmpBasePath,
 | 
			
		||||
			Stdout:  &outbuf,
 | 
			
		||||
			Stderr:  &errbuf,
 | 
			
		||||
		}); err != nil {
 | 
			
		||||
		log.Error("git config [filter.lfs.required -> <false> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
 | 
			
		||||
		return "", fmt.Errorf("git config [filter.lfs.required -> <false> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
 | 
			
		||||
	}
 | 
			
		||||
	outbuf.Reset()
 | 
			
		||||
	errbuf.Reset()
 | 
			
		||||
 | 
			
		||||
	if err := gitConfigCommand().AddArguments("filter.lfs.clean", "").RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
	if err := gitConfigCommand().AddArguments("filter.lfs.clean", "").
 | 
			
		||||
		RunWithContext(&git.RunContext{
 | 
			
		||||
			Timeout: -1,
 | 
			
		||||
			Dir:     tmpBasePath,
 | 
			
		||||
			Stdout:  &outbuf,
 | 
			
		||||
			Stderr:  &errbuf,
 | 
			
		||||
		}); err != nil {
 | 
			
		||||
		log.Error("git config [filter.lfs.clean -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
 | 
			
		||||
		return "", fmt.Errorf("git config [filter.lfs.clean -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
 | 
			
		||||
	}
 | 
			
		||||
	outbuf.Reset()
 | 
			
		||||
	errbuf.Reset()
 | 
			
		||||
 | 
			
		||||
	if err := gitConfigCommand().AddArguments("filter.lfs.smudge", "").RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
	if err := gitConfigCommand().AddArguments("filter.lfs.smudge", "").
 | 
			
		||||
		RunWithContext(&git.RunContext{
 | 
			
		||||
			Timeout: -1,
 | 
			
		||||
			Dir:     tmpBasePath,
 | 
			
		||||
			Stdout:  &outbuf,
 | 
			
		||||
			Stderr:  &errbuf,
 | 
			
		||||
		}); err != nil {
 | 
			
		||||
		log.Error("git config [filter.lfs.smudge -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
 | 
			
		||||
		return "", fmt.Errorf("git config [filter.lfs.smudge -> <> ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
 | 
			
		||||
	}
 | 
			
		||||
	outbuf.Reset()
 | 
			
		||||
	errbuf.Reset()
 | 
			
		||||
 | 
			
		||||
	if err := gitConfigCommand().AddArguments("core.sparseCheckout", "true").RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
	if err := gitConfigCommand().AddArguments("core.sparseCheckout", "true").
 | 
			
		||||
		RunWithContext(&git.RunContext{
 | 
			
		||||
			Timeout: -1,
 | 
			
		||||
			Dir:     tmpBasePath,
 | 
			
		||||
			Stdout:  &outbuf,
 | 
			
		||||
			Stderr:  &errbuf,
 | 
			
		||||
		}); err != nil {
 | 
			
		||||
		log.Error("git config [core.sparseCheckout -> true ]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
 | 
			
		||||
		return "", fmt.Errorf("git config [core.sparsecheckout -> true]: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
 | 
			
		||||
	}
 | 
			
		||||
@@ -224,7 +254,13 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
 | 
			
		||||
	errbuf.Reset()
 | 
			
		||||
 | 
			
		||||
	// Read base branch index
 | 
			
		||||
	if err := git.NewCommand(ctx, "read-tree", "HEAD").RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
	if err := git.NewCommand(ctx, "read-tree", "HEAD").
 | 
			
		||||
		RunWithContext(&git.RunContext{
 | 
			
		||||
			Timeout: -1,
 | 
			
		||||
			Dir:     tmpBasePath,
 | 
			
		||||
			Stdout:  &outbuf,
 | 
			
		||||
			Stderr:  &errbuf,
 | 
			
		||||
		}); err != nil {
 | 
			
		||||
		log.Error("git read-tree HEAD: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
 | 
			
		||||
		return "", fmt.Errorf("Unable to read base branch in to the index: %v\n%s\n%s", err, outbuf.String(), errbuf.String())
 | 
			
		||||
	}
 | 
			
		||||
@@ -279,7 +315,13 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
 | 
			
		||||
		fallthrough
 | 
			
		||||
	case repo_model.MergeStyleRebaseMerge:
 | 
			
		||||
		// Checkout head branch
 | 
			
		||||
		if err := git.NewCommand(ctx, "checkout", "-b", stagingBranch, trackingBranch).RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
		if err := git.NewCommand(ctx, "checkout", "-b", stagingBranch, trackingBranch).
 | 
			
		||||
			RunWithContext(&git.RunContext{
 | 
			
		||||
				Timeout: -1,
 | 
			
		||||
				Dir:     tmpBasePath,
 | 
			
		||||
				Stdout:  &outbuf,
 | 
			
		||||
				Stderr:  &errbuf,
 | 
			
		||||
			}); err != nil {
 | 
			
		||||
			log.Error("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
 | 
			
		||||
			return "", fmt.Errorf("git checkout base prior to merge post staging rebase  [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
 | 
			
		||||
		}
 | 
			
		||||
@@ -287,7 +329,13 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
 | 
			
		||||
		errbuf.Reset()
 | 
			
		||||
 | 
			
		||||
		// Rebase before merging
 | 
			
		||||
		if err := git.NewCommand(ctx, "rebase", baseBranch).RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
		if err := git.NewCommand(ctx, "rebase", baseBranch).
 | 
			
		||||
			RunWithContext(&git.RunContext{
 | 
			
		||||
				Timeout: -1,
 | 
			
		||||
				Dir:     tmpBasePath,
 | 
			
		||||
				Stdout:  &outbuf,
 | 
			
		||||
				Stderr:  &errbuf,
 | 
			
		||||
			}); err != nil {
 | 
			
		||||
			// Rebase will leave a REBASE_HEAD file in .git if there is a conflict
 | 
			
		||||
			if _, statErr := os.Stat(filepath.Join(tmpBasePath, ".git", "REBASE_HEAD")); statErr == nil {
 | 
			
		||||
				var commitSha string
 | 
			
		||||
@@ -335,7 +383,13 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Checkout base branch again
 | 
			
		||||
		if err := git.NewCommand(ctx, "checkout", baseBranch).RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
		if err := git.NewCommand(ctx, "checkout", baseBranch).
 | 
			
		||||
			RunWithContext(&git.RunContext{
 | 
			
		||||
				Timeout: -1,
 | 
			
		||||
				Dir:     tmpBasePath,
 | 
			
		||||
				Stdout:  &outbuf,
 | 
			
		||||
				Stderr:  &errbuf,
 | 
			
		||||
			}); err != nil {
 | 
			
		||||
			log.Error("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
 | 
			
		||||
			return "", fmt.Errorf("git checkout base prior to merge post staging rebase  [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
 | 
			
		||||
		}
 | 
			
		||||
@@ -375,7 +429,14 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
 | 
			
		||||
		}
 | 
			
		||||
		sig := pr.Issue.Poster.NewGitSig()
 | 
			
		||||
		if signArg == "" {
 | 
			
		||||
			if err := git.NewCommand(ctx, "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email), "-m", message).RunInDirTimeoutEnvPipeline(env, -1, tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
			if err := git.NewCommand(ctx, "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email), "-m", message).
 | 
			
		||||
				RunWithContext(&git.RunContext{
 | 
			
		||||
					Env:     env,
 | 
			
		||||
					Timeout: -1,
 | 
			
		||||
					Dir:     tmpBasePath,
 | 
			
		||||
					Stdout:  &outbuf,
 | 
			
		||||
					Stderr:  &errbuf,
 | 
			
		||||
				}); err != nil {
 | 
			
		||||
				log.Error("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
 | 
			
		||||
				return "", fmt.Errorf("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
 | 
			
		||||
			}
 | 
			
		||||
@@ -384,7 +445,14 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
 | 
			
		||||
				// add trailer
 | 
			
		||||
				message += fmt.Sprintf("\nCo-authored-by: %s\nCo-committed-by: %s\n", sig.String(), sig.String())
 | 
			
		||||
			}
 | 
			
		||||
			if err := git.NewCommand(ctx, "commit", signArg, fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email), "-m", message).RunInDirTimeoutEnvPipeline(env, -1, tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
			if err := git.NewCommand(ctx, "commit", signArg, fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email), "-m", message).
 | 
			
		||||
				RunWithContext(&git.RunContext{
 | 
			
		||||
					Env:     env,
 | 
			
		||||
					Timeout: -1,
 | 
			
		||||
					Dir:     tmpBasePath,
 | 
			
		||||
					Stdout:  &outbuf,
 | 
			
		||||
					Stderr:  &errbuf,
 | 
			
		||||
				}); err != nil {
 | 
			
		||||
				log.Error("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
 | 
			
		||||
				return "", fmt.Errorf("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
 | 
			
		||||
			}
 | 
			
		||||
@@ -448,7 +516,13 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Push back to upstream.
 | 
			
		||||
	if err := pushCmd.RunInDirTimeoutEnvPipeline(env, -1, tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
	if err := pushCmd.RunWithContext(&git.RunContext{
 | 
			
		||||
		Env:     env,
 | 
			
		||||
		Timeout: -1,
 | 
			
		||||
		Dir:     tmpBasePath,
 | 
			
		||||
		Stdout:  &outbuf,
 | 
			
		||||
		Stderr:  &errbuf,
 | 
			
		||||
	}); err != nil {
 | 
			
		||||
		if strings.Contains(errbuf.String(), "non-fast-forward") {
 | 
			
		||||
			return "", &git.ErrPushOutOfDate{
 | 
			
		||||
				StdOut: outbuf.String(),
 | 
			
		||||
@@ -475,12 +549,26 @@ func rawMerge(ctx context.Context, pr *models.PullRequest, doer *user_model.User
 | 
			
		||||
func commitAndSignNoAuthor(ctx context.Context, pr *models.PullRequest, message, signArg, tmpBasePath string, env []string) error {
 | 
			
		||||
	var outbuf, errbuf strings.Builder
 | 
			
		||||
	if signArg == "" {
 | 
			
		||||
		if err := git.NewCommand(ctx, "commit", "-m", message).RunInDirTimeoutEnvPipeline(env, -1, tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
		if err := git.NewCommand(ctx, "commit", "-m", message).
 | 
			
		||||
			RunWithContext(&git.RunContext{
 | 
			
		||||
				Env:     env,
 | 
			
		||||
				Timeout: -1,
 | 
			
		||||
				Dir:     tmpBasePath,
 | 
			
		||||
				Stdout:  &outbuf,
 | 
			
		||||
				Stderr:  &errbuf,
 | 
			
		||||
			}); err != nil {
 | 
			
		||||
			log.Error("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
 | 
			
		||||
			return fmt.Errorf("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		if err := git.NewCommand(ctx, "commit", signArg, "-m", message).RunInDirTimeoutEnvPipeline(env, -1, tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
		if err := git.NewCommand(ctx, "commit", signArg, "-m", message).
 | 
			
		||||
			RunWithContext(&git.RunContext{
 | 
			
		||||
				Env:     env,
 | 
			
		||||
				Timeout: -1,
 | 
			
		||||
				Dir:     tmpBasePath,
 | 
			
		||||
				Stdout:  &outbuf,
 | 
			
		||||
				Stderr:  &errbuf,
 | 
			
		||||
			}); err != nil {
 | 
			
		||||
			log.Error("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
 | 
			
		||||
			return fmt.Errorf("git commit [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
 | 
			
		||||
		}
 | 
			
		||||
@@ -490,7 +578,12 @@ func commitAndSignNoAuthor(ctx context.Context, pr *models.PullRequest, message,
 | 
			
		||||
 | 
			
		||||
func runMergeCommand(pr *models.PullRequest, mergeStyle repo_model.MergeStyle, cmd *git.Command, tmpBasePath string) error {
 | 
			
		||||
	var outbuf, errbuf strings.Builder
 | 
			
		||||
	if err := cmd.RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
	if err := cmd.RunWithContext(&git.RunContext{
 | 
			
		||||
		Timeout: -1,
 | 
			
		||||
		Dir:     tmpBasePath,
 | 
			
		||||
		Stdout:  &outbuf,
 | 
			
		||||
		Stderr:  &errbuf,
 | 
			
		||||
	}); err != nil {
 | 
			
		||||
		// Merge will leave a MERGE_HEAD file in the .git folder if there is a conflict
 | 
			
		||||
		if _, statErr := os.Stat(filepath.Join(tmpBasePath, ".git", "MERGE_HEAD")); statErr == nil {
 | 
			
		||||
			// We have a merge conflict error
 | 
			
		||||
@@ -523,7 +616,13 @@ func getDiffTree(ctx context.Context, repoPath, baseBranch, headBranch string) (
 | 
			
		||||
	getDiffTreeFromBranch := func(repoPath, baseBranch, headBranch string) (string, error) {
 | 
			
		||||
		var outbuf, errbuf strings.Builder
 | 
			
		||||
		// Compute the diff-tree for sparse-checkout
 | 
			
		||||
		if err := git.NewCommand(ctx, "diff-tree", "--no-commit-id", "--name-only", "-r", "-z", "--root", baseBranch, headBranch, "--").RunInDirPipeline(repoPath, &outbuf, &errbuf); err != nil {
 | 
			
		||||
		if err := git.NewCommand(ctx, "diff-tree", "--no-commit-id", "--name-only", "-r", "-z", "--root", baseBranch, headBranch, "--").
 | 
			
		||||
			RunWithContext(&git.RunContext{
 | 
			
		||||
				Timeout: -1,
 | 
			
		||||
				Dir:     repoPath,
 | 
			
		||||
				Stdout:  &outbuf,
 | 
			
		||||
				Stderr:  &errbuf,
 | 
			
		||||
			}); err != nil {
 | 
			
		||||
			return "", fmt.Errorf("git diff-tree [%s base:%s head:%s]: %s", repoPath, baseBranch, headBranch, errbuf.String())
 | 
			
		||||
		}
 | 
			
		||||
		return outbuf.String(), nil
 | 
			
		||||
 
 | 
			
		||||
@@ -383,10 +383,11 @@ func checkConflicts(ctx context.Context, pr *models.PullRequest, gitRepo *git.Re
 | 
			
		||||
	// 7. Run the check command
 | 
			
		||||
	conflict = false
 | 
			
		||||
	err = git.NewCommand(gitRepo.Ctx, args...).
 | 
			
		||||
		RunInDirTimeoutEnvFullPipelineFunc(
 | 
			
		||||
			nil, -1, tmpBasePath,
 | 
			
		||||
			nil, stderrWriter, nil,
 | 
			
		||||
			func(ctx context.Context, cancel context.CancelFunc) error {
 | 
			
		||||
		RunWithContext(&git.RunContext{
 | 
			
		||||
			Timeout: -1,
 | 
			
		||||
			Dir:     tmpBasePath,
 | 
			
		||||
			Stderr:  stderrWriter,
 | 
			
		||||
			PipelineFunc: func(ctx context.Context, cancel context.CancelFunc) error {
 | 
			
		||||
				// Close the writer end of the pipe to begin processing
 | 
			
		||||
				_ = stderrWriter.Close()
 | 
			
		||||
				defer func() {
 | 
			
		||||
@@ -444,7 +445,8 @@ func checkConflicts(ctx context.Context, pr *models.PullRequest, gitRepo *git.Re
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				return nil
 | 
			
		||||
			})
 | 
			
		||||
			},
 | 
			
		||||
		})
 | 
			
		||||
 | 
			
		||||
	// 8. If there is a conflict the `git apply` command will return a non-zero error code - so there will be a positive error.
 | 
			
		||||
	if err != nil {
 | 
			
		||||
 
 | 
			
		||||
@@ -63,10 +63,12 @@ func readUnmergedLsFileLines(ctx context.Context, tmpBasePath string, outputChan
 | 
			
		||||
 | 
			
		||||
	stderr := &strings.Builder{}
 | 
			
		||||
	err = git.NewCommand(ctx, "ls-files", "-u", "-z").
 | 
			
		||||
		RunInDirTimeoutEnvFullPipelineFunc(
 | 
			
		||||
			nil, -1, tmpBasePath,
 | 
			
		||||
			lsFilesWriter, stderr, nil,
 | 
			
		||||
			func(_ context.Context, _ context.CancelFunc) error {
 | 
			
		||||
		RunWithContext(&git.RunContext{
 | 
			
		||||
			Timeout: -1,
 | 
			
		||||
			Dir:     tmpBasePath,
 | 
			
		||||
			Stdout:  lsFilesWriter,
 | 
			
		||||
			Stderr:  stderr,
 | 
			
		||||
			PipelineFunc: func(_ context.Context, _ context.CancelFunc) error {
 | 
			
		||||
				_ = lsFilesWriter.Close()
 | 
			
		||||
				defer func() {
 | 
			
		||||
					_ = lsFilesReader.Close()
 | 
			
		||||
@@ -102,8 +104,8 @@ func readUnmergedLsFileLines(ctx context.Context, tmpBasePath string, outputChan
 | 
			
		||||
					toemit.path = split[2][2 : len(split[2])-1]
 | 
			
		||||
					outputChan <- toemit
 | 
			
		||||
				}
 | 
			
		||||
			})
 | 
			
		||||
 | 
			
		||||
			},
 | 
			
		||||
		})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		outputChan <- &lsFileLine{err: fmt.Errorf("git ls-files -u -z: %v", git.ConcatenateError(err, stderr.String()))}
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -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