t / t4200-rerere.shon commit fix importing of subversion tars (46f6178)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Johannes E. Schindelin
   4#
   5
   6test_description='git-rerere
   7'
   8
   9. ./test-lib.sh
  10
  11cat > a1 << EOF
  12Whether 'tis nobler in the mind to suffer
  13The slings and arrows of outrageous fortune,
  14Or to take arms against a sea of troubles,
  15And by opposing end them? To die: to sleep;
  16No more; and by a sleep to say we end
  17The heart-ache and the thousand natural shocks
  18That flesh is heir to, 'tis a consummation
  19Devoutly to be wish'd.
  20EOF
  21
  22git add a1
  23git commit -q -a -m initial
  24
  25git checkout -b first
  26cat >> a1 << EOF
  27To die, to sleep;
  28To sleep: perchance to dream: ay, there's the rub;
  29For in that sleep of death what dreams may come
  30When we have shuffled off this mortal coil,
  31Must give us pause: there's the respect
  32That makes calamity of so long life;
  33EOF
  34git commit -q -a -m first
  35
  36git checkout -b second master
  37git show first:a1 |
  38sed -e 's/To die, t/To die! T/' > a1
  39echo "* END *" >>a1
  40git commit -q -a -m second
  41
  42# activate rerere
  43mkdir .git/rr-cache
  44
  45test_expect_failure 'conflicting merge' 'git pull . first'
  46
  47sha1=$(sed -e 's/\t.*//' .git/rr-cache/MERGE_RR)
  48rr=.git/rr-cache/$sha1
  49test_expect_success 'recorded preimage' "grep ======= $rr/preimage"
  50
  51test_expect_success 'no postimage or thisimage yet' \
  52        "test ! -f $rr/postimage -a ! -f $rr/thisimage"
  53
  54test_expect_success 'preimage has right number of lines' '
  55
  56        cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) &&
  57        test $cnt = 9
  58
  59'
  60
  61git show first:a1 > a1
  62
  63cat > expect << EOF
  64--- a/a1
  65+++ b/a1
  66@@ -6,17 +6,9 @@
  67 The heart-ache and the thousand natural shocks
  68 That flesh is heir to, 'tis a consummation
  69 Devoutly to be wish'd.
  70-<<<<<<<
  71-To die! To sleep;
  72-=======
  73 To die, to sleep;
  74->>>>>>>
  75 To sleep: perchance to dream: ay, there's the rub;
  76 For in that sleep of death what dreams may come
  77 When we have shuffled off this mortal coil,
  78 Must give us pause: there's the respect
  79 That makes calamity of so long life;
  80-<<<<<<<
  81-=======
  82-* END *
  83->>>>>>>
  84EOF
  85git rerere diff > out
  86
  87test_expect_success 'rerere diff' 'git diff expect out'
  88
  89cat > expect << EOF
  90a1
  91EOF
  92
  93git rerere status > out
  94
  95test_expect_success 'rerere status' 'git diff expect out'
  96
  97test_expect_success 'commit succeeds' \
  98        "git commit -q -a -m 'prefer first over second'"
  99
 100test_expect_success 'recorded postimage' "test -f $rr/postimage"
 101
 102git checkout -b third master
 103git show second^:a1 | sed 's/To die: t/To die! T/' > a1
 104git commit -q -a -m third
 105
 106test_expect_failure 'another conflicting merge' 'git pull . first'
 107
 108git show first:a1 | sed 's/To die: t/To die! T/' > expect
 109test_expect_success 'rerere kicked in' "! grep ======= a1"
 110
 111test_expect_success 'rerere prefers first change' 'git diff a1 expect'
 112
 113rm $rr/postimage
 114echo "$sha1     a1" | tr '\012' '\0' > .git/rr-cache/MERGE_RR
 115
 116test_expect_success 'rerere clear' 'git rerere clear'
 117
 118test_expect_success 'clear removed the directory' "test ! -d $rr"
 119
 120mkdir $rr
 121echo Hello > $rr/preimage
 122echo World > $rr/postimage
 123
 124sha2=4000000000000000000000000000000000000000
 125rr2=.git/rr-cache/$sha2
 126mkdir $rr2
 127echo Hello > $rr2/preimage
 128
 129almost_15_days_ago=$((60-15*86400))
 130just_over_15_days_ago=$((-1-15*86400))
 131almost_60_days_ago=$((60-60*86400))
 132just_over_60_days_ago=$((-1-60*86400))
 133
 134test-chmtime =$almost_60_days_ago $rr/preimage
 135test-chmtime =$almost_15_days_ago $rr2/preimage
 136
 137test_expect_success 'garbage collection (part1)' 'git rerere gc'
 138
 139test_expect_success 'young records still live' \
 140        "test -f $rr/preimage && test -f $rr2/preimage"
 141
 142test-chmtime =$just_over_60_days_ago $rr/preimage
 143test-chmtime =$just_over_15_days_ago $rr2/preimage
 144
 145test_expect_success 'garbage collection (part2)' 'git rerere gc'
 146
 147test_expect_success 'old records rest in peace' \
 148        "test ! -f $rr/preimage && test ! -f $rr2/preimage"
 149
 150test_done
 151
 152