From: Junio C Hamano Date: Wed, 20 Aug 2008 19:29:27 +0000 (-0700) Subject: for-each-ref: cope with tags with incomplete lines X-Git-Tag: v1.6.0.1~20 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e276c26b4b65711c27e3ef37e732d41eeae42094;p=git.git 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 --- diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c index 445039e19..4d25ec51d 100644 --- a/builtin-for-each-ref.c +++ b/builtin-for-each-ref.c @@ -459,8 +459,10 @@ static void find_subpos(const char *buf, unsigned long sz, const char **sub, con return; *sub = buf; /* first non-empty line */ buf = strchr(buf, '\n'); - if (!buf) + if (!buf) { + *body = ""; return; /* no body */ + } while (*buf == '\n') buf++; /* skip blank between subject and body */ *body = buf; diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index a3c8941c7..8ced59321 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -262,4 +262,14 @@ for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do " done +test_expect_success 'an unusual tag with an incomplete line' ' + + git tag -m "bogo" bogo && + bogo=$(git cat-file tag bogo) && + bogo=$(printf "%s" "$bogo" | git mktag) && + git tag -f bogo "$bogo" && + git for-each-ref --format "%(body)" refs/tags/bogo + +' + test_done