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

Add GetFormatPatch receiver for a repository #103

Merged
merged 3 commits into from
Jan 5, 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
5 changes: 5 additions & 0 deletions repo_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,8 @@ func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch stri
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) ([]byte, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the gitea PR I'd implement a GetFormatPatchReader(base, head string) (io.ReadCloser, error) as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm out of time for today so what about merging this and then improve later ? I'm looking forward for your PR implementing the "Reader" version of both methods (GetPatchReader and GEtFormatPatchReader)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging @strk PR would be much appreciated.

return NewCommand("format-patch", "--binary", "--stdout", base + "..." + head).RunInDirBytes(repo.Path)
}
21 changes: 21 additions & 0 deletions repo_pull_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package git

import (
"testing"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add an empty line here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done with 9783381


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

func TestGetFormatPatch(t *testing.T) {
repo, err := OpenRepository(".");
assert.NoError(t, err)
patchb, err := repo.GetFormatPatch("cdb43f0e^", "cdb43f0e")
assert.NoError(t, err)
patch := string(patchb)
assert.Regexp(t, "^From cdb43f0e", patch)
assert.Regexp(t, "Subject: .PATCH. add @daviian as maintainer", patch)
}