t / t3306-notes-prune.shon commit Merge branch 'nd/pretty-commit-log-message' (c17f1a9)
   1#!/bin/sh
   2
   3test_description='Test git notes prune'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'setup: create a few commits with notes' '
   8
   9        : > 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'
  28
  29cat > expect <<END_OF_LOG
  30commit 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29
  31Author: A U Thor <author@example.com>
  32Date:   Thu Apr 7 15:15:13 2005 -0700
  33
  34    3rd
  35
  36Notes:
  37    Note #3
  38
  39commit 08341ad9e94faa089d60fd3f523affb25c6da189
  40Author: A U Thor <author@example.com>
  41Date:   Thu Apr 7 15:14:13 2005 -0700
  42
  43    2nd
  44
  45Notes:
  46    Note #2
  47
  48commit ab5f302035f2e7aaf04265f08b42034c23256e1f
  49Author: A U Thor <author@example.com>
  50Date:   Thu Apr 7 15:13:13 2005 -0700
  51
  52    1st
  53
  54Notes:
  55    Note #1
  56END_OF_LOG
  57
  58test_expect_success 'verify commits and notes' '
  59
  60        git log > actual &&
  61        test_cmp expect actual
  62'
  63
  64test_expect_success 'remove some commits' '
  65
  66        git reset --hard HEAD~1 &&
  67        git reflog expire --expire=now HEAD &&
  68        git gc --prune=now
  69'
  70
  71test_expect_success 'verify that commits are gone' '
  72
  73        test_must_fail git cat-file -p 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
  74        git cat-file -p 08341ad9e94faa089d60fd3f523affb25c6da189 &&
  75        git cat-file -p ab5f302035f2e7aaf04265f08b42034c23256e1f
  76'
  77
  78test_expect_success 'verify that notes are still present' '
  79
  80        git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
  81        git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
  82        git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
  83'
  84
  85test_expect_success 'prune -n does not remove notes' '
  86
  87        git notes list > expect &&
  88        git notes prune -n &&
  89        git notes list > actual &&
  90        test_cmp expect actual
  91'
  92
  93cat > expect <<EOF
  945ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29
  95EOF
  96
  97test_expect_success 'prune -n lists prunable notes' '
  98
  99
 100        git notes prune -n > actual &&
 101        test_cmp expect actual
 102'
 103
 104
 105test_expect_success 'prune notes' '
 106
 107        git notes prune
 108'
 109
 110test_expect_success 'verify that notes are gone' '
 111
 112        test_must_fail git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
 113        git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
 114        git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
 115'
 116
 117test_expect_success 'remove some commits' '
 118
 119        git reset --hard HEAD~1 &&
 120        git reflog expire --expire=now HEAD &&
 121        git gc --prune=now
 122'
 123
 124cat > expect <<EOF
 12508341ad9e94faa089d60fd3f523affb25c6da189
 126EOF
 127
 128test_expect_success 'prune -v notes' '
 129
 130        git notes prune -v > actual &&
 131        test_cmp expect actual
 132'
 133
 134test_expect_success 'verify that notes are gone' '
 135
 136        test_must_fail git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
 137        test_must_fail git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
 138        git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
 139'
 140
 141test_done