Skip to content

Commit f36538d

Browse files
chriscoolgitster
authored andcommitted
builtin/apply: make check_apply_state() return -1 instead of die()ing
To libify `git apply` functionality we have to signal errors to the caller instead of die()ing. To do that in a compatible manner with the rest of the error handling in "builtin/apply.c", check_apply_state() should return -1 instead of calling die(). Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2f5a6d1 commit f36538d

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

builtin/apply.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4551,34 +4551,36 @@ static int option_parse_directory(const struct option *opt,
45514551
return 0;
45524552
}
45534553

4554-
static void check_apply_state(struct apply_state *state, int force_apply)
4554+
static int check_apply_state(struct apply_state *state, int force_apply)
45554555
{
45564556
int is_not_gitdir = !startup_info->have_repository;
45574557

45584558
if (state->apply_with_reject && state->threeway)
4559-
die("--reject and --3way cannot be used together.");
4559+
return error("--reject and --3way cannot be used together.");
45604560
if (state->cached && state->threeway)
4561-
die("--cached and --3way cannot be used together.");
4561+
return error("--cached and --3way cannot be used together.");
45624562
if (state->threeway) {
45634563
if (is_not_gitdir)
4564-
die(_("--3way outside a repository"));
4564+
return error(_("--3way outside a repository"));
45654565
state->check_index = 1;
45664566
}
45674567
if (state->apply_with_reject)
45684568
state->apply = state->apply_verbosely = 1;
45694569
if (!force_apply && (state->diffstat || state->numstat || state->summary || state->check || state->fake_ancestor))
45704570
state->apply = 0;
45714571
if (state->check_index && is_not_gitdir)
4572-
die(_("--index outside a repository"));
4572+
return error(_("--index outside a repository"));
45734573
if (state->cached) {
45744574
if (is_not_gitdir)
4575-
die(_("--cached outside a repository"));
4575+
return error(_("--cached outside a repository"));
45764576
state->check_index = 1;
45774577
}
45784578
if (state->check_index)
45794579
state->unsafe_paths = 0;
45804580
if (!state->lock_file)
4581-
die("BUG: state->lock_file should not be NULL");
4581+
return error("BUG: state->lock_file should not be NULL");
4582+
4583+
return 0;
45824584
}
45834585

45844586
static int apply_all_patches(struct apply_state *state,
@@ -4747,7 +4749,8 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
47474749
argc = parse_options(argc, argv, state.prefix, builtin_apply_options,
47484750
apply_usage, 0);
47494751

4750-
check_apply_state(&state, force_apply);
4752+
if (check_apply_state(&state, force_apply))
4753+
exit(128);
47514754

47524755
ret = apply_all_patches(&state, argc, argv, options);
47534756

0 commit comments

Comments
 (0)