Skip to content

Commit 06e4775

Browse files
prertikgitster
authored andcommitted
builtin rebase: handle the pre-rebase hook and --no-verify
This commit converts the equivalent part of the shell script `git-legacy-rebase.sh` to run the pre-rebase hook (unless disabled), and to interrupt the rebase with error if the hook fails. Signed-off-by: Pratik Karki <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 075bc85 commit 06e4775

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
@@ -70,6 +70,7 @@ struct rebase_options {
7070
const char *state_dir;
7171
struct commit *upstream;
7272
const char *upstream_name;
73+
const char *upstream_arg;
7374
char *head_name;
7475
struct object_id orig_head;
7576
struct commit *onto;
@@ -310,13 +311,16 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
310311
};
311312
const char *branch_name;
312313
int ret, flags;
314+
int ok_to_skip_pre_rebase = 0;
313315
struct strbuf msg = STRBUF_INIT;
314316
struct strbuf revisions = STRBUF_INIT;
315317
struct object_id merge_base;
316318
struct option builtin_rebase_options[] = {
317319
OPT_STRING(0, "onto", &options.onto_name,
318320
N_("revision"),
319321
N_("rebase onto given branch instead of upstream")),
322+
OPT_BOOL(0, "no-verify", &ok_to_skip_pre_rebase,
323+
N_("allow pre-rebase hook to run")),
320324
OPT_END(),
321325
};
322326

@@ -382,6 +386,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
382386
options.upstream = peel_committish(options.upstream_name);
383387
if (!options.upstream)
384388
die(_("invalid upstream '%s'"), options.upstream_name);
389+
options.upstream_arg = options.upstream_name;
385390
} else
386391
die("TODO: upstream for --root");
387392

@@ -430,6 +435,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
430435
die(_("Could not resolve HEAD to a revision"));
431436
}
432437

438+
/* If a hook exists, give it a chance to interrupt*/
439+
if (!ok_to_skip_pre_rebase &&
440+
run_hook_le(NULL, "pre-rebase", options.upstream_arg,
441+
argc ? argv[0] : NULL, NULL))
442+
die(_("The pre-rebase hook refused to rebase."));
443+
433444
strbuf_addf(&msg, "rebase: checkout %s", options.onto_name);
434445
if (reset_head(&options.onto->object.oid, "checkout", NULL, 1))
435446
die(_("Could not detach HEAD"));

0 commit comments

Comments
 (0)