notes remove: allow removing more than one

While "xargs -n1 git notes rm" is certainly a possible way to remove notes
from many objects, this would create one notes "commit" per removal, which
is not quite suitable for seasonal housekeeping.

Allow taking more than one on the command line, and record their removal
as a single atomic event if everthing goes well.

Even though the old code insisted that "git notes rm" must be given only
one object (or zero, in which case it would default to HEAD), this
condition was not tested. Add tests to handle the new case where we feed
multiple objects, and also make sure if there is a bad input, no change
is recorded.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano
2011-05-18 15:44:37 -07:00
parent b602ed7dea
commit c3ab1a8e4c
3 changed files with 49 additions and 25 deletions

View File

@ -435,6 +435,26 @@ test_expect_success 'removing non-existing note should not create new commit' '
test_cmp before_commit after_commit
'
test_expect_success 'removing more than one' '
before=$(git rev-parse --verify refs/notes/commits) &&
test_when_finished "git update-ref refs/notes/commits $before" &&
# We have only two -- add another and make sure it stays
git notes add -m "extra" &&
git notes list HEAD >after-removal-expect &&
git notes remove HEAD^^ HEAD^^^ &&
git notes list | sed -e "s/ .*//" >actual &&
test_cmp after-removal-expect actual
'
test_expect_success 'removing is atomic' '
before=$(git rev-parse --verify refs/notes/commits) &&
test_when_finished "git update-ref refs/notes/commits $before" &&
test_must_fail git notes remove HEAD^^ HEAD^^^ HEAD^ &&
after=$(git rev-parse --verify refs/notes/commits) &&
test "$before" = "$after"
'
test_expect_success 'list notes with "git notes list"' '
git notes list > output &&
test_cmp expect output