1
0
Fork 0
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:
Sandro Santilli 2018-01-07 14:10:20 +01:00 committed by Lauris BH
parent 18bb0f8f13
commit 44053532bb
7 changed files with 79 additions and 6 deletions

View file

@ -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
}