3 # Copyright (c) 2006 Johannes E. Schindelin
6 test_description
='git-rerere
12 Whether 'tis nobler in the mind to suffer
13 The slings and arrows of outrageous fortune,
14 Or to take arms against a sea of troubles,
15 And by opposing end them? To die: to sleep;
16 No more; and by a sleep to say we end
17 The heart-ache and the thousand natural shocks
18 That flesh is heir to, 'tis a consummation
19 Devoutly to be wish'd.
23 git commit
-q -a -m initial
28 To sleep: perchance to dream: ay, there's the rub;
29 For in that sleep of death what dreams may come
30 When we have shuffled off this mortal coil,
31 Must give us pause: there's the respect
32 That makes calamity of so long life;
34 git commit
-q -a -m first
36 git checkout
-b second master
38 sed -e 's/To die, t/To die! T/' -e 's/life;$/life./' > a1
39 git commit
-q -a -m second
44 test_expect_failure
'conflicting merge' 'git pull . first'
46 sha1
=$
(sed -e 's/\t.*//' .git
/rr-cache
/MERGE_RR
)
47 rr
=.git
/rr-cache
/$sha1
48 test_expect_success
'recorded preimage' "grep ======= $rr/preimage"
50 test_expect_success
'no postimage or thisimage yet' \
51 "test ! -f $rr/postimage -a ! -f $rr/thisimage"
53 test_expect_success
'preimage have right number of lines' '
55 cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) &&
60 git show first
:a1
> a1
66 The heart-ache and the thousand natural shocks
67 That flesh is heir to, 'tis a consummation
68 Devoutly to be wish'd.
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
79 -That makes calamity of so long life.
81 That makes calamity of so long life;
86 test_expect_success
'rerere diff' 'diff -u expect out'
92 git rerere status
> out
94 test_expect_success
'rerere status' 'diff -u expect out'
96 test_expect_success
'commit succeeds' \
97 "git commit -q -a -m 'prefer first over second'"
99 test_expect_success
'recorded postimage' "test -f $rr/postimage"
101 git checkout
-b third master
102 git show second^
:a1 |
sed 's/To die: t/To die! T/' > a1
103 git commit
-q -a -m third
105 test_expect_failure
'another conflicting merge' 'git pull . first'
107 git show first
:a1 |
sed 's/To die: t/To die! T/' > expect
108 test_expect_success
'rerere kicked in' "! grep ======= a1"
110 test_expect_success
'rerere prefers first change' 'diff -u a1 expect'
113 echo "$sha1 a1" |
tr '\012' '\0' > .git
/rr-cache
/MERGE_RR
115 test_expect_success
'rerere clear' 'git rerere clear'
117 test_expect_success
'clear removed the directory' "test ! -d $rr"
120 echo Hello
> $rr/preimage
121 echo World
> $rr/postimage
123 sha2
=4000000000000000000000000000000000000000
124 rr2
=.git
/rr-cache
/$sha2
126 echo Hello
> $rr2/preimage
128 case "$(date -d @11111111 +%s 2>/dev/null)" in
130 # 'date' must be able to take arbitrary input with @11111111 notation.
131 # for this test to succeed. We should fix this part using more
132 # portable script someday.
135 almost_15_days_ago
=$
(($now+60-15*86400))
136 just_over_15_days_ago
=$
(($now-1-15*86400))
137 almost_60_days_ago
=$
(($now+60-60*86400))
138 just_over_60_days_ago
=$
(($now-1-60*86400))
139 predate1
="$(date -d "@
$almost_60_days_ago" +%Y%m%d%H%M.%S)"
140 predate2
="$(date -d "@
$almost_15_days_ago" +%Y%m%d%H%M.%S)"
141 postdate1
="$(date -d "@
$just_over_60_days_ago" +%Y%m%d%H%M.%S)"
142 postdate2
="$(date -d "@
$just_over_15_days_ago" +%Y%m%d%H%M.%S)"
144 touch -m -t "$predate1" $rr/preimage
145 touch -m -t "$predate2" $rr2/preimage
147 test_expect_success
'garbage collection (part1)' 'git rerere gc'
149 test_expect_success
'young records still live' \
150 "test -f $rr/preimage -a -f $rr2/preimage"
152 touch -m -t "$postdate1" $rr/preimage
153 touch -m -t "$postdate2" $rr2/preimage
155 test_expect_success
'garbage collection (part2)' 'git rerere gc'
157 test_expect_success
'old records rest in peace' \
158 "test ! -f $rr/preimage -a ! -f $rr2/preimage"