2010-02-13 21:28:28 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='Test git notes prune'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success 'setup: create a few commits with notes' '
|
|
|
|
|
|
|
|
: > file1 &&
|
|
|
|
git add file1 &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m 1st &&
|
2010-02-13 21:28:34 +00:00
|
|
|
git notes add -m "Note #1" &&
|
2019-08-18 19:16:37 +00:00
|
|
|
first=$(git rev-parse HEAD) &&
|
2010-02-13 21:28:28 +00:00
|
|
|
: > file2 &&
|
|
|
|
git add file2 &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m 2nd &&
|
2010-02-13 21:28:34 +00:00
|
|
|
git notes add -m "Note #2" &&
|
2019-08-18 19:16:37 +00:00
|
|
|
second=$(git rev-parse HEAD) &&
|
2010-02-13 21:28:28 +00:00
|
|
|
: > file3 &&
|
|
|
|
git add file3 &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m 3rd &&
|
2019-08-18 19:16:37 +00:00
|
|
|
third=$(git rev-parse HEAD) &&
|
|
|
|
COMMIT_FILE=$(echo $third | sed "s!^..!.git/objects/&/!") &&
|
2011-04-14 17:38:13 +00:00
|
|
|
test -f $COMMIT_FILE &&
|
2018-03-24 07:44:31 +00:00
|
|
|
test-tool chmtime =+0 $COMMIT_FILE &&
|
2010-02-13 21:28:34 +00:00
|
|
|
git notes add -m "Note #3"
|
2010-02-13 21:28:28 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
cat > expect <<END_OF_LOG
|
2019-08-18 19:16:37 +00:00
|
|
|
commit $third
|
2010-02-13 21:28:28 +00:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:15:13 2005 -0700
|
|
|
|
|
|
|
|
3rd
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
Note #3
|
|
|
|
|
2019-08-18 19:16:37 +00:00
|
|
|
commit $second
|
2010-02-13 21:28:28 +00:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:14:13 2005 -0700
|
|
|
|
|
|
|
|
2nd
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
Note #2
|
|
|
|
|
2019-08-18 19:16:37 +00:00
|
|
|
commit $first
|
2010-02-13 21:28:28 +00:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:13:13 2005 -0700
|
|
|
|
|
|
|
|
1st
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
Note #1
|
|
|
|
END_OF_LOG
|
|
|
|
|
|
|
|
test_expect_success 'verify commits and notes' '
|
|
|
|
|
|
|
|
git log > actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'remove some commits' '
|
|
|
|
|
2010-05-14 21:42:07 +00:00
|
|
|
git reset --hard HEAD~1 &&
|
2010-02-13 21:28:28 +00:00
|
|
|
git reflog expire --expire=now HEAD &&
|
|
|
|
git gc --prune=now
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'verify that commits are gone' '
|
|
|
|
|
2019-08-18 19:16:37 +00:00
|
|
|
test_must_fail git cat-file -p $third &&
|
|
|
|
git cat-file -p $second &&
|
|
|
|
git cat-file -p $first
|
2010-02-13 21:28:28 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'verify that notes are still present' '
|
|
|
|
|
2019-08-18 19:16:37 +00:00
|
|
|
git notes show $third &&
|
|
|
|
git notes show $second &&
|
|
|
|
git notes show $first
|
2010-02-13 21:28:28 +00:00
|
|
|
'
|
|
|
|
|
2010-05-14 21:42:07 +00:00
|
|
|
test_expect_success 'prune -n does not remove notes' '
|
|
|
|
|
|
|
|
git notes list > expect &&
|
|
|
|
git notes prune -n &&
|
|
|
|
git notes list > actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
|
|
|
|
test_expect_success 'prune -n lists prunable notes' '
|
|
|
|
|
2019-08-18 19:16:37 +00:00
|
|
|
echo $third >expect &&
|
2010-05-14 21:42:07 +00:00
|
|
|
git notes prune -n > actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
|
2010-02-13 21:28:28 +00:00
|
|
|
test_expect_success 'prune notes' '
|
|
|
|
|
|
|
|
git notes prune
|
|
|
|
'
|
|
|
|
|
2010-05-14 21:42:07 +00:00
|
|
|
test_expect_success 'verify that notes are gone' '
|
|
|
|
|
2019-08-18 19:16:37 +00:00
|
|
|
test_must_fail git notes show $third &&
|
|
|
|
git notes show $second &&
|
|
|
|
git notes show $first
|
2010-05-14 21:42:07 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'remove some commits' '
|
|
|
|
|
|
|
|
git reset --hard HEAD~1 &&
|
|
|
|
git reflog expire --expire=now HEAD &&
|
|
|
|
git gc --prune=now
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prune -v notes' '
|
|
|
|
|
2019-08-18 19:16:37 +00:00
|
|
|
echo $second >expect &&
|
2010-05-14 21:42:07 +00:00
|
|
|
git notes prune -v > actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2010-02-13 21:28:28 +00:00
|
|
|
test_expect_success 'verify that notes are gone' '
|
|
|
|
|
2019-08-18 19:16:37 +00:00
|
|
|
test_must_fail git notes show $third &&
|
|
|
|
test_must_fail git notes show $second &&
|
|
|
|
git notes show $first
|
2010-02-13 21:28:28 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_done
|