t / t2030-unresolve-info.shon commit Documentation/Makefile: add missing xsl dependencies for manpages (c91d03a)
   1#!/bin/sh
   2
   3test_description='undoing resolution'
   4
   5. ./test-lib.sh
   6
   7check_resolve_undo () {
   8        msg=$1
   9        shift
  10        while case $# in
  11        0)      break ;;
  12        1|2|3)  die "Bug in check-resolve-undo test" ;;
  13        esac
  14        do
  15                path=$1
  16                shift
  17                for stage in 1 2 3
  18                do
  19                        sha1=$1
  20                        shift
  21                        case "$sha1" in
  22                        '') continue ;;
  23                        esac
  24                        sha1=$(git rev-parse --verify "$sha1")
  25                        printf "100644 %s %s\t%s\n" $sha1 $stage $path
  26                done
  27        done >"$msg.expect" &&
  28        git ls-files --resolve-undo >"$msg.actual" &&
  29        test_cmp "$msg.expect" "$msg.actual"
  30}
  31
  32prime_resolve_undo () {
  33        git reset --hard &&
  34        git checkout second^0 &&
  35        test_tick &&
  36        test_must_fail git merge third^0 &&
  37        echo merge does not leave anything &&
  38        check_resolve_undo empty &&
  39        echo different >fi/le &&
  40        git add fi/le &&
  41        echo resolving records &&
  42        check_resolve_undo recorded fi/le initial:fi/le second:fi/le third:fi/le
  43}
  44
  45test_expect_success setup '
  46        mkdir fi &&
  47        printf "a\0a" >binary &&
  48        git add binary &&
  49        test_commit initial fi/le first &&
  50        git branch side &&
  51        git branch another &&
  52        printf "a\0b" >binary &&
  53        git add binary &&
  54        test_commit second fi/le second &&
  55        git checkout side &&
  56        test_commit third fi/le third &&
  57        git branch add-add &&
  58        git checkout another &&
  59        test_commit fourth fi/le fourth &&
  60        git checkout add-add &&
  61        test_commit fifth add-differently &&
  62        git checkout master
  63'
  64
  65test_expect_success 'add records switch clears' '
  66        prime_resolve_undo &&
  67        test_tick &&
  68        git commit -m merged &&
  69        echo committing keeps &&
  70        check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
  71        git checkout second^0 &&
  72        echo switching clears &&
  73        check_resolve_undo cleared
  74'
  75
  76test_expect_success 'rm records reset clears' '
  77        prime_resolve_undo &&
  78        test_tick &&
  79        git commit -m merged &&
  80        echo committing keeps &&
  81        check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
  82
  83        echo merge clears upfront &&
  84        test_must_fail git merge fourth^0 &&
  85        check_resolve_undo nuked &&
  86
  87        git rm -f fi/le &&
  88        echo resolving records &&
  89        check_resolve_undo recorded fi/le initial:fi/le HEAD:fi/le fourth:fi/le &&
  90
  91        git reset --hard &&
  92        echo resetting discards &&
  93        check_resolve_undo discarded
  94'
  95
  96test_expect_success 'plumbing clears' '
  97        prime_resolve_undo &&
  98        test_tick &&
  99        git commit -m merged &&
 100        echo committing keeps &&
 101        check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
 102
 103        echo plumbing clear &&
 104        git update-index --clear-resolve-undo &&
 105        check_resolve_undo cleared
 106'
 107
 108test_expect_success 'add records checkout -m undoes' '
 109        prime_resolve_undo &&
 110        git diff HEAD &&
 111        git checkout --conflict=merge fi/le &&
 112        echo checkout used the record and removed it &&
 113        check_resolve_undo removed &&
 114        echo the index and the work tree is unmerged again &&
 115        git diff >actual &&
 116        grep "^++<<<<<<<" actual
 117'
 118
 119test_expect_success 'unmerge with plumbing' '
 120        prime_resolve_undo &&
 121        git update-index --unresolve fi/le &&
 122        git ls-files -u >actual &&
 123        test_line_count = 3 actual
 124'
 125
 126test_expect_success 'rerere and rerere forget' '
 127        mkdir .git/rr-cache &&
 128        prime_resolve_undo &&
 129        echo record the resolution &&
 130        git rerere &&
 131        rerere_id=$(cd .git/rr-cache && echo */postimage) &&
 132        rerere_id=${rerere_id%/postimage} &&
 133        test -f .git/rr-cache/$rerere_id/postimage &&
 134        git checkout -m fi/le &&
 135        echo resurrect the conflict &&
 136        grep "^=======" fi/le &&
 137        echo reresolve the conflict &&
 138        git rerere &&
 139        test "z$(cat fi/le)" = zdifferent &&
 140        echo register the resolution again &&
 141        git add fi/le &&
 142        check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
 143        test -z "$(git ls-files -u)" &&
 144        git rerere forget fi/le &&
 145        ! test -f .git/rr-cache/$rerere_id/postimage &&
 146        tr "\0" "\n" <.git/MERGE_RR >actual &&
 147        echo "$rerere_id        fi/le" >expect &&
 148        test_cmp expect actual
 149'
 150
 151test_expect_success 'rerere and rerere forget (subdirectory)' '
 152        rm -fr .git/rr-cache &&
 153        mkdir .git/rr-cache &&
 154        prime_resolve_undo &&
 155        echo record the resolution &&
 156        (cd fi && git rerere) &&
 157        rerere_id=$(cd .git/rr-cache && echo */postimage) &&
 158        rerere_id=${rerere_id%/postimage} &&
 159        test -f .git/rr-cache/$rerere_id/postimage &&
 160        (cd fi && git checkout -m le) &&
 161        echo resurrect the conflict &&
 162        grep "^=======" fi/le &&
 163        echo reresolve the conflict &&
 164        (cd fi && git rerere) &&
 165        test "z$(cat fi/le)" = zdifferent &&
 166        echo register the resolution again &&
 167        (cd fi && git add le) &&
 168        check_resolve_undo kept fi/le initial:fi/le second:fi/le third:fi/le &&
 169        test -z "$(git ls-files -u)" &&
 170        (cd fi && git rerere forget le) &&
 171        ! test -f .git/rr-cache/$rerere_id/postimage &&
 172        tr "\0" "\n" <.git/MERGE_RR >actual &&
 173        echo "$rerere_id        fi/le" >expect &&
 174        test_cmp expect actual
 175'
 176
 177test_expect_success 'rerere forget (binary)' '
 178        git checkout -f side &&
 179        printf "a\0c" >binary &&
 180        git commit -a -m binary &&
 181        test_must_fail git merge second &&
 182        git rerere forget binary
 183'
 184
 185test_expect_success 'rerere forget (add-add conflict)' '
 186        git checkout -f master &&
 187        echo master >add-differently &&
 188        git add add-differently &&
 189        git commit -m "add differently" &&
 190        test_must_fail git merge fifth &&
 191        git rerere forget add-differently 2>actual &&
 192        test_i18ngrep "no remembered" actual
 193'
 194
 195test_done