forked from forgejo/forgejo
Serve .patch for pull requests (#3305)
* Serve .patch for pull requests Closes #3259 Updates "git" module, for GetFormatPatch * Handle io.Copy error
This commit is contained in:
parent
18bb0f8f13
commit
44053532bb
7 changed files with 79 additions and 6 deletions
1
vendor/code.gitea.io/git/MAINTAINERS
generated
vendored
1
vendor/code.gitea.io/git/MAINTAINERS
generated
vendored
|
@ -7,6 +7,7 @@ Kim Carlbäcker <kim.carlbacker@gmail.com> (@bkcsoft)
|
|||
LefsFlare <nobody@nobody.tld> (@LefsFlarey)
|
||||
Lunny Xiao <xiaolunwen@gmail.com> (@lunny)
|
||||
Matthias Loibl <mail@matthiasloibl.com> (@metalmatze)
|
||||
Morgan Bazalgette <the@howl.moe> (@thehowl)
|
||||
Rachid Zarouali <nobody@nobody.tld> (@xinity)
|
||||
Rémy Boulanouar <admin@dblk.org> (@DblK)
|
||||
Sandro Santilli <strk@kbt.io> (@strk)
|
||||
|
|
5
vendor/code.gitea.io/git/command.go
generated
vendored
5
vendor/code.gitea.io/git/command.go
generated
vendored
|
@ -17,6 +17,9 @@ import (
|
|||
var (
|
||||
// GlobalCommandArgs global command args for external package setting
|
||||
GlobalCommandArgs []string
|
||||
|
||||
// DefaultCommandExecutionTimeout default command execution timeout duration
|
||||
DefaultCommandExecutionTimeout = 60 * time.Second
|
||||
)
|
||||
|
||||
// Command represents a command with its subcommands or arguments.
|
||||
|
@ -50,7 +53,7 @@ func (c *Command) AddArguments(args ...string) *Command {
|
|||
// it pipes stdout and stderr to given io.Writer.
|
||||
func (c *Command) RunInDirTimeoutPipeline(timeout time.Duration, dir string, stdout, stderr io.Writer) error {
|
||||
if timeout == -1 {
|
||||
timeout = 60 * time.Second
|
||||
timeout = DefaultCommandExecutionTimeout
|
||||
}
|
||||
|
||||
if len(dir) == 0 {
|
||||
|
|
14
vendor/code.gitea.io/git/repo_pull.go
generated
vendored
14
vendor/code.gitea.io/git/repo_pull.go
generated
vendored
|
@ -5,8 +5,10 @@
|
|||
package git
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"container/list"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -73,3 +75,15 @@ func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch stri
|
|||
func (repo *Repository) GetPatch(base, head string) ([]byte, error) {
|
||||
return NewCommand("diff", "-p", "--binary", base, head).RunInDirBytes(repo.Path)
|
||||
}
|
||||
|
||||
// GetFormatPatch generates and returns format-patch data between given revisions.
|
||||
func (repo *Repository) GetFormatPatch(base, head string) (io.Reader, error) {
|
||||
stdout := new(bytes.Buffer)
|
||||
stderr := new(bytes.Buffer)
|
||||
|
||||
if err := NewCommand("format-patch", "--binary", "--stdout", base+"..."+head).
|
||||
RunInDirPipeline(repo.Path, stdout, stderr); err != nil {
|
||||
return nil, concatenateError(err, stderr.String())
|
||||
}
|
||||
return stdout, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue