Skip to content

Commit e276c26

Browse files
committed
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 <[email protected]>
1 parent c35539e commit e276c26

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

builtin-for-each-ref.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,10 @@ static void find_subpos(const char *buf, unsigned long sz, const char **sub, con
459459
return;
460460
*sub = buf; /* first non-empty line */
461461
buf = strchr(buf, '\n');
462-
if (!buf)
462+
if (!buf) {
463+
*body = "";
463464
return; /* no body */
465+
}
464466
while (*buf == '\n')
465467
buf++; /* skip blank between subject and body */
466468
*body = buf;

t/t6300-for-each-ref.sh

+10
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,14 @@ for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
262262
"
263263
done
264264

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+
265275
test_done

0 commit comments

Comments
 (0)