@@ -48,7 +48,6 @@ static int option_verbosity;
4848static int option_progress ;
4949static struct string_list option_config ;
5050static struct string_list option_reference ;
51- static const char * src_ref_prefix = "refs/heads/" ;
5251
5352static int opt_parse_reference (const struct option * opt , const char * arg , int unset )
5453{
@@ -413,6 +412,17 @@ static void remove_junk_on_signal(int signo)
413412 raise (signo );
414413}
415414
415+ static struct ref * find_remote_branch (const struct ref * refs , const char * branch )
416+ {
417+ struct ref * ref ;
418+ struct strbuf head = STRBUF_INIT ;
419+ strbuf_addstr (& head , "refs/heads/" );
420+ strbuf_addstr (& head , branch );
421+ ref = find_ref_by_name (refs , head .buf );
422+ strbuf_release (& head );
423+ return ref ;
424+ }
425+
416426static struct ref * wanted_peer_refs (const struct ref * refs ,
417427 struct refspec * refspec )
418428{
@@ -425,13 +435,8 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
425435
426436 if (!option_branch )
427437 remote_head = guess_remote_head (head , refs , 0 );
428- else {
429- struct strbuf sb = STRBUF_INIT ;
430- strbuf_addstr (& sb , src_ref_prefix );
431- strbuf_addstr (& sb , option_branch );
432- remote_head = find_ref_by_name (refs , sb .buf );
433- strbuf_release (& sb );
434- }
438+ else
439+ remote_head = find_remote_branch (refs , option_branch );
435440
436441 if (!remote_head && option_branch )
437442 warning (_ ("Could not find remote branch %s to clone." ),
@@ -502,7 +507,7 @@ static void update_remote_refs(const struct ref *refs,
502507static void update_head (const struct ref * our , const struct ref * remote ,
503508 const char * msg )
504509{
505- if (our ) {
510+ if (our && ! prefixcmp ( our -> name , "refs/heads/" ) ) {
506511 /* Local default branch link */
507512 create_symref ("HEAD" , our -> name , NULL );
508513 if (!option_bare ) {
@@ -609,6 +614,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
609614 struct strbuf key = STRBUF_INIT , value = STRBUF_INIT ;
610615 struct strbuf branch_top = STRBUF_INIT , reflog_msg = STRBUF_INIT ;
611616 struct transport * transport = NULL ;
617+ const char * src_ref_prefix = "refs/heads/" ;
612618 struct remote * remote ;
613619 int err = 0 ;
614620
@@ -807,12 +813,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
807813 guess_remote_head (remote_head , mapped_refs , 0 );
808814
809815 if (option_branch ) {
810- struct strbuf head = STRBUF_INIT ;
811- strbuf_addstr (& head , src_ref_prefix );
812- strbuf_addstr (& head , option_branch );
813816 our_head_points_at =
814- find_ref_by_name (mapped_refs , head .buf );
815- strbuf_release (& head );
817+ find_remote_branch (mapped_refs , option_branch );
816818
817819 if (!our_head_points_at ) {
818820 warning (_ ("Remote branch %s not found in "
0 commit comments