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)
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
package git
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -21,7 +22,8 @@ func TestGetFormatPatch(t *testing.T) {
|
|||
repo, err := OpenRepository(clonedPath)
|
||||
assert.NoError(t, err)
|
||||
defer repo.Close()
|
||||
rd, err := repo.GetFormatPatch("8d92fc95^", "8d92fc95")
|
||||
rd := &bytes.Buffer{}
|
||||
err = repo.GetPatch("8d92fc95^", "8d92fc95", rd)
|
||||
assert.NoError(t, err)
|
||||
patchb, err := ioutil.ReadAll(rd)
|
||||
assert.NoError(t, err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue