Skip to content

Commit b7f542c

Browse files
committed
Adjust Repository#createCommitWithSignature to account for updateRef
1 parent e693f32 commit b7f542c

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

test/tests/commit.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,7 @@ describe("Commit", function() {
867867
var committer = signatures[1];
868868

869869
return repo.createCommitWithSignature(
870+
null,
870871
author,
871872
committer,
872873
"message",
@@ -884,7 +885,112 @@ describe("Commit", function() {
884885
})
885886
.then(function(signatureInfo) {
886887
assert.equal(signature, signatureInfo.signature);
888+
return reinitialize(test);
889+
}, function(reason) {
890+
return reinitialize(test)
891+
.then(function() {
892+
return Promise.reject(reason);
893+
});
894+
});
895+
});
896+
897+
it("Can create a signed commit in a repo and update refs", function() {
898+
899+
var signature = "-----BEGIN PGP SIGNATURE-----\n" +
900+
"Version: GnuPG v1.4.12 (Darwin)\n" +
901+
"\n" +
902+
"iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al\n" +
903+
"o6IoMAhv0Z/LHlWhzBd9e7JeCnanRt12bAU7yvYp9+Z+z+dbwqLwDoFp8LVuigl8\n" +
904+
"JGLcnwiUW3rSvhjdCp9irdb4+bhKUnKUzSdsR2CK4/hC0N2i/HOvMYX+BRsvqweq\n" +
905+
"AsAkA6dAWh+gAfedrBUkCTGhlNYoetjdakWqlGL1TiKAefEZrtA1TpPkGn92vbLq\n" +
906+
"SphFRUY9hVn1ZBWrT3hEpvAIcZag3rTOiRVT1X1flj8B2vGCEr3RrcwOIZikpdaW\n" +
907+
"who/X3xh/DGbI2RbuxmmJpxxP/8dsVchRJJzBwG+yhwU/iN3MlV2c5D69tls/Dok\n" +
908+
"6VbyU4lm/ae0y3yR83D9dUlkycOnmmlBAHKIZ9qUts9X7mWJf0+yy2QxJVpjaTGG\n" +
909+
"cmnQKKPeNIhGJk2ENnnnzjEve7L7YJQF6itbx5VCOcsGh3Ocb3YR7DMdWjt7f8pu\n" +
910+
"c6j+q1rP7EpE2afUN/geSlp5i3x8aXZPDj67jImbVCE/Q1X9voCtyzGJH7MXR0N9\n" +
911+
"ZpRF8yzveRfMH8bwAJjSOGAFF5XkcR/RNY95o+J+QcgBLdX48h+ZdNmUf6jqlu3J\n" +
912+
"7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc\n" +
913+
"cpxtDQQMGYFpXK/71stq\n" +
914+
"=ozeK\n" +
915+
"-----END PGP SIGNATURE-----";
916+
917+
function onSignature(dataToSign) {
918+
return new Promise(function (resolve) {
919+
return resolve(signature);
920+
});
921+
}
922+
923+
var test = this;
924+
var expectedCommitId = "ccb99bb20716ef7c37e92c7b8db029a7af7f747b";
925+
var fileName = "newfile.txt";
926+
var fileContent = "hello world";
927+
928+
var repo;
929+
var index;
930+
var treeOid;
931+
var parent;
932+
933+
return NodeGit.Repository.open(reposPath)
934+
.then(function(repoResult) {
935+
repo = repoResult;
936+
return fse.writeFile(path.join(repo.workdir(), fileName), fileContent);
937+
})
938+
.then(function() {
939+
return repo.refreshIndex();
940+
})
941+
.then(function(indexResult) {
942+
index = indexResult;
943+
})
944+
.then(function() {
945+
return index.addByPath(fileName);
946+
})
947+
.then(function() {
948+
return index.write();
949+
})
950+
.then(function() {
951+
return index.writeTree();
952+
})
953+
.then(function(oidResult) {
954+
treeOid = oidResult;
955+
return NodeGit.Reference.nameToId(repo, "HEAD");
956+
})
957+
.then(function(head) {
958+
return repo.getCommit(head);
959+
})
960+
.then(function(parentResult) {
961+
parent = parentResult;
962+
return Promise.all([
963+
NodeGit.Signature.create("Foo Bar", "foo@bar.com", 123456789, 60),
964+
NodeGit.Signature.create("Foo A Bar", "foo@bar.com", 987654321, 90)
965+
]);
966+
})
967+
.then(function(signatures) {
968+
var author = signatures[0];
969+
var committer = signatures[1];
887970

971+
return repo.createCommitWithSignature(
972+
"HEAD",
973+
author,
974+
committer,
975+
"message",
976+
treeOid,
977+
[parent],
978+
"gpgsig",
979+
onSignature);
980+
})
981+
.then(function(commitId) {
982+
assert.equal(expectedCommitId, commitId);
983+
return NodeGit.Commit.lookup(repo, commitId);
984+
})
985+
.then(function(commit) {
986+
return commit.getSignature("gpgsig");
987+
})
988+
.then(function(signatureInfo) {
989+
assert.equal(signature, signatureInfo.signature);
990+
return repo.getHeadCommit();
991+
})
992+
.then(function(headCommit) {
993+
assert.equal(expectedCommitId, headCommit.id());
888994
return undoCommit()
889995
.then(function(){
890996
return reinitialize(test);

0 commit comments

Comments
 (0)