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 |sed's/To die, t/To die! T/'> a1 38git commit -q -a -m second 39 40# activate rerere 41mkdir .git/rr-cache 42 43test_expect_failure 'conflicting merge''git pull . first' 44 45sha1=4f58849a60b4f969a2848966b6d02893b783e8fb 46rr=.git/rr-cache/$sha1 47test_expect_success 'recorded preimage'"grep =======$rr/preimage" 48 49test_expect_success 'no postimage or thisimage yet' \ 50"test ! -f$rr/postimage -a ! -f$rr/thisimage" 51 52git show first:a1 > a1 53 54cat> expect << EOF 55--- a/a1 56+++ b/a1 57@@ -6,11 +6,7 @@ 58 The heart-ache and the thousand natural shocks 59 That flesh is heir to, 'tis a consummation 60 Devoutly to be wish'd. 61-<<<<<<< 62-To die! To sleep; 63-======= 64 To die, to sleep; 65->>>>>>> 66 To sleep: perchance to dream: ay, there's the rub; 67 For in that sleep of death what dreams may come 68 When we have shuffled off this mortal coil, 69EOF 70 71git rerere diff> out 72 73test_expect_success 'rerere diff''diff -u expect out' 74 75cat> expect << EOF 76a1 77EOF 78 79git rerere status > out 80 81test_expect_success 'rerere status''diff -u expect out' 82 83test_expect_success 'commit succeeds' \ 84"git commit -q -a -m 'prefer first over second'" 85 86test_expect_success 'recorded postimage'"test -f$rr/postimage" 87 88git checkout -b third master 89git show second^:a1 |sed's/To die: t/To die! T/'> a1 90git commit -q -a -m third 91 92test_expect_failure 'another conflicting merge''git pull . first' 93 94git show first:a1 |sed's/To die: t/To die! T/'> expect 95test_expect_success 'rerere kicked in'"! grep ======= a1" 96 97test_expect_success 'rerere prefers first change''diff -u a1 expect' 98 99rm$rr/postimage 100echo"$sha1a1"|tr'\012''\0'> .git/rr-cache/MERGE_RR 101 102test_expect_success 'rerere clear''git rerere clear' 103 104test_expect_success 'clear removed the directory'"test ! -d$rr" 105 106mkdir$rr 107echo Hello >$rr/preimage 108echo World >$rr/postimage 109 110sha2=4000000000000000000000000000000000000000 111rr2=.git/rr-cache/$sha2 112mkdir$rr2 113echo Hello >$rr2/preimage 114 115case"$(date -d @11111111 +%s 2>/dev/null)"in 116[1-9]*) 117# it is a recent GNU date. good. 118 now=$(date +%s) 119 almost_15_days_ago=$(($now+60-15*86400)) 120 just_over_15_days_ago=$(($now-1-15*86400)) 121 almost_60_days_ago=$(($now+60-60*86400)) 122 just_over_60_days_ago=$(($now-1-60*86400)) 123 predate1="$(date -d "@$almost_60_days_ago" +%c)" 124 predate2="$(date -d "@$almost_15_days_ago" +%c)" 125 postdate1="$(date -d "@$just_over_60_days_ago" +%c)" 126 postdate2="$(date -d "@$just_over_15_days_ago" +%c)" 127;; 128*) 129# it is not GNU date. oh, well. 130 predate1="$(date)" 131 predate2="$(date)" 132 postdate1='1 Oct 2006 00:00:00' 133 postdate2='1 Dec 2006 00:00:00' 134esac 135 136touch-m -d"$predate1"$rr/preimage 137touch-m -d"$predate2"$rr2/preimage 138 139test_expect_success 'garbage collection (part1)''git rerere gc' 140 141test_expect_success 'young records still live' \ 142"test -f$rr/preimage -a -f$rr2/preimage" 143 144touch-m -d"$postdate1"$rr/preimage 145touch-m -d"$postdate2"$rr2/preimage 146 147test_expect_success 'garbage collection (part2)''git rerere gc' 148 149test_expect_success 'old records rest in peace' \ 150"test ! -f$rr/preimage -a ! -f$rr2/preimage" 151 152test_done 153 154