@@ -406,3 +406,46 @@ void test_refs_reflog_messages__detaching_head_default_message(void)
406406
407407 cl_assert_equal_i (false, git_repository_head_detached (g_repo ));
408408}
409+
410+ void test_refs_reflog_messages__renaming_checked_out_branch_updates_HEAD_reflog (void )
411+ {
412+ git_reference * head_ref , * current_ref , * renamed_ref ;
413+ int nentries , nentries_after ;
414+ git_buf msg = GIT_BUF_INIT ;
415+
416+ cl_git_pass (git_repository_head (& head_ref , g_repo ));
417+
418+ cl_git_pass (git_reference_resolve (& current_ref , head_ref ));
419+
420+ nentries = reflog_entrycount (g_repo , GIT_HEAD_FILE );
421+
422+ cl_git_pass (git_branch_move (& renamed_ref , current_ref , "refs/heads/renamed" , 1 ));
423+
424+ nentries_after = reflog_entrycount (g_repo , GIT_HEAD_FILE );
425+
426+ cl_assert_equal_i (nentries + 1 , nentries_after );
427+ cl_reflog_check_entry (g_repo , GIT_HEAD_FILE , 0 ,
428+ GIT_OID_HEX_ZERO ,
429+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750" ,
430+ NULL , "checkout: moving from master to refs/heads/renamed" );
431+
432+ goto cleanup ; /* FIXME: See #4292 */
433+
434+ git_buf_printf (& msg , "Branch: renamed %s to %s" , git_reference_name (current_ref ), git_reference_name (renamed_ref ));
435+ cl_assert_equal_i (nentries + 2 , nentries_after );
436+ cl_reflog_check_entry (g_repo , GIT_HEAD_FILE , 0 ,
437+ GIT_OID_HEX_ZERO ,
438+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750" ,
439+ NULL , git_buf_cstr (& msg ));
440+
441+ cl_reflog_check_entry (g_repo , GIT_HEAD_FILE , 1 ,
442+ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750" ,
443+ GIT_OID_HEX_ZERO ,
444+ NULL , git_buf_cstr (& msg ));
445+
446+ cleanup :
447+ git_buf_free (& msg );
448+ git_reference_free (head_ref );
449+ git_reference_free (current_ref );
450+ git_reference_free (renamed_ref );
451+ }
0 commit comments