Skip to content

Commit 278d269

Browse files
committed
Allow update_ref to be null
libgit2 allows this parameter to be null
1 parent d52829e commit 278d269

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

generate/input/descriptor.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@
360360
},
361361
"tree": {
362362
"isOptional": true
363+
},
364+
"update_ref": {
365+
"isOptional": true
363366
}
364367
}
365368
},

test/tests/commit.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,59 @@ describe("Commit", function() {
277277
});
278278
});
279279

280+
it("can amend commit and update reference separately", function() {
281+
var customReflogMessage = "updating reference manually";
282+
283+
var head, repo, oid, originalReflogCount;
284+
285+
return NodeGit.Repository.open(reposPath)
286+
.then(function(repoResult) {
287+
repo = repoResult;
288+
// grab the original reflog entry count (to make sure .amend
289+
// doesn't add a reflog entry when not given a reference)
290+
return NodeGit.Reflog.read(repo, "HEAD");
291+
})
292+
.then(function(reflog) {
293+
originalReflogCount = reflog.entrycount();
294+
// get the head reference and commit
295+
return repo.head();
296+
})
297+
.then(function(headResult) {
298+
head = headResult;
299+
return repo.getHeadCommit();
300+
})
301+
.then(function(headCommit) {
302+
// amend the commit but don't update any reference
303+
// (passing null as update_ref)
304+
return headCommit.amend(
305+
null,
306+
null,
307+
null,
308+
"message",
309+
null,
310+
null);
311+
}).then(function(oidResult) {
312+
oid = oidResult;
313+
// update the reference manually
314+
return head.setTarget(oid, customReflogMessage);
315+
}).then(function() {
316+
// load reflog and make sure the last message is what we expected
317+
return NodeGit.Reflog.read(repo, "HEAD");
318+
}).then(function(reflog) {
319+
var reflogEntry = reflog.entryByIndex(0);
320+
assert.equal(
321+
NodeGit.Reflog.entryMessage(reflogEntry),
322+
customReflogMessage
323+
);
324+
assert.equal(
325+
NodeGit.Reflog.entryIdNew(reflogEntry).toString(),
326+
oid
327+
);
328+
// only setTarget should have added to the entrycount
329+
assert.equal(reflog.entrycount(), originalReflogCount + 1);
330+
});
331+
});
332+
280333
it("has an owner", function() {
281334
var owner = this.commit.owner();
282335
assert.ok(owner instanceof Repository);

0 commit comments

Comments
 (0)