@@ -48,7 +48,6 @@ static int option_verbosity;
48
48
static int option_progress ;
49
49
static struct string_list option_config ;
50
50
static struct string_list option_reference ;
51
- static const char * src_ref_prefix = "refs/heads/" ;
52
51
53
52
static int opt_parse_reference (const struct option * opt , const char * arg , int unset )
54
53
{
@@ -413,6 +412,17 @@ static void remove_junk_on_signal(int signo)
413
412
raise (signo );
414
413
}
415
414
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
+
416
426
static struct ref * wanted_peer_refs (const struct ref * refs ,
417
427
struct refspec * refspec )
418
428
{
@@ -425,13 +435,8 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
425
435
426
436
if (!option_branch )
427
437
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 );
435
440
436
441
if (!remote_head && option_branch )
437
442
warning (_ ("Could not find remote branch %s to clone." ),
@@ -502,7 +507,7 @@ static void update_remote_refs(const struct ref *refs,
502
507
static void update_head (const struct ref * our , const struct ref * remote ,
503
508
const char * msg )
504
509
{
505
- if (our ) {
510
+ if (our && ! prefixcmp ( our -> name , "refs/heads/" ) ) {
506
511
/* Local default branch link */
507
512
create_symref ("HEAD" , our -> name , NULL );
508
513
if (!option_bare ) {
@@ -609,6 +614,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
609
614
struct strbuf key = STRBUF_INIT , value = STRBUF_INIT ;
610
615
struct strbuf branch_top = STRBUF_INIT , reflog_msg = STRBUF_INIT ;
611
616
struct transport * transport = NULL ;
617
+ const char * src_ref_prefix = "refs/heads/" ;
612
618
struct remote * remote ;
613
619
int err = 0 ;
614
620
@@ -807,12 +813,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
807
813
guess_remote_head (remote_head , mapped_refs , 0 );
808
814
809
815
if (option_branch ) {
810
- struct strbuf head = STRBUF_INIT ;
811
- strbuf_addstr (& head , src_ref_prefix );
812
- strbuf_addstr (& head , option_branch );
813
816
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 );
816
818
817
819
if (!our_head_points_at ) {
818
820
warning (_ ("Remote branch %s not found in "
0 commit comments