t / t4200-rerere.shon commit checkout: allow detaching to HEAD even when switching to the tip of a branch (3e0318a)
   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/' -e 's/life;$/life./' > a1
  39git commit -q -a -m second
  40
  41# activate rerere
  42mkdir .git/rr-cache
  43
  44test_expect_failure 'conflicting merge' 'git pull . first'
  45
  46sha1=$(sed -e 's/\t.*//' .git/rr-cache/MERGE_RR)
  47rr=.git/rr-cache/$sha1
  48test_expect_success 'recorded preimage' "grep ======= $rr/preimage"
  49
  50test_expect_success 'no postimage or thisimage yet' \
  51        "test ! -f $rr/postimage -a ! -f $rr/thisimage"
  52
  53test_expect_success 'preimage have right number of lines' '
  54
  55        cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) &&
  56        test "$cnt" = 10
  57
  58'
  59
  60git show first:a1 > a1
  61
  62cat > expect << EOF
  63--- a/a1
  64+++ b/a1
  65@@ -6,17 +6,9 @@
  66 The heart-ache and the thousand natural shocks
  67 That flesh is heir to, 'tis a consummation
  68 Devoutly to be wish'd.
  69-<<<<<<<
  70-To die! To sleep;
  71-=======
  72 To die, to sleep;
  73->>>>>>>
  74 To sleep: perchance to dream: ay, there's the rub;
  75 For in that sleep of death what dreams may come
  76 When we have shuffled off this mortal coil,
  77 Must give us pause: there's the respect
  78-<<<<<<<
  79-That makes calamity of so long life.
  80-=======
  81 That makes calamity of so long life;
  82->>>>>>>
  83EOF
  84git rerere diff > out
  85
  86test_expect_success 'rerere diff' 'git diff expect out'
  87
  88cat > expect << EOF
  89a1
  90EOF
  91
  92git rerere status > out
  93
  94test_expect_success 'rerere status' 'git diff expect out'
  95
  96test_expect_success 'commit succeeds' \
  97        "git commit -q -a -m 'prefer first over second'"
  98
  99test_expect_success 'recorded postimage' "test -f $rr/postimage"
 100
 101git checkout -b third master
 102git show second^:a1 | sed 's/To die: t/To die! T/' > a1
 103git commit -q -a -m third
 104
 105test_expect_failure 'another conflicting merge' 'git pull . first'
 106
 107git show first:a1 | sed 's/To die: t/To die! T/' > expect
 108test_expect_success 'rerere kicked in' "! grep ======= a1"
 109
 110test_expect_success 'rerere prefers first change' 'git diff a1 expect'
 111
 112rm $rr/postimage
 113echo "$sha1     a1" | tr '\012' '\0' > .git/rr-cache/MERGE_RR
 114
 115test_expect_success 'rerere clear' 'git rerere clear'
 116
 117test_expect_success 'clear removed the directory' "test ! -d $rr"
 118
 119mkdir $rr
 120echo Hello > $rr/preimage
 121echo World > $rr/postimage
 122
 123sha2=4000000000000000000000000000000000000000
 124rr2=.git/rr-cache/$sha2
 125mkdir $rr2
 126echo Hello > $rr2/preimage
 127
 128almost_15_days_ago=$((60-15*86400))
 129just_over_15_days_ago=$((-1-15*86400))
 130almost_60_days_ago=$((60-60*86400))
 131just_over_60_days_ago=$((-1-60*86400))
 132
 133test-chmtime =$almost_60_days_ago $rr/preimage
 134test-chmtime =$almost_15_days_ago $rr2/preimage
 135
 136test_expect_success 'garbage collection (part1)' 'git rerere gc'
 137
 138test_expect_success 'young records still live' \
 139        "test -f $rr/preimage && test -f $rr2/preimage"
 140
 141test-chmtime =$just_over_60_days_ago $rr/preimage
 142test-chmtime =$just_over_15_days_ago $rr2/preimage
 143
 144test_expect_success 'garbage collection (part2)' 'git rerere gc'
 145
 146test_expect_success 'old records rest in peace' \
 147        "test ! -f $rr/preimage && test ! -f $rr2/preimage"
 148
 149test_done
 150
 151