builtin rebase: start a new rebase only if none is in progress
To run a new rebase, there needs to be a check to assure that no other rebase is in progress. New rebase operation cannot start until an ongoing rebase operation completes or is terminated. Signed-off-by: Pratik Karki <predatoramigo@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pratik Karki committed
Sep 4, 2018 at 14:27 UTC
c54dacb50ea6d99a1fd9ad0abd5e64dd9914295e
1 file changed
+47
-1
builtin/rebase.c
+47
-1
@@ -87,6 +87,7 @@ struct rebase_options {
87
REBASE_VERBOSE = 1<<1,
88
REBASE_DIFFSTAT = 1<<2,
89
REBASE_FORCE = 1<<3,
90
+ REBASE_INTERACTIVE_EXPLICIT = 1<<4,
91
} flags;
92
struct strbuf git_am_opt;
93
};
@@ -392,10 +393,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
393
.git_am_opt = STRBUF_INIT,
394
};
395
const char *branch_name;
395
- int ret, flags;
396
+ int ret, flags, in_progress = 0;
397
int ok_to_skip_pre_rebase = 0;
398
struct strbuf msg = STRBUF_INIT;
399
struct strbuf revisions = STRBUF_INIT;
400
+ struct strbuf buf = STRBUF_INIT;
401
struct object_id merge_base;
402
struct option builtin_rebase_options[] = {
403
OPT_STRING(0, "onto", &options.onto_name,
@@ -447,6 +449,30 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
449
450
git_config(rebase_config, &options);
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
+
476
argc = parse_options(argc, argv, prefix,
477
builtin_rebase_options,
478
builtin_rebase_usage, 0);
@@ -455,6 +481,26 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
481
usage_with_options(builtin_rebase_usage,
482
builtin_rebase_options);
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
+
504
if (!(options.flags & REBASE_NO_QUIET))
505
strbuf_addstr(&options.git_am_opt, " -q");
506