From 95849ccbf86964b52bb85e0cdca7b5354fbbf7e3 Mon Sep 17 00:00:00 2001 From: lhchavez Date: Tue, 18 Aug 2020 09:49:55 -0700 Subject: [PATCH] Remove the rebase-specific bits from this change --- go.mod | 2 - go.sum | 7 --- rebase.go | 75 +++--------------------------- rebase_test.go | 122 ------------------------------------------------- wrapper.c | 5 -- 5 files changed, 7 insertions(+), 204 deletions(-) delete mode 100644 go.sum diff --git a/go.mod b/go.mod index 11118cb..5d3beea 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,3 @@ module github.com/libgit2/git2go/v28 go 1.13 - -require golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de diff --git a/go.sum b/go.sum deleted file mode 100644 index 1769e6b..0000000 --- a/go.sum +++ /dev/null @@ -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= diff --git a/rebase.go b/rebase.go index d685f25..d29e183 100644 --- a/rebase.go +++ b/rebase.go @@ -2,8 +2,6 @@ package git /* #include - -extern void _go_git_populate_commit_sign_cb(git_rebase_options *opts); */ import "C" import ( @@ -71,66 +69,14 @@ func newRebaseOperationFromC(c *C.git_rebase_operation) *RebaseOperation { 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 type RebaseOptions struct { - Version uint - Quiet int - InMemory int - RewriteNotesRef string - MergeOptions MergeOptions - CheckoutOptions CheckoutOpts - CommitSigningCallback CommitSigningCallback + Version uint + Quiet int + InMemory int + RewriteNotesRef string + MergeOptions MergeOptions + CheckoutOptions CheckoutOpts } // DefaultRebaseOptions returns a RebaseOptions with default values. @@ -162,7 +108,7 @@ func (ro *RebaseOptions) toC() *C.git_rebase_options { if ro == nil { return nil } - opts := &C.git_rebase_options{ + return &C.git_rebase_options{ version: C.uint(ro.Version), quiet: C.int(ro.Quiet), inmemory: C.int(ro.InMemory), @@ -170,13 +116,6 @@ func (ro *RebaseOptions) toC() *C.git_rebase_options { merge_options: *ro.MergeOptions.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 { diff --git a/rebase_test.go b/rebase_test.go index a78e6c7..c7deef6 100644 --- a/rebase_test.go +++ b/rebase_test.go @@ -1,15 +1,10 @@ package git import ( - "bytes" "errors" "strconv" - "strings" "testing" "time" - - "golang.org/x/crypto/openpgp" - "golang.org/x/crypto/openpgp/packet" ) // Tests @@ -137,123 +132,6 @@ func TestRebaseNoConflicts(t *testing.T) { 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 func setupRepoForRebase(repo *Repository, masterCommit, branchName string, opts commitOpts) error { // Create a new branch from master diff --git a/wrapper.c b/wrapper.c index 99d2c62..64af1f3 100644 --- a/wrapper.c +++ b/wrapper.c @@ -11,11 +11,6 @@ void _go_git_populate_apply_cb(git_apply_options *options) 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) { opts->remote_cb = (git_remote_create_cb)remoteCreateCallback;