Skip to content
Open
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
2 changes: 1 addition & 1 deletion generate/input/callbacks.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
},
{
"name": "parents",
"cType": "const git_oid * []"
"cType": "const git_commit * []"
},
{
"name": "payload",
Expand Down
4 changes: 2 additions & 2 deletions generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -3142,10 +3142,10 @@
},
{
"name": "parents",
"cType": "const git_oid **",
"cType": "const git_commit **",
"cppClassName": "Array",
"jsClassName": "Array",
"arrayElementCppClassName": "GitOid",
"arrayElementCppClassName": "GitCommit",
"arrayLengthArgumentName": "parent_count"
},
{
Expand Down
4 changes: 2 additions & 2 deletions generate/templates/partials/configurable_callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@
else if (!result->IsNull() && !result->IsUndefined()) {
{% if _return.isOutParam %}
{{ _return.cppClassName }}* wrapper = Nan::ObjectWrap::Unwrap<{{ _return.cppClassName }}>(Nan::To<v8::Object>(result).ToLocalChecked());
wrapper->selfFreeing = false;

{% if _return.cppClassName == "GitOid" %}
git_oid_cpy(baton->{{ _return.name }}, wrapper->GetValue());
{% else %}
wrapper->selfFreeing = false;
*baton->{{ _return.name }} = wrapper->GetValue();
{% endif %}
baton->result = {{ field.return.success }};
Expand Down Expand Up @@ -185,11 +185,11 @@
else if (!result->IsNull() && !result->IsUndefined()) {
{% if _return.isOutParam %}
{{ _return.cppClassName }}* wrapper = Nan::ObjectWrap::Unwrap<{{ _return.cppClassName }}>(Nan::To<v8::Object>(result).ToLocalChecked());
wrapper->selfFreeing = false;

{% if _return.cppClassName == "GitOid" %}
git_oid_cpy(baton->{{ _return.name }}, wrapper->GetValue());
{% else %}
wrapper->selfFreeing = false;
*baton->{{ _return.name }} = wrapper->GetValue();
{% endif %}
baton->result = {{ field.return.success }};
Expand Down
90 changes: 43 additions & 47 deletions lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,11 @@ Repository.prototype.createCommitBuffer = function(
* @param {Signature} committer
* @param {String} message
* @param {Tree|Oid|String} Tree
* @param {Array} parents
* @param {Array of Commits} parents
* @param {Function} onSignature Callback to be called with string to be signed
* @return {Oid} The oid of the commit
*/
Repository.prototype.createCommitWithSignature = function(
Repository.prototype.createCommitWithSignature = async function(
updateRef,
author,
committer,
Expand All @@ -636,32 +636,33 @@ Repository.prototype.createCommitWithSignature = function(
parents,
onSignature
) {
let repo = this;
let newParents = [];
let skippedSigning = false;

var repo = this;
var promises = [];
var commitContent;
var skippedSigning;

parents = parents || [];

promises.push(repo.getTree(tree));
if (!(tree instanceof Tree)) {
tree = await repo.getTree(tree);
}

parents.forEach(function(parent) {
promises.push(repo.getCommit(parent));
let showDeprecationWarning = false;
parents.forEach(async (parent) => {
if (parent instanceof Commit) {
newParents.push(parent);
} else {
newParents.push(await repo.getCommit(parent));
showDeprecationWarning = true;
}
});

const createCommitPromise = Promise.all(promises).then(function(results) {
tree = results[0];

// Get the normalized values for our input into the function
var parentsLength = parents.length;
parents = [];
if (showDeprecationWarning) {
console.warn("DeprecationWarning: Parents in Repository.createCommitWithSignature " +
"should be an array of Commits instead an array of Oid|String");
}

for (var i = 0; i < parentsLength; i++) {
parents.push(results[i + 1]);
}
parents = newParents;

return Commit.createBuffer(
const createCommitPromise = async () => {
let commitContent = await Commit.createBuffer(
repo,
author,
committer,
Expand All @@ -671,13 +672,12 @@ Repository.prototype.createCommitWithSignature = function(
parents.length,
parents
);
}).then(function(commitContentResult) {
commitContent = commitContentResult;
if (!commitContent.endsWith("\n")) {
commitContent += "\n";
}
return onSignature(commitContent);
}).then(function({ code, field, signedData }) {

const { code, field, signedData } = await onSignature(commitContent);

switch (code) {
case NodeGit.Error.CODE.OK:
return Commit.createWithSignature(
Expand Down Expand Up @@ -708,32 +708,28 @@ Repository.prototype.createCommitWithSignature = function(
throw error;
}
}
});
};

if (!updateRef) {
return createCommitPromise;
return createCommitPromise();
}

return createCommitPromise
.then(function(commitOid) {
if (skippedSigning) {
return commitOid;
}
const commitOid = await createCommitPromise();
if (skippedSigning) {
return commitOid;
}

return repo.getCommit(commitOid)
.then(function(commitResult) {
return Reference.updateTerminal(
repo,
updateRef,
commitOid,
getReflogMessageForCommit(commitResult),
committer
);
})
.then(function() {
return commitOid;
});
});
const commitResult = await repo.getCommit(commitOid);

await Reference.updateTerminal(
repo,
updateRef,
commitOid,
getReflogMessageForCommit(commitResult),
committer
);

return commitOid;
};

/**
Expand Down