Skip to content

Commit 2e2b887

Browse files
committed
unpack_trees(): allow callers to differentiate worktree errors from merge errors
Instead of uniformly returning -1 on any error, this teaches unpack_trees() to return -2 when the merge itself is Ok but worktree refuses to get updated. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 6286a08 commit 2e2b887

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

unpack-trees.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,13 @@ static int unpack_failed(struct unpack_trees_options *o, const char *message)
358358
return -1;
359359
}
360360

361+
/*
362+
* N-way merge "len" trees. Returns 0 on success, -1 on failure to manipulate the
363+
* resulting index, -2 on failure to reflect the changes to the work tree.
364+
*/
361365
int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options *o)
362366
{
367+
int ret;
363368
static struct cache_entry *dfc;
364369

365370
if (len > MAX_UNPACK_TREES)
@@ -404,11 +409,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
404409
return unpack_failed(o, "Merge requires file-level merging");
405410

406411
o->src_index = NULL;
407-
if (check_updates(o))
408-
return -1;
412+
ret = check_updates(o) ? (-2) : 0;
409413
if (o->dst_index)
410414
*o->dst_index = o->result;
411-
return 0;
415+
return ret;
412416
}
413417

414418
/* Here come the merge functions */

0 commit comments

Comments
 (0)