1#!/bin/sh
   2test_description='Test git notes prune'
   4. ./test-lib.sh
   6test_expect_success 'setup: create a few commits with notes' '
   8        : > file1 &&
  10        git add file1 &&
  11        test_tick &&
  12        git commit -m 1st &&
  13        git notes add -m "Note #1" &&
  14        : > file2 &&
  15        git add file2 &&
  16        test_tick &&
  17        git commit -m 2nd &&
  18        git notes add -m "Note #2" &&
  19        : > file3 &&
  20        git add file3 &&
  21        test_tick &&
  22        git commit -m 3rd &&
  23        COMMIT_FILE=.git/objects/5e/e1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
  24        test -f $COMMIT_FILE &&
  25        test-chmtime =+0 $COMMIT_FILE &&
  26        git notes add -m "Note #3"
  27'
  28cat > expect <<END_OF_LOG
  30commit 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29
  31Author: A U Thor <author@example.com>
  32Date:   Thu Apr 7 15:15:13 2005 -0700
  33    3rd
  35Notes:
  37    Note #3
  38commit 08341ad9e94faa089d60fd3f523affb25c6da189
  40Author: A U Thor <author@example.com>
  41Date:   Thu Apr 7 15:14:13 2005 -0700
  42    2nd
  44Notes:
  46    Note #2
  47commit ab5f302035f2e7aaf04265f08b42034c23256e1f
  49Author: A U Thor <author@example.com>
  50Date:   Thu Apr 7 15:13:13 2005 -0700
  51    1st
  53Notes:
  55    Note #1
  56END_OF_LOG
  57test_expect_success 'verify commits and notes' '
  59        git log > actual &&
  61        test_cmp expect actual
  62'
  63test_expect_success 'remove some commits' '
  65        git reset --hard HEAD~1 &&
  67        git reflog expire --expire=now HEAD &&
  68        git gc --prune=now
  69'
  70test_expect_success 'verify that commits are gone' '
  72        test_must_fail git cat-file -p 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
  74        git cat-file -p 08341ad9e94faa089d60fd3f523affb25c6da189 &&
  75        git cat-file -p ab5f302035f2e7aaf04265f08b42034c23256e1f
  76'
  77test_expect_success 'verify that notes are still present' '
  79        git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
  81        git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
  82        git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
  83'
  84test_expect_success 'prune -n does not remove notes' '
  86        git notes list > expect &&
  88        git notes prune -n &&
  89        git notes list > actual &&
  90        test_cmp expect actual
  91'
  92cat > expect <<EOF
  945ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29
  95EOF
  96test_expect_success 'prune -n lists prunable notes' '
  98        git notes prune -n > actual &&
 101        test_cmp expect actual
 102'
 103test_expect_success 'prune notes' '
 106        git notes prune
 108'
 109test_expect_success 'verify that notes are gone' '
 111        test_must_fail git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
 113        git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
 114        git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
 115'
 116test_expect_success 'remove some commits' '
 118        git reset --hard HEAD~1 &&
 120        git reflog expire --expire=now HEAD &&
 121        git gc --prune=now
 122'
 123cat > expect <<EOF
 12508341ad9e94faa089d60fd3f523affb25c6da189
 126EOF
 127test_expect_success 'prune -v notes' '
 129        git notes prune -v > actual &&
 131        test_cmp expect actual
 132'
 133test_expect_success 'verify that notes are gone' '
 135        test_must_fail git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
 137        test_must_fail git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
 138        git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
 139'
 140test_done