int cmd_rerere(int argc, const char **argv, const char *prefix)
{
- struct string_list merge_rr = { NULL, 0, 0, 1 };
+ struct string_list merge_rr = STRING_LIST_INIT_DUP;
- int i, fd, flags = 0;
-
- if (2 < argc) {
- if (!strcmp(argv[1], "-h"))
- usage(git_rerere_usage);
- if (!strcmp(argv[1], "--rerere-autoupdate"))
- flags = RERERE_AUTOUPDATE;
- else if (!strcmp(argv[1], "--no-rerere-autoupdate"))
- flags = RERERE_NOAUTOUPDATE;
- if (flags) {
- argc--;
- argv++;
- }
- }
- if (argc < 2)
+ int i, fd, autoupdate = -1, flags = 0;
+
+ struct option options[] = {
+ OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
+ "register clean resolutions in index", 1),
+ OPT_END(),
+ };
+
+ argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+
+ if (autoupdate == 1)
+ flags = RERERE_AUTOUPDATE;
+ if (autoupdate == 0)
+ flags = RERERE_NOAUTOUPDATE;
+
+ if (argc < 1)
return rerere(flags);
- if (!strcmp(argv[1], "forget")) {
- const char **pathspec = get_pathspec(prefix, argv + 2);
+ if (!strcmp(argv[0], "forget")) {
+ const char **pathspec = get_pathspec(prefix, argv + 1);
return rerere_forget(pathspec);
}
if (!has_rerere_resolution(name))
unlink_rr_item(name);
}
- unlink_or_warn(git_path("rr-cache/MERGE_RR"));
+ unlink_or_warn(git_path("MERGE_RR"));
- } else if (!strcmp(argv[1], "gc"))
+ } else if (!strcmp(argv[0], "gc"))
garbage_collect(&merge_rr);
- else if (!strcmp(argv[1], "status"))
+ else if (!strcmp(argv[0], "status"))
for (i = 0; i < merge_rr.nr; i++)
printf("%s\n", merge_rr.items[i].string);
- else if (!strcmp(argv[1], "diff"))
+ else if (!strcmp(argv[0], "diff"))
for (i = 0; i < merge_rr.nr; i++) {
const char *path = merge_rr.items[i].string;
const char *name = (const char *)merge_rr.items[i].util;
grep ^=======$ $rr/preimage
'
- test_expect_success 'no postimage or thisimage yet' \
- "test ! -f $rr/postimage -a ! -f $rr/thisimage"
+ test_expect_success 'set up rr-cache' '
+ rm -rf .git/rr-cache &&
+ git config rerere.enabled true &&
+ git reset --hard &&
+ test_must_fail git merge first &&
+ sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
+ rr=.git/rr-cache/$sha1
+ '
- test_expect_success 'preimage has right number of lines' '
+ test_expect_success 'rr-cache looks sane' '
+ # no postimage or thisimage yet
+ ! test -f $rr/postimage &&
+ ! test -f $rr/thisimage &&
+ # preimage has right number of lines
cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) &&
+ echo $cnt &&
test $cnt = 13
-
'
- git show first:a1 > a1
-
- cat > expect << EOF
- --- a/a1
- +++ b/a1
- @@ -1,4 +1,4 @@
- -Some Title
- +Some title
- ==========
- Whether 'tis nobler in the mind to suffer
- The slings and arrows of outrageous fortune,
- @@ -8,21 +8,11 @@
- The heart-ache and the thousand natural shocks
- That flesh is heir to, 'tis a consummation
- Devoutly to be wish'd.
- -<<<<<<<
- -Some Title
- -==========
- -To die! To sleep;
- -=======
- Some title
- ==========
- To die, to sleep;
- ->>>>>>>
- To sleep: perchance to dream: ay, there's the rub;
- For in that sleep of death what dreams may come
- When we have shuffled off this mortal coil,
- Must give us pause: there's the respect
- That makes calamity of so long life;
- -<<<<<<<
- -=======
- -* END *
- ->>>>>>>
- EOF
- git rerere diff > out
-
- test_expect_success 'rerere diff' 'test_cmp expect out'
-
- cat > expect << EOF
- a1
- EOF
-
- git rerere status > out
-
- test_expect_success 'rerere status' 'test_cmp expect out'
-
- test_expect_success 'commit succeeds' \
- "git commit -q -a -m 'prefer first over second'"
-
- test_expect_success 'recorded postimage' "test -f $rr/postimage"
-
- oldmtimepost=$(test-chmtime -v -60 $rr/postimage |cut -f 1)
-
- test_expect_success 'another conflicting merge' '
- git checkout -b third master &&
- git show second^:a1 | sed "s/To die: t/To die! T/" > a1 &&
- git commit -q -a -m third &&
- test_must_fail git pull . first
+ test_expect_success 'rerere diff' '
+ git show first:a1 >a1 &&
+ cat >expect <<-\EOF &&
+ --- a/a1
+ +++ b/a1
+ @@ -1,4 +1,4 @@
+ -Some Title
+ +Some title
+ ==========
+ Whether '\''tis nobler in the mind to suffer
+ The slings and arrows of outrageous fortune,
+ @@ -8,21 +8,11 @@
+ The heart-ache and the thousand natural shocks
+ That flesh is heir to, '\''tis a consummation
+ Devoutly to be wish'\''d.
+ -<<<<<<<
+ -Some Title
+ -==========
+ -To die! To sleep;
+ -=======
+ Some title
+ ==========
+ To die, to sleep;
+ ->>>>>>>
+ To sleep: perchance to dream: ay, there'\''s the rub;
+ For in that sleep of death what dreams may come
+ When we have shuffled off this mortal coil,
+ Must give us pause: there'\''s the respect
+ That makes calamity of so long life;
+ -<<<<<<<
+ -=======
+ -* END *
+ ->>>>>>>
+ EOF
+ git rerere diff >out &&
+ test_cmp expect out
'
- git show first:a1 | sed 's/To die: t/To die! T/' > expect
- test_expect_success 'rerere kicked in' "! grep ^=======$ a1"
-
- test_expect_success 'rerere prefers first change' 'test_cmp a1 expect'
-
- test_expect_success 'rerere updates postimage timestamp' '
- newmtimepost=$(test-chmtime -v +0 $rr/postimage |cut -f 1) &&
- test $oldmtimepost -lt $newmtimepost
+ test_expect_success 'rerere status' '
+ echo a1 >expect &&
+ git rerere status >out &&
+ test_cmp expect out
'
- rm $rr/postimage
- echo "$sha1 a1" | perl -pe 'y/\012/\000/' > .git/MERGE_RR
+ test_expect_success 'first postimage wins' '
+ git show first:a1 | sed "s/To die: t/To die! T/" >expect &&
- test_expect_success 'rerere clear' 'git rerere clear'
+ git commit -q -a -m "prefer first over second" &&
+ test -f $rr/postimage &&
- test_expect_success 'clear removed the directory' "test ! -d $rr"
++ oldmtimepost=$(test-chmtime -v -60 $rr/postimage | cut -f 1) &&
+
- mkdir $rr
- echo Hello > $rr/preimage
- echo World > $rr/postimage
+ git checkout -b third master &&
+ git show second^:a1 | sed "s/To die: t/To die! T/" >a1 &&
+ git commit -q -a -m third &&
- sha2=4000000000000000000000000000000000000000
- rr2=.git/rr-cache/$sha2
- mkdir $rr2
- echo Hello > $rr2/preimage
+ test_must_fail git pull . first &&
+ # rerere kicked in
+ ! grep "^=======\$" a1 &&
+ test_cmp expect a1
+ '
- almost_15_days_ago=$((60-15*86400))
- just_over_15_days_ago=$((-1-15*86400))
- almost_60_days_ago=$((60-60*86400))
- just_over_60_days_ago=$((-1-60*86400))
++test_expect_success 'rerere updates postimage timestamp' '
++ newmtimepost=$(test-chmtime -v +0 $rr/postimage | cut -f 1) &&
++ test $oldmtimepost -lt $newmtimepost
++'
+
- test-chmtime =$just_over_60_days_ago $rr/preimage
- test-chmtime =$almost_60_days_ago $rr/postimage
- test-chmtime =$almost_15_days_ago $rr2/preimage
+ test_expect_success 'rerere clear' '
+ rm $rr/postimage &&
+ echo "$sha1 a1" | perl -pe "y/\012/\000/" >.git/MERGE_RR &&
+ git rerere clear &&
+ ! test -d $rr
+ '
- test_expect_success 'garbage collection (part1)' 'git rerere gc'
+ test_expect_success 'set up for garbage collection tests' '
+ mkdir -p $rr &&
+ echo Hello >$rr/preimage &&
+ echo World >$rr/postimage &&
- test_expect_success 'young or recently used records still live' \
- "test -f $rr/preimage && test -f $rr2/preimage"
+ sha2=4000000000000000000000000000000000000000 &&
+ rr2=.git/rr-cache/$sha2 &&
+ mkdir $rr2 &&
+ echo Hello >$rr2/preimage &&
- test-chmtime =$just_over_60_days_ago $rr/postimage
- test-chmtime =$just_over_15_days_ago $rr2/preimage
+ almost_15_days_ago=$((60-15*86400)) &&
+ just_over_15_days_ago=$((-1-15*86400)) &&
+ almost_60_days_ago=$((60-60*86400)) &&
+ just_over_60_days_ago=$((-1-60*86400)) &&
- test_expect_success 'garbage collection (part2)' 'git rerere gc'
- test-chmtime =$almost_60_days_ago $rr/preimage &&
++ test-chmtime =$just_over_60_days_ago $rr/preimage &&
++ test-chmtime =$almost_60_days_ago $rr/postimage &&
+ test-chmtime =$almost_15_days_ago $rr2/preimage
+ '
- test_expect_success 'old records rest in peace' \
- "test ! -f $rr/preimage && test ! -f $rr2/preimage"
-test_expect_success 'garbage collection preserves young records' '
++test_expect_success 'gc preserves young or recently used records' '
+ git rerere gc &&
+ test -f $rr/preimage &&
+ test -f $rr2/preimage
+ '
- test_expect_success 'file2 added differently in two branches' '
+ test_expect_success 'old records rest in peace' '
- test-chmtime =$just_over_60_days_ago $rr/preimage &&
++ test-chmtime =$just_over_60_days_ago $rr/postimage &&
+ test-chmtime =$just_over_15_days_ago $rr2/preimage &&
+ git rerere gc &&
+ ! test -f $rr/preimage &&
+ ! test -f $rr2/preimage
+ '
+
+ test_expect_success 'setup: file2 added differently in two branches' '
git reset --hard &&
+
git checkout -b fourth &&
- echo Hallo > file2 &&
+ echo Hallo >file2 &&
git add file2 &&
+ test_tick &&
git commit -m version1 &&
+
git checkout third &&
- echo Bello > file2 &&
+ echo Bello >file2 &&
git add file2 &&
+ test_tick &&
git commit -m version2 &&
+
test_must_fail git merge fourth &&
- echo Cello > file2 &&
+ echo Cello >file2 &&
git add file2 &&
git commit -m resolution
'