@@ -584,6 +584,26 @@ static int module_foreach(int argc, const char **argv, const char *prefix)
584
584
return 0 ;
585
585
}
586
586
587
+ static char * compute_submodule_clone_url (const char * rel_url )
588
+ {
589
+ char * remoteurl , * relurl ;
590
+ char * remote = get_default_remote ();
591
+ struct strbuf remotesb = STRBUF_INIT ;
592
+
593
+ strbuf_addf (& remotesb , "remote.%s.url" , remote );
594
+ if (git_config_get_string (remotesb .buf , & remoteurl )) {
595
+ warning (_ ("could not look up configuration '%s'. Assuming this repository is its own authoritative upstream." ), remotesb .buf );
596
+ remoteurl = xgetcwd ();
597
+ }
598
+ relurl = relative_url (remoteurl , rel_url , NULL );
599
+
600
+ free (remote );
601
+ free (remoteurl );
602
+ strbuf_release (& remotesb );
603
+
604
+ return relurl ;
605
+ }
606
+
587
607
struct init_cb {
588
608
const char * prefix ;
589
609
unsigned int flags ;
@@ -634,21 +654,9 @@ static void init_submodule(const char *path, const char *prefix,
634
654
/* Possibly a url relative to parent */
635
655
if (starts_with_dot_dot_slash (url ) ||
636
656
starts_with_dot_slash (url )) {
637
- char * remoteurl , * relurl ;
638
- char * remote = get_default_remote ();
639
- struct strbuf remotesb = STRBUF_INIT ;
640
- strbuf_addf (& remotesb , "remote.%s.url" , remote );
641
- free (remote );
642
-
643
- if (git_config_get_string (remotesb .buf , & remoteurl )) {
644
- warning (_ ("could not lookup configuration '%s'. Assuming this repository is its own authoritative upstream." ), remotesb .buf );
645
- remoteurl = xgetcwd ();
646
- }
647
- relurl = relative_url (remoteurl , url , NULL );
648
- strbuf_release (& remotesb );
649
- free (remoteurl );
650
- free (url );
651
- url = relurl ;
657
+ char * oldurl = url ;
658
+ url = compute_submodule_clone_url (oldurl );
659
+ free (oldurl );
652
660
}
653
661
654
662
if (git_config_set_gently (sb .buf , url ))
@@ -1582,6 +1590,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
1582
1590
struct strbuf sb = STRBUF_INIT ;
1583
1591
const char * displaypath = NULL ;
1584
1592
int needs_cloning = 0 ;
1593
+ int need_free_url = 0 ;
1585
1594
1586
1595
if (ce_stage (ce )) {
1587
1596
if (suc -> recursive_prefix )
@@ -1630,8 +1639,14 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
1630
1639
1631
1640
strbuf_reset (& sb );
1632
1641
strbuf_addf (& sb , "submodule.%s.url" , sub -> name );
1633
- if (repo_config_get_string_const (the_repository , sb .buf , & url ))
1634
- url = sub -> url ;
1642
+ if (repo_config_get_string_const (the_repository , sb .buf , & url )) {
1643
+ if (starts_with_dot_slash (sub -> url ) ||
1644
+ starts_with_dot_dot_slash (sub -> url )) {
1645
+ url = compute_submodule_clone_url (sub -> url );
1646
+ need_free_url = 1 ;
1647
+ } else
1648
+ url = sub -> url ;
1649
+ }
1635
1650
1636
1651
strbuf_reset (& sb );
1637
1652
strbuf_addf (& sb , "%s/.git" , ce -> name );
@@ -1677,6 +1692,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
1677
1692
cleanup :
1678
1693
strbuf_reset (& displaypath_sb );
1679
1694
strbuf_reset (& sb );
1695
+ if (need_free_url )
1696
+ free ((void * )url );
1680
1697
1681
1698
return needs_cloning ;
1682
1699
}
0 commit comments