Remove SavePatch and generate patches on the fly (#9302)
* Save patches to temporary files * Remove SavePatch and generate patches on the fly * Use ioutil.TempDir * fixup! Use ioutil.TempDir * fixup! fixup! Use ioutil.TempDir * RemoveAll LocalCopyPath() in initIntergrationTest * Default to status checking on PR creation * Remove unnecessary set to StatusChecking * Protect against unable to load repo * Handle conflicts * Restore original conflict setting * In TestPullRequests update status to StatusChecking before running TestPatch
This commit is contained in:
parent
8f16a2c37b
commit
74179d1b5e
16 changed files with 432 additions and 406 deletions
|
@ -6,7 +6,6 @@
|
|||
package git
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"container/list"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -94,19 +93,22 @@ func (repo *Repository) GetCompareInfo(basePath, baseBranch, headBranch string)
|
|||
return compareInfo, nil
|
||||
}
|
||||
|
||||
// GetPatch generates and returns patch data between given revisions.
|
||||
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())
|
||||
// GetDiffOrPatch generates either diff or formatted patch data between given revisions
|
||||
func (repo *Repository) GetDiffOrPatch(base, head string, w io.Writer, formatted bool) error {
|
||||
if formatted {
|
||||
return repo.GetPatch(base, head, w)
|
||||
}
|
||||
return stdout, nil
|
||||
return repo.GetDiff(base, head, w)
|
||||
}
|
||||
|
||||
// GetDiff generates and returns patch data between given revisions.
|
||||
func (repo *Repository) GetDiff(base, head string, w io.Writer) error {
|
||||
return NewCommand("diff", "-p", "--binary", base, head).
|
||||
RunInDirPipeline(repo.Path, w, nil)
|
||||
}
|
||||
|
||||
// GetPatch generates and returns format-patch data between given revisions.
|
||||
func (repo *Repository) GetPatch(base, head string, w io.Writer) error {
|
||||
return NewCommand("format-patch", "--binary", "--stdout", base+"..."+head).
|
||||
RunInDirPipeline(repo.Path, w, nil)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue