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

Commit b3e9f25

Browse files
strklafriks
authored andcommitted
Add GetFormatPatch receiver for a repository (#103)
* Add GetFormatPatch receiver for a repository Includes test * Use binary for GetFormatPatch Also add missing test file * Add empty line
1 parent b8e8779 commit b3e9f25

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

repo_pull.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,8 @@ func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch stri
7373
func (repo *Repository) GetPatch(base, head string) ([]byte, error) {
7474
return NewCommand("diff", "-p", "--binary", base, head).RunInDirBytes(repo.Path)
7575
}
76+
77+
// 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+
}

repo_pull_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2018 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package git
6+
7+
import (
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func TestGetFormatPatch(t *testing.T) {
14+
repo, err := OpenRepository(".");
15+
assert.NoError(t, err)
16+
patchb, err := repo.GetFormatPatch("cdb43f0e^", "cdb43f0e")
17+
assert.NoError(t, err)
18+
patch := string(patchb)
19+
assert.Regexp(t, "^From cdb43f0e", patch)
20+
assert.Regexp(t, "Subject: .PATCH. add @daviian as maintainer", patch)
21+
}

0 commit comments

Comments
 (0)