@matheusbsbs / matheus-bagliano / commits / e276c26b4b
Fork 0

for-each-ref: cope with tags with incomplete lines

If you have a tag with a single, incomplete line as its payload, asking git-for-each-ref for its %(body) element accessed a NULL pointer. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 20, 2008 at 12:29 UTC e276c26b4b65711c27e3ef37e732d41eeae42094
2 files changed +13 -1
builtin-for-each-ref.c
+3 -1
@@ -459,8 +459,10 @@ static void find_subpos(const char *buf, unsigned long sz, const char **sub, con
459 return;
460 *sub = buf; /* first non-empty line */
461 buf = strchr(buf, '\n');
462 - if (!buf)
462 + if (!buf) {
463 + *body = "";
464 return; /* no body */
465 + }
466 while (*buf == '\n')
467 buf++; /* skip blank between subject and body */
468 *body = buf;
t/t6300-for-each-ref.sh
+10
@@ -262,4 +262,14 @@ for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
262 "
263 done
264
265 +test_expect_success 'an unusual tag with an incomplete line' '
266 +
267 + git tag -m "bogo" bogo &&
268 + bogo=$(git cat-file tag bogo) &&
269 + bogo=$(printf "%s" "$bogo" | git mktag) &&
270 + git tag -f bogo "$bogo" &&
271 + git for-each-ref --format "%(body)" refs/tags/bogo
272 +
273 +'
274 +
275 test_done