@@ -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