Remove the rebase-specific bits from this change
This commit is contained in:
parent
a6ef2b306f
commit
95849ccbf8
2
go.mod
2
go.mod
|
@ -1,5 +1,3 @@
|
||||||
module github.com/libgit2/git2go/v28
|
module github.com/libgit2/git2go/v28
|
||||||
|
|
||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
require golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de
|
|
||||||
|
|
7
go.sum
7
go.sum
|
@ -1,7 +0,0 @@
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
|
||||||
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig=
|
|
||||||
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
75
rebase.go
75
rebase.go
|
@ -2,8 +2,6 @@ package git
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
|
|
||||||
extern void _go_git_populate_commit_sign_cb(git_rebase_options *opts);
|
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
|
@ -71,66 +69,14 @@ func newRebaseOperationFromC(c *C.git_rebase_operation) *RebaseOperation {
|
||||||
return operation
|
return operation
|
||||||
}
|
}
|
||||||
|
|
||||||
//export commitSignCallback
|
|
||||||
func commitSignCallback(_signature *C.git_buf, _signature_field *C.git_buf, _commit_content *C.char, _payload unsafe.Pointer) C.int {
|
|
||||||
opts, ok := pointerHandles.Get(_payload).(*RebaseOptions)
|
|
||||||
if !ok {
|
|
||||||
panic("invalid sign payload")
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.CommitSigningCallback == nil {
|
|
||||||
return C.GIT_PASSTHROUGH
|
|
||||||
}
|
|
||||||
|
|
||||||
commitContent := C.GoString(_commit_content)
|
|
||||||
|
|
||||||
signature, signatureField, err := opts.CommitSigningCallback(commitContent)
|
|
||||||
if err != nil {
|
|
||||||
if gitError, ok := err.(*GitError); ok {
|
|
||||||
return C.int(gitError.Code)
|
|
||||||
}
|
|
||||||
return C.int(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
fillBuf := func(bufData string, buf *C.git_buf) error {
|
|
||||||
clen := C.size_t(len(bufData))
|
|
||||||
cstr := unsafe.Pointer(C.CString(bufData))
|
|
||||||
defer C.free(cstr)
|
|
||||||
|
|
||||||
// libgit2 requires the contents of the buffer to be NULL-terminated.
|
|
||||||
// C.CString() guarantees that the returned buffer will be
|
|
||||||
// NULL-terminated, so we can safely copy the terminator.
|
|
||||||
if int(C.git_buf_set(buf, cstr, clen+1)) != 0 {
|
|
||||||
return errors.New("could not set buffer")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if signatureField != "" {
|
|
||||||
err := fillBuf(signatureField, _signature_field)
|
|
||||||
if err != nil {
|
|
||||||
return C.int(-1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
err = fillBuf(signature, _signature)
|
|
||||||
if err != nil {
|
|
||||||
return C.int(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return C.GIT_OK
|
|
||||||
}
|
|
||||||
|
|
||||||
// RebaseOptions are used to tell the rebase machinery how to operate
|
// RebaseOptions are used to tell the rebase machinery how to operate
|
||||||
type RebaseOptions struct {
|
type RebaseOptions struct {
|
||||||
Version uint
|
Version uint
|
||||||
Quiet int
|
Quiet int
|
||||||
InMemory int
|
InMemory int
|
||||||
RewriteNotesRef string
|
RewriteNotesRef string
|
||||||
MergeOptions MergeOptions
|
MergeOptions MergeOptions
|
||||||
CheckoutOptions CheckoutOpts
|
CheckoutOptions CheckoutOpts
|
||||||
CommitSigningCallback CommitSigningCallback
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultRebaseOptions returns a RebaseOptions with default values.
|
// DefaultRebaseOptions returns a RebaseOptions with default values.
|
||||||
|
@ -162,7 +108,7 @@ func (ro *RebaseOptions) toC() *C.git_rebase_options {
|
||||||
if ro == nil {
|
if ro == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
opts := &C.git_rebase_options{
|
return &C.git_rebase_options{
|
||||||
version: C.uint(ro.Version),
|
version: C.uint(ro.Version),
|
||||||
quiet: C.int(ro.Quiet),
|
quiet: C.int(ro.Quiet),
|
||||||
inmemory: C.int(ro.InMemory),
|
inmemory: C.int(ro.InMemory),
|
||||||
|
@ -170,13 +116,6 @@ func (ro *RebaseOptions) toC() *C.git_rebase_options {
|
||||||
merge_options: *ro.MergeOptions.toC(),
|
merge_options: *ro.MergeOptions.toC(),
|
||||||
checkout_options: *ro.CheckoutOptions.toC(),
|
checkout_options: *ro.CheckoutOptions.toC(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if ro.CommitSigningCallback != nil {
|
|
||||||
C._go_git_populate_commit_sign_cb(opts)
|
|
||||||
opts.payload = pointerHandles.Track(ro)
|
|
||||||
}
|
|
||||||
|
|
||||||
return opts
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapEmptyStringToNull(ref string) *C.char {
|
func mapEmptyStringToNull(ref string) *C.char {
|
||||||
|
|
122
rebase_test.go
122
rebase_test.go
|
@ -1,15 +1,10 @@
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/crypto/openpgp"
|
|
||||||
"golang.org/x/crypto/openpgp/packet"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tests
|
// Tests
|
||||||
|
@ -137,123 +132,6 @@ func TestRebaseNoConflicts(t *testing.T) {
|
||||||
assertStringList(t, expectedHistory, actualHistory)
|
assertStringList(t, expectedHistory, actualHistory)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRebaseGpgSigned(t *testing.T) {
|
|
||||||
// TEST DATA
|
|
||||||
|
|
||||||
entity, err := openpgp.NewEntity("Namey mcnameface", "test comment", "test@example.com", nil)
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
opts, err := DefaultRebaseOptions()
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
signCommitContent := func(commitContent string) (string, string, error) {
|
|
||||||
cipherText := new(bytes.Buffer)
|
|
||||||
err := openpgp.ArmoredDetachSignText(cipherText, entity, strings.NewReader(commitContent), &packet.Config{})
|
|
||||||
if err != nil {
|
|
||||||
return "", "", errors.New("error signing payload")
|
|
||||||
}
|
|
||||||
|
|
||||||
return cipherText.String(), "", nil
|
|
||||||
}
|
|
||||||
opts.CommitSigningCallback = signCommitContent
|
|
||||||
|
|
||||||
commitOpts := commitOpts{
|
|
||||||
CommitSigningCallback: signCommitContent,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inputs
|
|
||||||
branchName := "emile"
|
|
||||||
masterCommit := "something"
|
|
||||||
emileCommits := []string{
|
|
||||||
"fou",
|
|
||||||
"barre",
|
|
||||||
"ouich",
|
|
||||||
}
|
|
||||||
|
|
||||||
// Outputs
|
|
||||||
expectedHistory := []string{
|
|
||||||
"Test rebase, Baby! " + emileCommits[2],
|
|
||||||
"Test rebase, Baby! " + emileCommits[1],
|
|
||||||
"Test rebase, Baby! " + emileCommits[0],
|
|
||||||
"Test rebase, Baby! " + masterCommit,
|
|
||||||
"This is a commit\n",
|
|
||||||
}
|
|
||||||
|
|
||||||
// TEST
|
|
||||||
repo := createTestRepo(t)
|
|
||||||
defer cleanupTestRepo(t, repo)
|
|
||||||
seedTestRepoOpt(t, repo, commitOpts)
|
|
||||||
|
|
||||||
// Try to open existing rebase
|
|
||||||
_, err = repo.OpenRebase(nil)
|
|
||||||
if err == nil {
|
|
||||||
t.Fatal("Did not expect to find a rebase in progress")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup a repo with 2 branches and a different tree
|
|
||||||
err = setupRepoForRebase(repo, masterCommit, branchName, commitOpts)
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
// Create several commits in emile
|
|
||||||
for _, commit := range emileCommits {
|
|
||||||
_, err = commitSomething(repo, commit, commit, commitOpts)
|
|
||||||
checkFatal(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rebase onto master
|
|
||||||
rebase, err := performRebaseOnto(repo, "master", &opts)
|
|
||||||
checkFatal(t, err)
|
|
||||||
defer rebase.Free()
|
|
||||||
|
|
||||||
// Finish the rebase properly
|
|
||||||
err = rebase.Finish()
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
// Check history is in correct order
|
|
||||||
actualHistory, err := commitMsgsList(repo)
|
|
||||||
checkFatal(t, err)
|
|
||||||
assertStringList(t, expectedHistory, actualHistory)
|
|
||||||
|
|
||||||
checkAllCommitsSigned(t, entity, repo)
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkAllCommitsSigned(t *testing.T, entity *openpgp.Entity, repo *Repository) {
|
|
||||||
head, err := headCommit(repo)
|
|
||||||
checkFatal(t, err)
|
|
||||||
defer head.Free()
|
|
||||||
|
|
||||||
parent := head
|
|
||||||
|
|
||||||
err = checkCommitSigned(t, entity, parent)
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
for parent.ParentCount() != 0 {
|
|
||||||
parent = parent.Parent(0)
|
|
||||||
defer parent.Free()
|
|
||||||
|
|
||||||
err = checkCommitSigned(t, entity, parent)
|
|
||||||
checkFatal(t, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkCommitSigned(t *testing.T, entity *openpgp.Entity, commit *Commit) error {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
signature, signedData, err := commit.ExtractSignature()
|
|
||||||
if err != nil {
|
|
||||||
t.Logf("No signature on commit\n%s", commit.ContentToSign())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = openpgp.CheckArmoredDetachedSignature(openpgp.EntityList{entity}, strings.NewReader(signedData), bytes.NewBufferString(signature))
|
|
||||||
if err != nil {
|
|
||||||
t.Logf("Commit is not signed correctly\n%s", commit.ContentToSign())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
func setupRepoForRebase(repo *Repository, masterCommit, branchName string, opts commitOpts) error {
|
func setupRepoForRebase(repo *Repository, masterCommit, branchName string, opts commitOpts) error {
|
||||||
// Create a new branch from master
|
// Create a new branch from master
|
||||||
|
|
|
@ -11,11 +11,6 @@ void _go_git_populate_apply_cb(git_apply_options *options)
|
||||||
options->hunk_cb = (git_apply_hunk_cb)hunkApplyCallback;
|
options->hunk_cb = (git_apply_hunk_cb)hunkApplyCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _go_git_populate_commit_sign_cb(git_rebase_options *opts)
|
|
||||||
{
|
|
||||||
opts->signing_cb = (git_commit_signing_cb)commitSignCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
void _go_git_populate_remote_cb(git_clone_options *opts)
|
void _go_git_populate_remote_cb(git_clone_options *opts)
|
||||||
{
|
{
|
||||||
opts->remote_cb = (git_remote_create_cb)remoteCreateCallback;
|
opts->remote_cb = (git_remote_create_cb)remoteCreateCallback;
|
||||||
|
|
Loading…
Reference in New Issue