Skip to content

Commit 6e8df31

Browse files
chriscoolgitster
authored andcommitted
builtin/apply: make remove_file() return -1 on error
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", remove_file() should return -1 instead of calling die(). Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe41b80 commit 6e8df31

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

builtin/apply.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4085,17 +4085,18 @@ static void patch_stats(struct apply_state *state, struct patch *patch)
40854085
}
40864086
}
40874087

4088-
static void remove_file(struct apply_state *state, struct patch *patch, int rmdir_empty)
4088+
static int remove_file(struct apply_state *state, struct patch *patch, int rmdir_empty)
40894089
{
40904090
if (state->update_index) {
40914091
if (remove_file_from_cache(patch->old_name) < 0)
4092-
die(_("unable to remove %s from index"), patch->old_name);
4092+
return error(_("unable to remove %s from index"), patch->old_name);
40934093
}
40944094
if (!state->cached) {
40954095
if (!remove_or_warn(patch->old_mode, patch->old_name) && rmdir_empty) {
40964096
remove_path(patch->old_name);
40974097
}
40984098
}
4099+
return 0;
40994100
}
41004101

41014102
static void add_index_file(struct apply_state *state,
@@ -4274,8 +4275,10 @@ static void write_out_one_result(struct apply_state *state,
42744275
int phase)
42754276
{
42764277
if (patch->is_delete > 0) {
4277-
if (phase == 0)
4278-
remove_file(state, patch, 1);
4278+
if (phase == 0) {
4279+
if (remove_file(state, patch, 1))
4280+
exit(128);
4281+
}
42794282
return;
42804283
}
42814284
if (patch->is_new > 0 || patch->is_copy) {
@@ -4287,8 +4290,10 @@ static void write_out_one_result(struct apply_state *state,
42874290
* Rename or modification boils down to the same
42884291
* thing: remove the old, write the new
42894292
*/
4290-
if (phase == 0)
4291-
remove_file(state, patch, patch->is_rename);
4293+
if (phase == 0) {
4294+
if (remove_file(state, patch, patch->is_rename))
4295+
exit(128);
4296+
}
42924297
if (phase == 1)
42934298
create_file(state, patch);
42944299
}

0 commit comments

Comments
 (0)