builtin-tag.c: Fix two memory leaks and minor notation changes.

A repeated call to read_sha1_file was not freing memory
when the buffer was allocated but returned size was zero.

Also, now the program does not allow many -F or -m options,
which was a bug too because it was not freing the memory
allocated for any previous -F or -m options.

Tests are provided for ensuring that only one option
-F or -m is given. Also, another test is shipped here,
to check that "git tag" fails when a non-existing file
is passed to the -F option, something that git-tag.sh
allowed creating the tag with an empty message.

Signed-off-by: Carlos Rica <jasampler@gmail.com>
Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Carlos Rica
2007-07-21 14:13:12 +02:00
committed by Junio C Hamano
parent 4d87b9c5db
commit e317cfafd2
2 changed files with 57 additions and 16 deletions

View File

@ -332,6 +332,33 @@ test_expect_success 'creating an annotated tag with -F - should succeed' '
git diff expect actual
'
test_expect_success \
'trying to create a tag with a non-existing -F file should fail' '
! test -f nonexistingfile &&
! tag_exists notag &&
! git-tag -F nonexistingfile notag &&
! tag_exists notag
'
test_expect_success \
'trying to create tags giving many -m or -F options should fail' '
echo "message file 1" >msgfile1 &&
echo "message file 2" >msgfile2 &&
! tag_exists msgtag &&
! git-tag -m "message 1" -m "message 2" msgtag &&
! tag_exists msgtag &&
! git-tag -F msgfile1 -F msgfile2 msgtag &&
! tag_exists msgtag &&
! git-tag -m "message 1" -F msgfile1 msgtag &&
! tag_exists msgtag &&
! git-tag -F msgfile1 -m "message 1" msgtag &&
! tag_exists msgtag &&
! git-tag -F msgfile1 -m "message 1" -F msgfile2 msgtag &&
! tag_exists msgtag &&
! git-tag -m "message 1" -F msgfile1 -m "message 2" msgtag &&
! tag_exists msgtag
'
# blank and empty messages:
get_tag_header empty-annotated-tag $commit commit $time >expect
@ -648,6 +675,14 @@ test_expect_success 'creating a signed tag with -F - should succeed' '
git diff expect actual
'
test_expect_success \
'trying to create a signed tag with non-existing -F file should fail' '
! test -f nonexistingfile &&
! tag_exists nosigtag &&
! git-tag -s -F nonexistingfile nosigtag &&
! tag_exists nosigtag
'
test_expect_success 'verifying a signed tag should succeed' \
'git-tag -v signed-tag'