t / t4200-rerere.shon commit Merge branch 'maint-1.7.1' into maint-1.7.2 (2de132f)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Johannes E. Schindelin
   4#
   5
   6test_description='git rerere
   7'
   8
   9. ./test-lib.sh
  10
  11test_expect_success 'setup' "
  12        cat > a1 <<- EOF &&
  13        Some title
  14        ==========
  15        Whether 'tis nobler in the mind to suffer
  16        The slings and arrows of outrageous fortune,
  17        Or to take arms against a sea of troubles,
  18        And by opposing end them? To die: to sleep;
  19        No more; and by a sleep to say we end
  20        The heart-ache and the thousand natural shocks
  21        That flesh is heir to, 'tis a consummation
  22        Devoutly to be wish'd.
  23        EOF
  24
  25        git add a1 &&
  26        git commit -q -a -m initial &&
  27
  28        git checkout -b first &&
  29        cat >> a1 <<- EOF &&
  30        Some title
  31        ==========
  32        To die, to sleep;
  33        To sleep: perchance to dream: ay, there's the rub;
  34        For in that sleep of death what dreams may come
  35        When we have shuffled off this mortal coil,
  36        Must give us pause: there's the respect
  37        That makes calamity of so long life;
  38        EOF
  39        git commit -q -a -m first &&
  40
  41        git checkout -b second master &&
  42        git show first:a1 |
  43        sed -e 's/To die, t/To die! T/' -e 's/Some title/Some Title/' > a1 &&
  44        echo '* END *' >>a1 &&
  45        git commit -q -a -m second
  46"
  47
  48test_expect_success 'nothing recorded without rerere' '
  49        (rm -rf .git/rr-cache; git config rerere.enabled false) &&
  50        test_must_fail git merge first &&
  51        ! test -d .git/rr-cache
  52'
  53
  54# activate rerere, old style
  55test_expect_success 'conflicting merge' '
  56        git reset --hard &&
  57        mkdir .git/rr-cache &&
  58        git config --unset rerere.enabled &&
  59        test_must_fail git merge first
  60'
  61
  62sha1=$(perl -pe 's/     .*//' .git/MERGE_RR)
  63rr=.git/rr-cache/$sha1
  64test_expect_success 'recorded preimage' "grep ^=======$ $rr/preimage"
  65
  66test_expect_success 'rerere.enabled works, too' '
  67        rm -rf .git/rr-cache &&
  68        git config rerere.enabled true &&
  69        git reset --hard &&
  70        test_must_fail git merge first &&
  71        grep ^=======$ $rr/preimage
  72'
  73
  74test_expect_success 'no postimage or thisimage yet' \
  75        "test ! -f $rr/postimage -a ! -f $rr/thisimage"
  76
  77test_expect_success 'preimage has right number of lines' '
  78
  79        cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) &&
  80        test $cnt = 13
  81
  82'
  83
  84git show first:a1 > a1
  85
  86cat > expect << EOF
  87--- a/a1
  88+++ b/a1
  89@@ -1,4 +1,4 @@
  90-Some Title
  91+Some title
  92 ==========
  93 Whether 'tis nobler in the mind to suffer
  94 The slings and arrows of outrageous fortune,
  95@@ -8,21 +8,11 @@
  96 The heart-ache and the thousand natural shocks
  97 That flesh is heir to, 'tis a consummation
  98 Devoutly to be wish'd.
  99-<<<<<<<
 100-Some Title
 101-==========
 102-To die! To sleep;
 103-=======
 104 Some title
 105 ==========
 106 To die, to sleep;
 107->>>>>>>
 108 To sleep: perchance to dream: ay, there's the rub;
 109 For in that sleep of death what dreams may come
 110 When we have shuffled off this mortal coil,
 111 Must give us pause: there's the respect
 112 That makes calamity of so long life;
 113-<<<<<<<
 114-=======
 115-* END *
 116->>>>>>>
 117EOF
 118git rerere diff > out
 119
 120test_expect_success 'rerere diff' 'test_cmp expect out'
 121
 122cat > expect << EOF
 123a1
 124EOF
 125
 126git rerere status > out
 127
 128test_expect_success 'rerere status' 'test_cmp expect out'
 129
 130test_expect_success 'commit succeeds' \
 131        "git commit -q -a -m 'prefer first over second'"
 132
 133test_expect_success 'recorded postimage' "test -f $rr/postimage"
 134
 135oldmtimepost=$(test-chmtime -v -60 $rr/postimage |cut -f 1)
 136
 137test_expect_success 'another conflicting merge' '
 138        git checkout -b third master &&
 139        git show second^:a1 | sed "s/To die: t/To die! T/" > a1 &&
 140        git commit -q -a -m third &&
 141        test_must_fail git pull . first
 142'
 143
 144git show first:a1 | sed 's/To die: t/To die! T/' > expect
 145test_expect_success 'rerere kicked in' "! grep ^=======$ a1"
 146
 147test_expect_success 'rerere prefers first change' 'test_cmp a1 expect'
 148
 149test_expect_success 'rerere updates postimage timestamp' '
 150        newmtimepost=$(test-chmtime -v +0 $rr/postimage |cut -f 1) &&
 151        test $oldmtimepost -lt $newmtimepost
 152'
 153
 154rm $rr/postimage
 155echo "$sha1     a1" | perl -pe 'y/\012/\000/' > .git/MERGE_RR
 156
 157test_expect_success 'rerere clear' 'git rerere clear'
 158
 159test_expect_success 'clear removed the directory' "test ! -d $rr"
 160
 161mkdir $rr
 162echo Hello > $rr/preimage
 163echo World > $rr/postimage
 164
 165sha2=4000000000000000000000000000000000000000
 166rr2=.git/rr-cache/$sha2
 167mkdir $rr2
 168echo Hello > $rr2/preimage
 169
 170almost_15_days_ago=$((60-15*86400))
 171just_over_15_days_ago=$((-1-15*86400))
 172almost_60_days_ago=$((60-60*86400))
 173just_over_60_days_ago=$((-1-60*86400))
 174
 175test-chmtime =$just_over_60_days_ago $rr/preimage
 176test-chmtime =$almost_60_days_ago $rr/postimage
 177test-chmtime =$almost_15_days_ago $rr2/preimage
 178
 179test_expect_success 'garbage collection (part1)' 'git rerere gc'
 180
 181test_expect_success 'young or recently used records still live' \
 182        "test -f $rr/preimage && test -f $rr2/preimage"
 183
 184test-chmtime =$just_over_60_days_ago $rr/postimage
 185test-chmtime =$just_over_15_days_ago $rr2/preimage
 186
 187test_expect_success 'garbage collection (part2)' 'git rerere gc'
 188
 189test_expect_success 'old records rest in peace' \
 190        "test ! -f $rr/preimage && test ! -f $rr2/preimage"
 191
 192test_expect_success 'file2 added differently in two branches' '
 193        git reset --hard &&
 194        git checkout -b fourth &&
 195        echo Hallo > file2 &&
 196        git add file2 &&
 197        git commit -m version1 &&
 198        git checkout third &&
 199        echo Bello > file2 &&
 200        git add file2 &&
 201        git commit -m version2 &&
 202        test_must_fail git merge fourth &&
 203        echo Cello > file2 &&
 204        git add file2 &&
 205        git commit -m resolution
 206'
 207
 208test_expect_success 'resolution was recorded properly' '
 209        git reset --hard HEAD~2 &&
 210        git checkout -b fifth &&
 211        echo Hallo > file3 &&
 212        git add file3 &&
 213        git commit -m version1 &&
 214        git checkout third &&
 215        echo Bello > file3 &&
 216        git add file3 &&
 217        git commit -m version2 &&
 218        git tag version2 &&
 219        test_must_fail git merge fifth &&
 220        test Cello = "$(cat file3)" &&
 221        test 0 != $(git ls-files -u | wc -l)
 222'
 223
 224test_expect_success 'rerere.autoupdate' '
 225        git config rerere.autoupdate true
 226        git reset --hard &&
 227        git checkout version2 &&
 228        test_must_fail git merge fifth &&
 229        test 0 = $(git ls-files -u | wc -l)
 230'
 231
 232test_expect_success 'merge --rerere-autoupdate' '
 233        git config --unset rerere.autoupdate
 234        git reset --hard &&
 235        git checkout version2 &&
 236        test_must_fail git merge --rerere-autoupdate fifth &&
 237        test 0 = $(git ls-files -u | wc -l)
 238'
 239
 240test_expect_success 'merge --no-rerere-autoupdate' '
 241        git config rerere.autoupdate true
 242        git reset --hard &&
 243        git checkout version2 &&
 244        test_must_fail git merge --no-rerere-autoupdate fifth &&
 245        test 2 = $(git ls-files -u | wc -l)
 246'
 247
 248test_done