@@ -76,6 +76,7 @@ struct rebase_options {
76
76
const char * revisions ;
77
77
const char * switch_to ;
78
78
int root ;
79
+ struct object_id * squash_onto ;
79
80
struct commit * restrict_revision ;
80
81
int dont_finish_rebase ;
81
82
enum {
@@ -375,6 +376,9 @@ static int run_specific_rebase(struct rebase_options *opts)
375
376
opts -> rebase_cousins ? "t" : "" );
376
377
add_var (& script_snippet , "strategy" , opts -> strategy );
377
378
add_var (& script_snippet , "strategy_opts" , opts -> strategy_opts );
379
+ add_var (& script_snippet , "rebase_root" , opts -> root ? "t" : "" );
380
+ add_var (& script_snippet , "squash_onto" ,
381
+ opts -> squash_onto ? oid_to_hex (opts -> squash_onto ) : "" );
378
382
379
383
switch (opts -> type ) {
380
384
case REBASE_AM :
@@ -653,6 +657,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
653
657
const char * rebase_merges = NULL ;
654
658
int fork_point = -1 ;
655
659
struct string_list strategy_options = STRING_LIST_INIT_NODUP ;
660
+ struct object_id squash_onto ;
661
+ char * squash_onto_name = NULL ;
656
662
struct option builtin_rebase_options [] = {
657
663
OPT_STRING (0 , "onto" , & options .onto_name ,
658
664
N_ ("revision" ),
@@ -744,6 +750,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
744
750
N_ ("option" ),
745
751
N_ ("pass the argument through to the merge "
746
752
"strategy" )),
753
+ OPT_BOOL (0 , "root" , & options .root ,
754
+ N_ ("rebase all reachable commits up to the root(s)" )),
747
755
OPT_END (),
748
756
};
749
757
@@ -1021,6 +1029,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1021
1029
}
1022
1030
}
1023
1031
1032
+ if (options .root && !options .onto_name )
1033
+ imply_interactive (& options , "--root without --onto" );
1034
+
1024
1035
switch (options .type ) {
1025
1036
case REBASE_MERGE :
1026
1037
case REBASE_INTERACTIVE :
@@ -1059,8 +1070,22 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1059
1070
if (!options .upstream )
1060
1071
die (_ ("invalid upstream '%s'" ), options .upstream_name );
1061
1072
options .upstream_arg = options .upstream_name ;
1062
- } else
1063
- die ("TODO: upstream for --root" );
1073
+ } else {
1074
+ if (!options .onto_name ) {
1075
+ if (commit_tree ("" , 0 , the_hash_algo -> empty_tree , NULL ,
1076
+ & squash_onto , NULL , NULL ) < 0 )
1077
+ die (_ ("Could not create new root commit" ));
1078
+ options .squash_onto = & squash_onto ;
1079
+ options .onto_name = squash_onto_name =
1080
+ xstrdup (oid_to_hex (& squash_onto ));
1081
+ }
1082
+ options .upstream_name = NULL ;
1083
+ options .upstream = NULL ;
1084
+ if (argc > 1 )
1085
+ usage_with_options (builtin_rebase_usage ,
1086
+ builtin_rebase_options );
1087
+ options .upstream_arg = "--root" ;
1088
+ }
1064
1089
1065
1090
/* Make sure the branch to rebase onto is valid. */
1066
1091
if (!options .onto_name )
@@ -1208,6 +1233,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1208
1233
*/
1209
1234
if (can_fast_forward (options .onto , & options .orig_head , & merge_base ) &&
1210
1235
!is_interactive (& options ) && !options .restrict_revision &&
1236
+ options .upstream &&
1211
1237
!oidcmp (& options .upstream -> object .oid , & options .onto -> object .oid )) {
1212
1238
int flag ;
1213
1239
@@ -1312,5 +1338,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1312
1338
free (options .head_name );
1313
1339
free (options .gpg_sign_opt );
1314
1340
free (options .cmd );
1341
+ free (squash_onto_name );
1315
1342
return ret ;
1316
1343
}
0 commit comments