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

Use io reader for GetFormatPatch #105

Merged
merged 1 commit into from
Jan 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions repo_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
package git

import (
"bytes"
"container/list"
"fmt"
"io"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -75,6 +77,13 @@ func (repo *Repository) GetPatch(base, head string) ([]byte, error) {
}

// GetFormatPatch generates and returns format-patch data between given revisions.
func (repo *Repository) GetFormatPatch(base, head string) ([]byte, error) {
return NewCommand("format-patch", "--binary", "--stdout", base + "..." + head).RunInDirBytes(repo.Path)
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
}
7 changes: 5 additions & 2 deletions repo_pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
package git

import (
"io/ioutil"
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetFormatPatch(t *testing.T) {
repo, err := OpenRepository(".");
repo, err := OpenRepository(".")
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)
patch := string(patchb)
assert.Regexp(t, "^From cdb43f0e", patch)
Expand Down