@@ -72,21 +72,6 @@ static char *get_default_remote(void)
72
72
return repo_get_default_remote (the_repository );
73
73
}
74
74
75
- static int print_default_remote (int argc , const char * * argv , const char * prefix )
76
- {
77
- char * remote ;
78
-
79
- if (argc != 1 )
80
- die (_ ("submodule--helper print-default-remote takes no arguments" ));
81
-
82
- remote = get_default_remote ();
83
- if (remote )
84
- printf ("%s\n" , remote );
85
-
86
- free (remote );
87
- return 0 ;
88
- }
89
-
90
75
static int starts_with_dot_slash (const char * str )
91
76
{
92
77
return str [0 ] == '.' && is_dir_sep (str [1 ]);
@@ -2027,6 +2012,7 @@ struct update_data {
2027
2012
unsigned int quiet ;
2028
2013
unsigned int nofetch ;
2029
2014
unsigned int just_cloned ;
2015
+ unsigned int remote ;
2030
2016
};
2031
2017
#define UPDATE_DATA_INIT { .update_strategy = SUBMODULE_UPDATE_STRATEGY_INIT }
2032
2018
@@ -2603,6 +2589,8 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
2603
2589
OPT_CALLBACK_F (0 , "oid" , & update_data .oid , N_ ("sha1" ),
2604
2590
N_ ("SHA1 expected by superproject" ), PARSE_OPT_NONEG ,
2605
2591
parse_opt_object_id ),
2592
+ OPT_BOOL (0 , "remote" , & update_data .remote ,
2593
+ N_ ("use SHA-1 of submodule's remote tracking branch" )),
2606
2594
OPT_END ()
2607
2595
};
2608
2596
@@ -2682,23 +2670,6 @@ static const char *remote_submodule_branch(const char *path)
2682
2670
return branch ;
2683
2671
}
2684
2672
2685
- static int resolve_remote_submodule_branch (int argc , const char * * argv ,
2686
- const char * prefix )
2687
- {
2688
- const char * ret ;
2689
- struct strbuf sb = STRBUF_INIT ;
2690
- if (argc != 2 )
2691
- die ("submodule--helper remote-branch takes exactly one arguments, got %d" , argc );
2692
-
2693
- ret = remote_submodule_branch (argv [1 ]);
2694
- if (!ret )
2695
- die ("submodule %s doesn't exist" , argv [1 ]);
2696
-
2697
- printf ("%s" , ret );
2698
- strbuf_release (& sb );
2699
- return 0 ;
2700
- }
2701
-
2702
2673
static int push_check (int argc , const char * * argv , const char * prefix )
2703
2674
{
2704
2675
struct remote * remote ;
@@ -3040,6 +3011,25 @@ static int update_submodule2(struct update_data *update_data)
3040
3011
die (_ ("Unable to find current revision in submodule path '%s'" ),
3041
3012
update_data -> displaypath );
3042
3013
3014
+ if (update_data -> remote ) {
3015
+ char * remote_name = get_default_remote_submodule (update_data -> sm_path );
3016
+ const char * branch = remote_submodule_branch (update_data -> sm_path );
3017
+ char * remote_ref = xstrfmt ("refs/remotes/%s/%s" , remote_name , branch );
3018
+
3019
+ if (!update_data -> nofetch ) {
3020
+ if (fetch_in_submodule (update_data -> sm_path , update_data -> depth ,
3021
+ 0 , NULL ))
3022
+ die (_ ("Unable to fetch in submodule path '%s'" ),
3023
+ update_data -> sm_path );
3024
+ }
3025
+
3026
+ if (resolve_gitlink_ref (update_data -> sm_path , remote_ref , & update_data -> oid ))
3027
+ die (_ ("Unable to find %s revision in submodule path '%s'" ),
3028
+ remote_ref , update_data -> sm_path );
3029
+
3030
+ free (remote_ref );
3031
+ }
3032
+
3043
3033
if (!oideq (& update_data -> oid , & update_data -> suboid ) || update_data -> force )
3044
3034
return do_run_update_procedure (update_data );
3045
3035
@@ -3439,11 +3429,9 @@ static struct cmd_struct commands[] = {
3439
3429
{"foreach" , module_foreach , SUPPORT_SUPER_PREFIX },
3440
3430
{"init" , module_init , SUPPORT_SUPER_PREFIX },
3441
3431
{"status" , module_status , SUPPORT_SUPER_PREFIX },
3442
- {"print-default-remote" , print_default_remote , 0 },
3443
3432
{"sync" , module_sync , SUPPORT_SUPER_PREFIX },
3444
3433
{"deinit" , module_deinit , 0 },
3445
3434
{"summary" , module_summary , SUPPORT_SUPER_PREFIX },
3446
- {"remote-branch" , resolve_remote_submodule_branch , 0 },
3447
3435
{"push-check" , push_check , 0 },
3448
3436
{"absorb-git-dirs" , absorb_git_dirs , SUPPORT_SUPER_PREFIX },
3449
3437
{"is-active" , is_active , 0 },
0 commit comments