merge-recursive: handle NULL in add_cacheinfo() correctly

1335d76e45 ("merge: avoid "safer crlf" during recording of merge results", 2016-07-08) tried to split make_cache_entry() call made with CE_MATCH_REFRESH into a call to make_cache_entry() without one, followed by a call to add_cache_entry(), refresh_cache() and another add_cache_entry() as needed. However the conversion was botched in that it forgot that refresh_cache() can return NULL, which was handled correctly in make_cache_entry() but in the updated code. This fixes https://github.com/git-for-windows/git/issues/952 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Nov 26, 2016 at 13:48 UTC 55e9f0e5c9a918c246b7eae1fe2a2e954f6426af
2 files changed +3 -1
merge-recursive.c
+2
@@ -213,6 +213,8 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
213 struct cache_entry *nce;
214
215 nce = refresh_cache_entry(ce, CE_MATCH_REFRESH | CE_MATCH_IGNORE_MISSING);
216 + if (!nce)
217 + return error(_("addinfo_cache failed for path '%s'"), path);
218 if (nce != ce)
219 ret = add_cache_entry(nce, options);
220 }
t/t3501-revert-cherry-pick.sh
+1 -1
@@ -141,7 +141,7 @@ test_expect_success 'cherry-pick "-" works with arguments' '
141 test_cmp expect actual
142 '
143
144 -test_expect_failure 'cherry-pick works with dirty renamed file' '
144 +test_expect_success 'cherry-pick works with dirty renamed file' '
145 test_commit to-rename &&
146 git checkout -b unrelated &&
147 test_commit unrelated &&