builtin rebase: require a clean worktree
This commit reads the index of the repository for rebase and checks whether the repository is ready for rebase. 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
e0333e5c63f347c5032fde05bddf711061e55e59
1 file changed
+11
builtin/rebase.c
+11
@@ -19,6 +19,7 @@
19
#include "parse-options.h"
20
#include "commit.h"
21
#include "diff.h"
22
+#include "wt-status.h"
23
24
static char const * const builtin_rebase_usage[] = {
25
N_("git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] "
@@ -479,6 +480,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
480
die(_("Could not resolve HEAD to a revision"));
481
}
482
483
+ if (read_index(the_repository->index) < 0)
484
+ die(_("could not read index"));
485
+
486
+ if (require_clean_work_tree("rebase",
487
+ _("Please commit or stash them."), 1, 1)) {
488
+ ret = 1;
489
+ goto cleanup;
490
+ }
491
+
492
/* If a hook exists, give it a chance to interrupt*/
493
if (!ok_to_skip_pre_rebase &&
494
run_hook_le(NULL, "pre-rebase", options.upstream_arg,
@@ -528,6 +538,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
538
539
ret = !!run_specific_rebase(&options);
540
541
+cleanup:
542
strbuf_release(&revisions);
543
free(options.head_name);
544
return ret;