mirror of
https://github.com/go-gitea/git.git
synced 2026-02-05 06:45:03 +01:00
use io reader for GetFormatPatch (#105)
This commit is contained in:
13
repo_pull.go
13
repo_pull.go
@@ -5,8 +5,10 @@
|
|||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"container/list"
|
"container/list"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -75,6 +77,13 @@ func (repo *Repository) GetPatch(base, head string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetFormatPatch generates and returns format-patch data between given revisions.
|
// GetFormatPatch generates and returns format-patch data between given revisions.
|
||||||
func (repo *Repository) GetFormatPatch(base, head string) ([]byte, error) {
|
func (repo *Repository) GetFormatPatch(base, head string) (io.Reader, error) {
|
||||||
return NewCommand("format-patch", "--binary", "--stdout", base + "..." + head).RunInDirBytes(repo.Path)
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,18 @@
|
|||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetFormatPatch(t *testing.T) {
|
func TestGetFormatPatch(t *testing.T) {
|
||||||
repo, err := OpenRepository(".");
|
repo, err := OpenRepository(".")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
patchb, err := repo.GetFormatPatch("cdb43f0e^", "cdb43f0e")
|
rd, err := repo.GetFormatPatch("cdb43f0e^", "cdb43f0e")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
patchb, err := ioutil.ReadAll(rd)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
patch := string(patchb)
|
patch := string(patchb)
|
||||||
assert.Regexp(t, "^From cdb43f0e", patch)
|
assert.Regexp(t, "^From cdb43f0e", patch)
|
||||||
|
|||||||
Reference in New Issue
Block a user