Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit f4a9105

Browse files
authored
use io reader for GetFormatPatch (#105)
1 parent 2c3dc95 commit f4a9105

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Diff for: repo_pull.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
package git
66

77
import (
8+
"bytes"
89
"container/list"
910
"fmt"
11+
"io"
1012
"strconv"
1113
"strings"
1214
"time"
@@ -75,6 +77,13 @@ func (repo *Repository) GetPatch(base, head string) ([]byte, error) {
7577
}
7678

7779
// GetFormatPatch generates and returns format-patch data between given revisions.
78-
func (repo *Repository) GetFormatPatch(base, head string) ([]byte, error) {
79-
return NewCommand("format-patch", "--binary", "--stdout", base + "..." + head).RunInDirBytes(repo.Path)
80+
func (repo *Repository) GetFormatPatch(base, head string) (io.Reader, error) {
81+
stdout := new(bytes.Buffer)
82+
stderr := new(bytes.Buffer)
83+
84+
if err := NewCommand("format-patch", "--binary", "--stdout", base+"..."+head).
85+
RunInDirPipeline(repo.Path, stdout, stderr); err != nil {
86+
return nil, concatenateError(err, stderr.String())
87+
}
88+
return stdout, nil
8089
}

Diff for: repo_pull_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
package git
66

77
import (
8+
"io/ioutil"
89
"testing"
910

1011
"github.com/stretchr/testify/assert"
1112
)
1213

1314
func TestGetFormatPatch(t *testing.T) {
14-
repo, err := OpenRepository(".");
15+
repo, err := OpenRepository(".")
1516
assert.NoError(t, err)
16-
patchb, err := repo.GetFormatPatch("cdb43f0e^", "cdb43f0e")
17+
rd, err := repo.GetFormatPatch("cdb43f0e^", "cdb43f0e")
18+
assert.NoError(t, err)
19+
patchb, err := ioutil.ReadAll(rd)
1720
assert.NoError(t, err)
1821
patch := string(patchb)
1922
assert.Regexp(t, "^From cdb43f0e", patch)

0 commit comments

Comments
 (0)