@@ -87,6 +87,7 @@ struct rebase_options {
87
87
REBASE_VERBOSE = 1 <<1 ,
88
88
REBASE_DIFFSTAT = 1 <<2 ,
89
89
REBASE_FORCE = 1 <<3 ,
90
+ REBASE_INTERACTIVE_EXPLICIT = 1 <<4 ,
90
91
} flags ;
91
92
struct strbuf git_am_opt ;
92
93
};
@@ -392,10 +393,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
392
393
.git_am_opt = STRBUF_INIT ,
393
394
};
394
395
const char * branch_name ;
395
- int ret , flags ;
396
+ int ret , flags , in_progress = 0 ;
396
397
int ok_to_skip_pre_rebase = 0 ;
397
398
struct strbuf msg = STRBUF_INIT ;
398
399
struct strbuf revisions = STRBUF_INIT ;
400
+ struct strbuf buf = STRBUF_INIT ;
399
401
struct object_id merge_base ;
400
402
struct option builtin_rebase_options [] = {
401
403
OPT_STRING (0 , "onto" , & options .onto_name ,
@@ -447,6 +449,30 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
447
449
448
450
git_config (rebase_config , & options );
449
451
452
+ if (is_directory (apply_dir ())) {
453
+ options .type = REBASE_AM ;
454
+ options .state_dir = apply_dir ();
455
+ } else if (is_directory (merge_dir ())) {
456
+ strbuf_reset (& buf );
457
+ strbuf_addf (& buf , "%s/rewritten" , merge_dir ());
458
+ if (is_directory (buf .buf )) {
459
+ options .type = REBASE_PRESERVE_MERGES ;
460
+ options .flags |= REBASE_INTERACTIVE_EXPLICIT ;
461
+ } else {
462
+ strbuf_reset (& buf );
463
+ strbuf_addf (& buf , "%s/interactive" , merge_dir ());
464
+ if (file_exists (buf .buf )) {
465
+ options .type = REBASE_INTERACTIVE ;
466
+ options .flags |= REBASE_INTERACTIVE_EXPLICIT ;
467
+ } else
468
+ options .type = REBASE_MERGE ;
469
+ }
470
+ options .state_dir = merge_dir ();
471
+ }
472
+
473
+ if (options .type != REBASE_UNSPECIFIED )
474
+ in_progress = 1 ;
475
+
450
476
argc = parse_options (argc , argv , prefix ,
451
477
builtin_rebase_options ,
452
478
builtin_rebase_usage , 0 );
@@ -455,6 +481,26 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
455
481
usage_with_options (builtin_rebase_usage ,
456
482
builtin_rebase_options );
457
483
484
+ /* Make sure no rebase is in progress */
485
+ if (in_progress ) {
486
+ const char * last_slash = strrchr (options .state_dir , '/' );
487
+ const char * state_dir_base =
488
+ last_slash ? last_slash + 1 : options .state_dir ;
489
+ const char * cmd_live_rebase =
490
+ "git rebase (--continue | --abort | --skip)" ;
491
+ strbuf_reset (& buf );
492
+ strbuf_addf (& buf , "rm -fr \"%s\"" , options .state_dir );
493
+ die (_ ("It seems that there is already a %s directory, and\n"
494
+ "I wonder if you are in the middle of another rebase. "
495
+ "If that is the\n"
496
+ "case, please try\n\t%s\n"
497
+ "If that is not the case, please\n\t%s\n"
498
+ "and run me again. I am stopping in case you still "
499
+ "have something\n"
500
+ "valuable there.\n" ),
501
+ state_dir_base , cmd_live_rebase , buf .buf );
502
+ }
503
+
458
504
if (!(options .flags & REBASE_NO_QUIET ))
459
505
strbuf_addstr (& options .git_am_opt , " -q" );
460
506
0 commit comments