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:
		@@ -76,7 +76,13 @@ func (repo *Repository) CheckAttribute(opts CheckAttributeOpts) (map[string]map[
 | 
			
		||||
 | 
			
		||||
	cmd := NewCommand(repo.Ctx, cmdArgs...)
 | 
			
		||||
 | 
			
		||||
	if err := cmd.RunInDirTimeoutEnvPipeline(env, -1, repo.Path, stdOut, stdErr); err != nil {
 | 
			
		||||
	if err := cmd.RunWithContext(&RunContext{
 | 
			
		||||
		Env:     env,
 | 
			
		||||
		Timeout: -1,
 | 
			
		||||
		Dir:     repo.Path,
 | 
			
		||||
		Stdout:  stdOut,
 | 
			
		||||
		Stderr:  stdErr,
 | 
			
		||||
	}); err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("failed to run check-attr: %v\n%s\n%s", err, stdOut.String(), stdErr.String())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -182,9 +188,17 @@ func (c *CheckAttributeReader) Run() error {
 | 
			
		||||
		_ = c.Close()
 | 
			
		||||
	}()
 | 
			
		||||
	stdErr := new(bytes.Buffer)
 | 
			
		||||
	err := c.cmd.RunInDirTimeoutEnvFullPipelineFunc(c.env, -1, c.Repo.Path, c.stdOut, stdErr, c.stdinReader, func(_ context.Context, _ context.CancelFunc) error {
 | 
			
		||||
		close(c.running)
 | 
			
		||||
		return nil
 | 
			
		||||
	err := c.cmd.RunWithContext(&RunContext{
 | 
			
		||||
		Env:     c.env,
 | 
			
		||||
		Timeout: -1,
 | 
			
		||||
		Dir:     c.Repo.Path,
 | 
			
		||||
		Stdin:   c.stdinReader,
 | 
			
		||||
		Stdout:  c.stdOut,
 | 
			
		||||
		Stderr:  stdErr,
 | 
			
		||||
		PipelineFunc: func(_ context.Context, _ context.CancelFunc) error {
 | 
			
		||||
			close(c.running)
 | 
			
		||||
			return nil
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil && c.ctx.Err() != nil && err.Error() != "signal: killed" {
 | 
			
		||||
		return fmt.Errorf("failed to run attr-check. Error: %w\nStderr: %s", err, stdErr.String())
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user