From 6fd42e2244d34e9e9c7320252365750a17f4a2f4 Mon Sep 17 00:00:00 2001 From: Steven King Jr Date: Tue, 29 Jan 2019 14:26:16 -0700 Subject: [PATCH 1/4] Fix order of `fp.assign` args --- lib/commit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/commit.js b/lib/commit.js index 734cfc781..fe8802299 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -130,8 +130,8 @@ Commit.prototype.amendWithSignature = function( message: resolvedMessage, tree: resolvedTree } = fp.assign( - truthyArgs, - commitFields + commitFields, + truthyArgs ); return Commit.createBuffer( From 94313ea4447217e4c0283cd731f1e8b5ef2f8ec3 Mon Sep 17 00:00:00 2001 From: Steven King Jr Date: Tue, 29 Jan 2019 14:43:02 -0700 Subject: [PATCH 2/4] Do not append an additional newline to `amend` commit buffers --- lib/commit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commit.js b/lib/commit.js index fe8802299..fe32b5e31 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -146,7 +146,7 @@ Commit.prototype.amendWithSignature = function( ); }) .then(function(commitContentResult) { - commitContent = commitContentResult + "\n"; + commitContent = commitContentResult; return onSignature(commitContent); }) .then(function(signature) { From b0c33bf51b88d00697b101d1f3677f5f72cf8881 Mon Sep 17 00:00:00 2001 From: Steven King Jr Date: Tue, 29 Jan 2019 14:45:35 -0700 Subject: [PATCH 3/4] Update tests --- test/tests/commit.js | 92 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/test/tests/commit.js b/test/tests/commit.js index 9bb0e4b2d..522017bc7 100644 --- a/test/tests/commit.js +++ b/test/tests/commit.js @@ -488,7 +488,7 @@ describe("Commit", function() { return repo.getHeadCommit(); }) .then(function(headCommit) { - message = headCommit.message().trim(); + message = headCommit.message(); parents = headCommit.parents(); return headCommit.amendWithSignature( @@ -512,11 +512,99 @@ describe("Commit", function() { }) .then(function(signatureInfo) { assert.equal(signatureInfo.signature, signature); - assert.equal(commit.message().trim(), message); + assert.equal(commit.message(), message); assert.deepEqual(commit.parents(), parents); }); }); + it("amending with signature respects overridden arguments", function() { + const signature = "-----BEGIN PGP SIGNATURE-----\n" + + "\n" + + "iQJHBAEBCAAxFiEEKdxGpJ93wnkLaBKfURjJKedOfEMFAlxPKUYTHHN0ZXZla0Bh\n" + + "eG9zb2Z0LmNvbQAKCRBRGMkp5058Q3vcD/0Uf6P68g98Kbvsgjg/aidM1ujruXaw\n" + + "X5WSsCAw+wWGICOj0n+KBnmQruI4HSFz3zykEshuOpcBv1X/+huwDeB/hBqonCU8\n" + + "QdexCdWR70YbT1bufesUwV9v1qwE4WOmFxWXgwh55K0wDRkc0u2aLcwrJkIEEVfs\n" + + "HqZyFzU4kwbGekY/m7d1DsBhWyKEGW9/25WMYmjWOWOiaFjeBaHLlxiEM8KGnMLH\n" + + "wx37NuFuaABgi23AAcBGdeWy04TEuU4S51+bHM3RotrZ2cryW2lEbkkXodhIJcq0\n" + + "RgrStCbvR0ehnOPdYSiRbxK8JNLZuNjHlK2g7wVi+C83vwMQuhU4H6OlYHGVr664\n" + + "4YzL83FdIo7wiMOFd2OOMLlCfHgTun60FvjCs4WHjrwH1fQl287FRPLa/4olBSQP\n" + + "yUXJaZdxm4cB4L/1pmbb/J/XUiOio3MpaN3GFm2hZloUlag1uPDBtCxTl5odvj4a\n" + + "GOmTBWznXxF/zrKnQVSvv+EccNxYFc0VVjAxGgNqPzIxDAKtw1lE5pbBkFpFpNHz\n" + + "StmwZkP9QIJY4hJYQfM+pzHLe8xjexL+Kh/TrYXgY1m/4vJe0HJSsnRnaR8Yfqhh\n" + + "LReqo94VHRYXR0rZQv4py0D9TrWaI8xHLve6ewhLPNRzyaI9fNrinbcPYZZOWnRi\n" + + "ekgUBx+BX6nJOw==\n" + + "=4Hy5\n" + + "-----END PGP SIGNATURE-----"; + + function onSignature(dataToSign) { + return new Promise(function (resolve) { + return resolve(signature); + }); + } + + var repo; + var oid; + var commit; + var message; + var parents; + var commitTree; + + var author = NodeGit.Signature.create( + "Scooby Doo", + "scoob@mystery.com", + 123456789, + 60 + ); + var committer = NodeGit.Signature.create( + "Shaggy Rogers", + "shaggy@mystery.com", + 987654321, + 90 + ); + var tree = Oid.fromString("f4661419a6fbbe865f78644fec722c023ce4b65f"); + + return NodeGit.Repository.open(reposPath) + .then(function(repoResult) { + repo = repoResult; + return repo.getHeadCommit(); + }) + .then(function(headCommit) { + message = headCommit.message(); + parents = headCommit.parents(); + + return headCommit.amendWithSignature( + null, + author, + committer, + null, + null, + tree, + "gpgsig", + onSignature + ); + }) + .then(function(oidResult) { + oid = oidResult; + return NodeGit.Commit.lookup(repo, oid); + }) + .then(function(commitResult) { + commit = commitResult; + return commit.getTree(); + }) + .then(function(commitTreeResult) { + commitTree = commitTreeResult; + return commit.getSignature("gpgsig"); + }) + .then(function(signatureInfo) { + assert.equal(signatureInfo.signature, signature); + assert.equal(commit.message(), message); + assert.deepEqual(commit.parents(), parents); + assert.deepEqual(commitTree.id(), tree); + assert.deepEqual(commit.author(), author); + assert.deepEqual(commit.committer(), committer); + }); + }); + it("has an owner", function() { var owner = this.commit.owner(); assert.ok(owner instanceof Repository); From b6498b0a2f69d2ac9ed78d48b521f4c0c2b1b637 Mon Sep 17 00:00:00 2001 From: Steven King Jr Date: Wed, 30 Jan 2019 09:39:25 -0700 Subject: [PATCH 4/4] Pad commit buffer with newline only if it does not already end with newline --- lib/commit.js | 3 +++ lib/repository.js | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/commit.js b/lib/commit.js index fe32b5e31..02b3679d5 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -147,6 +147,9 @@ Commit.prototype.amendWithSignature = function( }) .then(function(commitContentResult) { commitContent = commitContentResult; + if (!commitContent.endsWith("\n")) { + commitContent += "\n"; + } return onSignature(commitContent); }) .then(function(signature) { diff --git a/lib/repository.js b/lib/repository.js index 1962d894d..d036486d4 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -698,7 +698,10 @@ Repository.prototype.createCommitWithSignature = function( parents ); }).then(function(commit_contentResult) { - commit_content = commit_contentResult + "\n"; + commit_content = commit_contentResult; + if (!commit_content.endsWith("\n")) { + commit_content += "\n"; + } return onSignature(commit_content); }).then(function(signature) { return Commit.createWithSignature(