t / t4200-rerere.shon commit bash completion: Support "divergence from upstream" messages in __git_ps1 (6d158cb)
   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
 135test_expect_success 'another conflicting merge' '
 136        git checkout -b third master &&
 137        git show second^:a1 | sed "s/To die: t/To die! T/" > a1 &&
 138        git commit -q -a -m third &&
 139        test_must_fail git pull . first
 140'
 141
 142git show first:a1 | sed 's/To die: t/To die! T/' > expect
 143test_expect_success 'rerere kicked in' "! grep ^=======$ a1"
 144
 145test_expect_success 'rerere prefers first change' 'test_cmp a1 expect'
 146
 147rm $rr/postimage
 148echo "$sha1     a1" | perl -pe 'y/\012/\000/' > .git/MERGE_RR
 149
 150test_expect_success 'rerere clear' 'git rerere clear'
 151
 152test_expect_success 'clear removed the directory' "test ! -d $rr"
 153
 154mkdir $rr
 155echo Hello > $rr/preimage
 156echo World > $rr/postimage
 157
 158sha2=4000000000000000000000000000000000000000
 159rr2=.git/rr-cache/$sha2
 160mkdir $rr2
 161echo Hello > $rr2/preimage
 162
 163almost_15_days_ago=$((60-15*86400))
 164just_over_15_days_ago=$((-1-15*86400))
 165almost_60_days_ago=$((60-60*86400))
 166just_over_60_days_ago=$((-1-60*86400))
 167
 168test-chmtime =$almost_60_days_ago $rr/preimage
 169test-chmtime =$almost_15_days_ago $rr2/preimage
 170
 171test_expect_success 'garbage collection (part1)' 'git rerere gc'
 172
 173test_expect_success 'young records still live' \
 174        "test -f $rr/preimage && test -f $rr2/preimage"
 175
 176test-chmtime =$just_over_60_days_ago $rr/preimage
 177test-chmtime =$just_over_15_days_ago $rr2/preimage
 178
 179test_expect_success 'garbage collection (part2)' 'git rerere gc'
 180
 181test_expect_success 'old records rest in peace' \
 182        "test ! -f $rr/preimage && test ! -f $rr2/preimage"
 183
 184test_expect_success 'file2 added differently in two branches' '
 185        git reset --hard &&
 186        git checkout -b fourth &&
 187        echo Hallo > file2 &&
 188        git add file2 &&
 189        git commit -m version1 &&
 190        git checkout third &&
 191        echo Bello > file2 &&
 192        git add file2 &&
 193        git commit -m version2 &&
 194        test_must_fail git merge fourth &&
 195        echo Cello > file2 &&
 196        git add file2 &&
 197        git commit -m resolution
 198'
 199
 200test_expect_success 'resolution was recorded properly' '
 201        git reset --hard HEAD~2 &&
 202        git checkout -b fifth &&
 203        echo Hallo > file3 &&
 204        git add file3 &&
 205        git commit -m version1 &&
 206        git checkout third &&
 207        echo Bello > file3 &&
 208        git add file3 &&
 209        git commit -m version2 &&
 210        git tag version2 &&
 211        test_must_fail git merge fifth &&
 212        test Cello = "$(cat file3)" &&
 213        test 0 != $(git ls-files -u | wc -l)
 214'
 215
 216test_expect_success 'rerere.autoupdate' '
 217        git config rerere.autoupdate true
 218        git reset --hard &&
 219        git checkout version2 &&
 220        test_must_fail git merge fifth &&
 221        test 0 = $(git ls-files -u | wc -l)
 222'
 223
 224test_expect_success 'merge --rerere-autoupdate' '
 225        git config --unset rerere.autoupdate
 226        git reset --hard &&
 227        git checkout version2 &&
 228        test_must_fail git merge --rerere-autoupdate fifth &&
 229        test 0 = $(git ls-files -u | wc -l)
 230'
 231
 232test_expect_success 'merge --no-rerere-autoupdate' '
 233        git config rerere.autoupdate true
 234        git reset --hard &&
 235        git checkout version2 &&
 236        test_must_fail git merge --no-rerere-autoupdate fifth &&
 237        test 2 = $(git ls-files -u | wc -l)
 238'
 239
 240test_done