@@ -462,6 +462,8 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
462
462
{
463
463
struct strbuf oldref = STRBUF_INIT , newref = STRBUF_INIT , logmsg = STRBUF_INIT ;
464
464
struct strbuf oldsection = STRBUF_INIT , newsection = STRBUF_INIT ;
465
+ const char * interpreted_oldname = NULL ;
466
+ const char * interpreted_newname = NULL ;
465
467
int recovery = 0 ;
466
468
467
469
if (!oldname ) {
@@ -493,6 +495,11 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
493
495
494
496
reject_rebase_or_bisect_branch (oldref .buf );
495
497
498
+ if (!skip_prefix (oldref .buf , "refs/heads/" , & interpreted_oldname ) ||
499
+ !skip_prefix (newref .buf , "refs/heads/" , & interpreted_newname )) {
500
+ die ("BUG: expected prefix missing for refs" );
501
+ }
502
+
496
503
if (copy )
497
504
strbuf_addf (& logmsg , "Branch: copied %s to %s" ,
498
505
oldref .buf , newref .buf );
@@ -507,11 +514,11 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
507
514
508
515
if (recovery ) {
509
516
if (copy )
510
- warning (_ ("Copied a misnamed branch '%s' away " ),
511
- oldref . buf + 11 );
517
+ warning (_ ("Created a copy of a misnamed branch '%s'" ),
518
+ interpreted_oldname );
512
519
else
513
520
warning (_ ("Renamed a misnamed branch '%s' away" ),
514
- oldref . buf + 11 );
521
+ interpreted_oldname );
515
522
}
516
523
517
524
if (!copy &&
@@ -520,9 +527,9 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
520
527
521
528
strbuf_release (& logmsg );
522
529
523
- strbuf_addf (& oldsection , "branch.%s" , oldref . buf + 11 );
530
+ strbuf_addf (& oldsection , "branch.%s" , interpreted_oldname );
524
531
strbuf_release (& oldref );
525
- strbuf_addf (& newsection , "branch.%s" , newref . buf + 11 );
532
+ strbuf_addf (& newsection , "branch.%s" , interpreted_newname );
526
533
strbuf_release (& newref );
527
534
if (!copy && git_config_rename_section (oldsection .buf , newsection .buf ) < 0 )
528
535
die (_ ("Branch is renamed, but update of config-file failed" ));
@@ -806,7 +813,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
806
813
die (_ ("the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead." ));
807
814
808
815
create_branch (argv [0 ], (argc == 2 ) ? argv [1 ] : head ,
809
- force , reflog , 0 , quiet , track );
816
+ force , 0 , reflog , quiet , track );
810
817
811
818
} else
812
819
usage_with_options (builtin_branch_usage , options );
0 commit comments