Skip to content

Commit e0333e5

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

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

builtin/rebase.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "parse-options.h"
2020
#include "commit.h"
2121
#include "diff.h"
22+
#include "wt-status.h"
2223

2324
static char const * const builtin_rebase_usage[] = {
2425
N_("git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] "
@@ -479,6 +480,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
479480
die(_("Could not resolve HEAD to a revision"));
480481
}
481482

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+
482492
/* If a hook exists, give it a chance to interrupt*/
483493
if (!ok_to_skip_pre_rebase &&
484494
run_hook_le(NULL, "pre-rebase", options.upstream_arg,
@@ -528,6 +538,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
528538

529539
ret = !!run_specific_rebase(&options);
530540

541+
cleanup:
531542
strbuf_release(&revisions);
532543
free(options.head_name);
533544
return ret;

0 commit comments

Comments
 (0)