]>
Commit | Line | Data |
---|---|---|
ad8e72cb JS |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2006 Johannes E. Schindelin | |
4 | # | |
5 | ||
6 | test_description='git-rerere | |
7 | ' | |
8 | ||
9 | . ./test-lib.sh | |
10 | ||
11 | cat > a1 << EOF | |
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. | |
20 | EOF | |
21 | ||
22 | git add a1 | |
23 | git commit -q -a -m initial | |
24 | ||
25 | git checkout -b first | |
26 | cat >> a1 << EOF | |
27 | To die, to sleep; | |
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; | |
33 | EOF | |
34 | git commit -q -a -m first | |
35 | ||
36 | git checkout -b second master | |
37 | git show first:a1 | sed 's/To die, t/To die! T/' > a1 | |
38 | git commit -q -a -m second | |
39 | ||
40 | # activate rerere | |
41 | mkdir .git/rr-cache | |
42 | ||
43 | test_expect_failure 'conflicting merge' 'git pull . first' | |
44 | ||
45 | sha1=4f58849a60b4f969a2848966b6d02893b783e8fb | |
46 | rr=.git/rr-cache/$sha1 | |
47 | test_expect_success 'recorded preimage' "grep ======= $rr/preimage" | |
48 | ||
49 | test_expect_success 'no postimage or thisimage yet' \ | |
50 | "test ! -f $rr/postimage -a ! -f $rr/thisimage" | |
51 | ||
52 | git show first:a1 > a1 | |
53 | ||
54 | cat > 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, | |
69 | EOF | |
70 | ||
71 | git rerere diff > out | |
72 | ||
73 | test_expect_success 'rerere diff' 'diff -u expect out' | |
74 | ||
75 | cat > expect << EOF | |
76 | a1 | |
77 | EOF | |
78 | ||
79 | git rerere status > out | |
80 | ||
81 | test_expect_success 'rerere status' 'diff -u expect out' | |
82 | ||
83 | test_expect_success 'commit succeeds' \ | |
84 | "git commit -q -a -m 'prefer first over second'" | |
85 | ||
86 | test_expect_success 'recorded postimage' "test -f $rr/postimage" | |
87 | ||
88 | git checkout -b third master | |
89 | git show second^:a1 | sed 's/To die: t/To die! T/' > a1 | |
90 | git commit -q -a -m third | |
91 | ||
92 | test_expect_failure 'another conflicting merge' 'git pull . first' | |
93 | ||
94 | git show first:a1 | sed 's/To die: t/To die! T/' > expect | |
95 | test_expect_success 'rerere kicked in' "! grep ======= a1" | |
96 | ||
97 | test_expect_success 'rerere prefers first change' 'diff -u a1 expect' | |
98 | ||
99 | rm $rr/postimage | |
100 | echo "$sha1 a1" | tr '\012' '\0' > .git/rr-cache/MERGE_RR | |
101 | ||
102 | test_expect_success 'rerere clear' 'git rerere clear' | |
103 | ||
104 | test_expect_success 'clear removed the directory' "test ! -d $rr" | |
105 | ||
106 | mkdir $rr | |
107 | echo Hello > $rr/preimage | |
108 | echo World > $rr/postimage | |
109 | ||
110 | sha2=4000000000000000000000000000000000000000 | |
111 | rr2=.git/rr-cache/$sha2 | |
112 | mkdir $rr2 | |
113 | echo Hello > $rr2/preimage | |
114 | ||
115 | case "$(date -d @11111111 +%s 2>/dev/null)" in | |
fa1b4d2a JH |
116 | 11111111) |
117 | # 'date' must be able to take arbitrary input with @11111111 notation. | |
118 | # for this test to succeed. We should fix this part using more | |
119 | # portable script someday. | |
120 | ||
ad8e72cb JS |
121 | now=$(date +%s) |
122 | almost_15_days_ago=$(($now+60-15*86400)) | |
123 | just_over_15_days_ago=$(($now-1-15*86400)) | |
124 | almost_60_days_ago=$(($now+60-60*86400)) | |
125 | just_over_60_days_ago=$(($now-1-60*86400)) | |
47009512 SS |
126 | predate1="$(date -d "@$almost_60_days_ago" +%Y%m%d%H%M.%S)" |
127 | predate2="$(date -d "@$almost_15_days_ago" +%Y%m%d%H%M.%S)" | |
128 | postdate1="$(date -d "@$just_over_60_days_ago" +%Y%m%d%H%M.%S)" | |
129 | postdate2="$(date -d "@$just_over_15_days_ago" +%Y%m%d%H%M.%S)" | |
ad8e72cb | 130 | |
fa1b4d2a JH |
131 | touch -m -t "$predate1" $rr/preimage |
132 | touch -m -t "$predate2" $rr2/preimage | |
ad8e72cb | 133 | |
fa1b4d2a | 134 | test_expect_success 'garbage collection (part1)' 'git rerere gc' |
ad8e72cb | 135 | |
fa1b4d2a JH |
136 | test_expect_success 'young records still live' \ |
137 | "test -f $rr/preimage -a -f $rr2/preimage" | |
ad8e72cb | 138 | |
fa1b4d2a JH |
139 | touch -m -t "$postdate1" $rr/preimage |
140 | touch -m -t "$postdate2" $rr2/preimage | |
ad8e72cb | 141 | |
fa1b4d2a | 142 | test_expect_success 'garbage collection (part2)' 'git rerere gc' |
ad8e72cb | 143 | |
fa1b4d2a JH |
144 | test_expect_success 'old records rest in peace' \ |
145 | "test ! -f $rr/preimage -a ! -f $rr2/preimage" | |
146 | ;; | |
147 | esac | |
ad8e72cb JS |
148 | |
149 | test_done | |
150 | ||
151 |