Skip to content

Commit c54dacb

Browse files
prertikgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1ed9c14 commit c54dacb

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

builtin/rebase.c

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ struct rebase_options {
8787
REBASE_VERBOSE = 1<<1,
8888
REBASE_DIFFSTAT = 1<<2,
8989
REBASE_FORCE = 1<<3,
90+
REBASE_INTERACTIVE_EXPLICIT = 1<<4,
9091
} flags;
9192
struct strbuf git_am_opt;
9293
};
@@ -392,10 +393,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
392393
.git_am_opt = STRBUF_INIT,
393394
};
394395
const char *branch_name;
395-
int ret, flags;
396+
int ret, flags, in_progress = 0;
396397
int ok_to_skip_pre_rebase = 0;
397398
struct strbuf msg = STRBUF_INIT;
398399
struct strbuf revisions = STRBUF_INIT;
400+
struct strbuf buf = STRBUF_INIT;
399401
struct object_id merge_base;
400402
struct option builtin_rebase_options[] = {
401403
OPT_STRING(0, "onto", &options.onto_name,
@@ -447,6 +449,30 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
447449

448450
git_config(rebase_config, &options);
449451

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+
450476
argc = parse_options(argc, argv, prefix,
451477
builtin_rebase_options,
452478
builtin_rebase_usage, 0);
@@ -455,6 +481,26 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
455481
usage_with_options(builtin_rebase_usage,
456482
builtin_rebase_options);
457483

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+
458504
if (!(options.flags & REBASE_NO_QUIET))
459505
strbuf_addstr(&options.git_am_opt, " -q");
460506

0 commit comments

Comments
 (0)