convert: git cherry-pick -Xrenormalize did not work

Working with a repo that used to be all CRLF. At some point it was changed to all LF, with `text=auto` in .gitattributes. Trying to cherry-pick a commit from before the switchover fails: $ git cherry-pick -Xrenormalize <commit> fatal: CRLF would be replaced by LF in [path] Commit 65237284 "unify the "auto" handling of CRLF" introduced a regression: Whenever crlf_action is CRLF_TEXT_XXX and not CRLF_AUTO_XXX, SAFE_CRLF_RENORMALIZE was feed into check_safe_crlf(). This is wrong because here everything else than SAFE_CRLF_WARN is treated as SAFE_CRLF_FAIL. Call check_safe_crlf() only if checksafe is SAFE_CRLF_WARN or SAFE_CRLF_FAIL. Reported-by: Eevee (Lexy Munroe) <eevee@veekun.com> Signed-off-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Torsten Bögershausen committed Nov 30, 2016 at 18:02 UTC 1c25d2d8ed4c5154c9059918e20e75cda3bede81
1 file changed +7 -6
convert.c
+7 -6
@@ -274,15 +274,16 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
274 if (convert_is_binary(len, &stats))
275 return 0;
276 /*
277 - * If the file in the index has any CR in it, do not convert.
278 - * This is the new safer autocrlf handling.
277 + * If the file in the index has any CR in it, do not
278 + * convert. This is the new safer autocrlf handling,
279 + * unless we want to renormalize in a merge or
280 + * cherry-pick.
281 */
280 - if (checksafe == SAFE_CRLF_RENORMALIZE)
281 - checksafe = SAFE_CRLF_FALSE;
282 - else if (has_cr_in_index(path))
282 + if ((checksafe != SAFE_CRLF_RENORMALIZE) && has_cr_in_index(path))
283 convert_crlf_into_lf = 0;
284 }
285 - if (checksafe && len) {
285 + if ((checksafe == SAFE_CRLF_WARN ||
286 + (checksafe == SAFE_CRLF_FAIL)) && len) {
287 struct text_stat new_stats;
288 memcpy(&new_stats, &stats, sizeof(new_stats));
289 /* simulate "git add" */