t / t6035-merge-dir-to-symlink.shon commit Merge branch 'jn/cherry-revert-message-clean-up' (ae76cb9)
   1#!/bin/sh
   2
   3test_description='merging when a directory was replaced with a symlink'
   4. ./test-lib.sh
   5
   6if ! test_have_prereq SYMLINKS
   7then
   8        skip_all='Symbolic links not supported, skipping tests.'
   9        test_done
  10fi
  11
  12test_expect_success 'create a commit where dir a/b changed to symlink' '
  13        mkdir -p a/b/c a/b-2/c &&
  14        > a/b/c/d &&
  15        > a/b-2/c/d &&
  16        > a/x &&
  17        git add -A &&
  18        git commit -m base &&
  19        git tag start &&
  20        rm -rf a/b &&
  21        ln -s b-2 a/b &&
  22        git add -A &&
  23        git commit -m "dir to symlink"
  24'
  25
  26test_expect_success 'keep a/b-2/c/d across checkout' '
  27        git checkout HEAD^0 &&
  28        git reset --hard master &&
  29        git rm --cached a/b &&
  30        git commit -m "untracked symlink remains" &&
  31         git checkout start^0 &&
  32         test -f a/b-2/c/d
  33'
  34
  35test_expect_success 'checkout should not have deleted a/b-2/c/d' '
  36        git checkout HEAD^0 &&
  37        git reset --hard master &&
  38         git checkout start^0 &&
  39         test -f a/b-2/c/d
  40'
  41
  42test_expect_success 'setup for merge test' '
  43        git reset --hard &&
  44        test -f a/b-2/c/d &&
  45        echo x > a/x &&
  46        git add a/x &&
  47        git commit -m x &&
  48        git tag baseline
  49'
  50
  51test_expect_success 'Handle D/F conflict, do not lose a/b-2/c/d in merge (resolve)' '
  52        git reset --hard &&
  53        git checkout baseline^0 &&
  54        git merge -s resolve master &&
  55        test -h a/b &&
  56        test -f a/b-2/c/d
  57'
  58
  59test_expect_success 'Handle D/F conflict, do not lose a/b-2/c/d in merge (recursive)' '
  60        git reset --hard &&
  61        git checkout baseline^0 &&
  62        git merge -s recursive master &&
  63        test -h a/b &&
  64        test -f a/b-2/c/d
  65'
  66
  67test_expect_success 'Handle F/D conflict, do not lose a/b-2/c/d in merge (resolve)' '
  68        git reset --hard &&
  69        git checkout master^0 &&
  70        git merge -s resolve baseline^0 &&
  71        test -h a/b &&
  72        test -f a/b-2/c/d
  73'
  74
  75test_expect_success 'Handle F/D conflict, do not lose a/b-2/c/d in merge (recursive)' '
  76        git reset --hard &&
  77        git checkout master^0 &&
  78        git merge -s recursive baseline^0 &&
  79        test -h a/b &&
  80        test -f a/b-2/c/d
  81'
  82
  83test_expect_failure 'do not lose untracked in merge (resolve)' '
  84        git reset --hard &&
  85        git checkout baseline^0 &&
  86        >a/b/c/e &&
  87        test_must_fail git merge -s resolve master &&
  88        test -f a/b/c/e &&
  89        test -f a/b-2/c/d
  90'
  91
  92test_expect_success 'do not lose untracked in merge (recursive)' '
  93        git reset --hard &&
  94        git checkout baseline^0 &&
  95        >a/b/c/e &&
  96        test_must_fail git merge -s recursive master &&
  97        test -f a/b/c/e &&
  98        test -f a/b-2/c/d
  99'
 100
 101test_expect_success 'do not lose modifications in merge (resolve)' '
 102        git reset --hard &&
 103        git checkout baseline^0 &&
 104        echo more content >>a/b/c/d &&
 105        test_must_fail git merge -s resolve master
 106'
 107
 108test_expect_success 'do not lose modifications in merge (recursive)' '
 109        git reset --hard &&
 110        git checkout baseline^0 &&
 111        echo more content >>a/b/c/d &&
 112        test_must_fail git merge -s recursive master
 113'
 114
 115test_expect_success 'setup a merge where dir a/b-2 changed to symlink' '
 116        git reset --hard &&
 117        git checkout start^0 &&
 118        rm -rf a/b-2 &&
 119        ln -s b a/b-2 &&
 120        git add -A &&
 121        git commit -m "dir a/b-2 to symlink" &&
 122        git tag test2
 123'
 124
 125test_expect_success 'merge should not have D/F conflicts (resolve)' '
 126        git reset --hard &&
 127        git checkout baseline^0 &&
 128        git merge -s resolve test2 &&
 129        test -h a/b-2 &&
 130        test -f a/b/c/d
 131'
 132
 133test_expect_success 'merge should not have D/F conflicts (recursive)' '
 134        git reset --hard &&
 135        git checkout baseline^0 &&
 136        git merge -s recursive test2 &&
 137        test -h a/b-2 &&
 138        test -f a/b/c/d
 139'
 140
 141test_expect_success 'merge should not have F/D conflicts (recursive)' '
 142        git reset --hard &&
 143        git checkout -b foo test2 &&
 144        git merge -s recursive baseline^0 &&
 145        test -h a/b-2 &&
 146        test -f a/b/c/d
 147'
 148
 149test_done