Skip to content

Commit

Permalink
unpack-trees: propagate errors adding entries to the index
Browse files Browse the repository at this point in the history
When unpack_trees tries to write an entry to the index,
add_index_entry may report an error to stderr, but we ignore
its return value. This leads to us returning a successful
exit code for an operation that partially failed. Let's make
sure to propagate this code.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Dec 17, 2014
1 parent d2446df commit 4616918
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions unpack-trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
opts->unpack_rejects[i].strdup_strings = 1;
}

static void do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
static int do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
unsigned int set, unsigned int clear)
{
clear |= CE_HASHED | CE_UNHASHED;
Expand All @@ -112,8 +112,8 @@ static void do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce,

ce->next = NULL;
ce->ce_flags = (ce->ce_flags & ~clear) | set;
add_index_entry(&o->result, ce,
ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
return add_index_entry(&o->result, ce,
ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
}

static struct cache_entry *dup_entry(const struct cache_entry *ce)
Expand Down Expand Up @@ -608,7 +608,9 @@ static int unpack_nondirectories(int n, unsigned long mask,

for (i = 0; i < n; i++)
if (src[i] && src[i] != o->df_conflict_entry)
do_add_entry(o, src[i], 0, 0);
if (do_add_entry(o, src[i], 0, 0))
return -1;

return 0;
}

Expand Down

0 comments on commit 4616918

Please sign in to comment.