aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/repo.go
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-04-14 07:17:27 +0800
committerGitHub <noreply@github.com>2023-04-13 19:17:27 -0400
commit334c899f7b79d639d618c0b2bd4417243d09347f (patch)
treedbb6a1e6b76e142b1f790190a1a031464af1b575 /modules/git/repo.go
parent985f76dc4b0692c4d6c6f37e82500ef859557c16 (diff)
downloadgitea-334c899f7b79d639d618c0b2bd4417243d09347f.tar.gz
gitea-334c899f7b79d639d618c0b2bd4417243d09347f.zip
Improve git log for debugging (#24095)
Diffstat (limited to 'modules/git/repo.go')
-rw-r--r--modules/git/repo.go45
1 files changed, 9 insertions, 36 deletions
diff --git a/modules/git/repo.go b/modules/git/repo.go
index 233f7f20cf..d29ec40ae2 100644
--- a/modules/git/repo.go
+++ b/modules/git/repo.go
@@ -209,49 +209,22 @@ func Push(ctx context.Context, repoPath string, opts PushOptions) error {
} else {
cmd.SetDescription(fmt.Sprintf("push branch %s to %s (force: %t, mirror: %t)", opts.Branch, opts.Remote, opts.Force, opts.Mirror))
}
- var outbuf, errbuf strings.Builder
- if opts.Timeout == 0 {
- opts.Timeout = -1
- }
-
- err := cmd.Run(&RunOpts{
- Env: opts.Env,
- Timeout: opts.Timeout,
- Dir: repoPath,
- Stdout: &outbuf,
- Stderr: &errbuf,
- })
+ stdout, stderr, err := cmd.RunStdString(&RunOpts{Env: opts.Env, Timeout: opts.Timeout, Dir: repoPath})
if err != nil {
- if strings.Contains(errbuf.String(), "non-fast-forward") {
- return &ErrPushOutOfDate{
- StdOut: outbuf.String(),
- StdErr: errbuf.String(),
- Err: err,
- }
- } else if strings.Contains(errbuf.String(), "! [remote rejected]") {
- err := &ErrPushRejected{
- StdOut: outbuf.String(),
- StdErr: errbuf.String(),
- Err: err,
- }
+ if strings.Contains(stderr, "non-fast-forward") {
+ return &ErrPushOutOfDate{StdOut: stdout, StdErr: stderr, Err: err}
+ } else if strings.Contains(stderr, "! [remote rejected]") {
+ err := &ErrPushRejected{StdOut: stdout, StdErr: stderr, Err: err}
err.GenerateMessage()
return err
- } else if strings.Contains(errbuf.String(), "matches more than one") {
- err := &ErrMoreThanOne{
- StdOut: outbuf.String(),
- StdErr: errbuf.String(),
- Err: err,
- }
- return err
+ } else if strings.Contains(stderr, "matches more than one") {
+ return &ErrMoreThanOne{StdOut: stdout, StdErr: stderr, Err: err}
}
+ return fmt.Errorf("push failed: %w - %s\n%s", err, stderr, stdout)
}
- if errbuf.Len() > 0 && err != nil {
- return fmt.Errorf("%w - %s", err, errbuf.String())
- }
-
- return err
+ return nil
}
// GetLatestCommitTime returns time for latest commit in repository (across all branches)