t / t4114-apply-typechange.shon commit Merge branch 'lt/maint-diff-reduce-lstat' into maint (5e04a1e)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Eric Wong
   4#
   5
   6test_description='git apply should not get confused with type changes.
   7
   8'
   9
  10. ./test-lib.sh
  11
  12if ! test_have_prereq SYMLINKS
  13then
  14        say 'Symbolic links not supported, skipping tests.'
  15        test_done
  16fi
  17
  18test_expect_success 'setup repository and commits' '
  19        echo "hello world" > foo &&
  20        echo "hi planet" > bar &&
  21        git update-index --add foo bar &&
  22        git commit -m initial &&
  23        git branch initial &&
  24        rm -f foo &&
  25        ln -s bar foo &&
  26        git update-index foo &&
  27        git commit -m "foo symlinked to bar" &&
  28        git branch foo-symlinked-to-bar &&
  29        rm -f foo &&
  30        echo "how far is the sun?" > foo &&
  31        git update-index foo &&
  32        git commit -m "foo back to file" &&
  33        git branch foo-back-to-file &&
  34        printf "\0" > foo &&
  35        git update-index foo &&
  36        git commit -m "foo becomes binary" &&
  37        git branch foo-becomes-binary &&
  38        rm -f foo &&
  39        git update-index --remove foo &&
  40        mkdir foo &&
  41        echo "if only I knew" > foo/baz &&
  42        git update-index --add foo/baz &&
  43        git commit -m "foo becomes a directory" &&
  44        git branch "foo-becomes-a-directory" &&
  45        echo "hello world" > foo/baz &&
  46        git update-index foo/baz &&
  47        git commit -m "foo/baz is the original foo" &&
  48        git branch foo-baz-renamed-from-foo
  49        '
  50
  51test_expect_success 'file renamed from foo to foo/baz' '
  52        git checkout -f initial &&
  53        git diff-tree -M -p HEAD foo-baz-renamed-from-foo > patch &&
  54        git apply --index < patch
  55        '
  56test_debug 'cat patch'
  57
  58
  59test_expect_success 'file renamed from foo/baz to foo' '
  60        git checkout -f foo-baz-renamed-from-foo &&
  61        git diff-tree -M -p HEAD initial > patch &&
  62        git apply --index < patch
  63        '
  64test_debug 'cat patch'
  65
  66
  67test_expect_success 'directory becomes file' '
  68        git checkout -f foo-becomes-a-directory &&
  69        git diff-tree -p HEAD initial > patch &&
  70        git apply --index < patch
  71        '
  72test_debug 'cat patch'
  73
  74
  75test_expect_success 'file becomes directory' '
  76        git checkout -f initial &&
  77        git diff-tree -p HEAD foo-becomes-a-directory > patch &&
  78        git apply --index < patch
  79        '
  80test_debug 'cat patch'
  81
  82
  83test_expect_success 'file becomes symlink' '
  84        git checkout -f initial &&
  85        git diff-tree -p HEAD foo-symlinked-to-bar > patch &&
  86        git apply --index < patch
  87        '
  88test_debug 'cat patch'
  89
  90
  91test_expect_success 'symlink becomes file' '
  92        git checkout -f foo-symlinked-to-bar &&
  93        git diff-tree -p HEAD foo-back-to-file > patch &&
  94        git apply --index < patch
  95        '
  96test_debug 'cat patch'
  97
  98test_expect_success 'binary file becomes symlink' '
  99        git checkout -f foo-becomes-binary &&
 100        git diff-tree -p --binary HEAD foo-symlinked-to-bar > patch &&
 101        git apply --index < patch
 102        '
 103test_debug 'cat patch'
 104
 105test_expect_success 'symlink becomes binary file' '
 106        git checkout -f foo-symlinked-to-bar &&
 107        git diff-tree -p --binary HEAD foo-becomes-binary > patch &&
 108        git apply --index < patch
 109        '
 110test_debug 'cat patch'
 111
 112
 113test_expect_success 'symlink becomes directory' '
 114        git checkout -f foo-symlinked-to-bar &&
 115        git diff-tree -p HEAD foo-becomes-a-directory > patch &&
 116        git apply --index < patch
 117        '
 118test_debug 'cat patch'
 119
 120
 121test_expect_success 'directory becomes symlink' '
 122        git checkout -f foo-becomes-a-directory &&
 123        git diff-tree -p HEAD foo-symlinked-to-bar > patch &&
 124        git apply --index < patch
 125        '
 126test_debug 'cat patch'
 127
 128
 129test_done