t / t4122-apply-symlink-inside.shon commit t0001: don't let a default ACL interfere with the umask test (d549d21)
   1#!/bin/sh
   2
   3test_description='apply to deeper directory without getting fooled with symlink'
   4. ./test-lib.sh
   5
   6test_expect_success setup '
   7
   8        mkdir -p arch/i386/boot arch/x86_64 &&
   9        test_write_lines 1 2 3 4 5 >arch/i386/boot/Makefile &&
  10        test_ln_s_add ../i386/boot arch/x86_64/boot &&
  11        git add . &&
  12        test_tick &&
  13        git commit -m initial &&
  14        git branch test &&
  15
  16        rm arch/x86_64/boot &&
  17        mkdir arch/x86_64/boot &&
  18        test_write_lines 2 3 4 5 6 >arch/x86_64/boot/Makefile &&
  19        git add . &&
  20        test_tick &&
  21        git commit -a -m second &&
  22
  23        git format-patch --binary -1 --stdout >test.patch
  24
  25'
  26
  27test_expect_success apply '
  28
  29        git checkout test &&
  30        git diff --exit-code test &&
  31        git diff --exit-code --cached test &&
  32        git apply --index test.patch
  33
  34'
  35
  36test_expect_success 'check result' '
  37
  38        git diff --exit-code master &&
  39        git diff --exit-code --cached master &&
  40        test_tick &&
  41        git commit -m replay &&
  42        T1=$(git rev-parse "master^{tree}") &&
  43        T2=$(git rev-parse "HEAD^{tree}") &&
  44        test "z$T1" = "z$T2"
  45
  46'
  47
  48test_expect_success SYMLINKS 'do not read from beyond symbolic link' '
  49        git reset --hard &&
  50        mkdir -p arch/x86_64/dir &&
  51        >arch/x86_64/dir/file &&
  52        git add arch/x86_64/dir/file &&
  53        echo line >arch/x86_64/dir/file &&
  54        git diff >patch &&
  55        git reset --hard &&
  56
  57        mkdir arch/i386/dir &&
  58        >arch/i386/dir/file &&
  59        ln -s ../i386/dir arch/x86_64/dir &&
  60
  61        test_must_fail git apply patch &&
  62        test_must_fail git apply --cached patch &&
  63        test_must_fail git apply --index patch
  64
  65'
  66
  67test_expect_success SYMLINKS 'do not follow symbolic link (setup)' '
  68
  69        rm -rf arch/i386/dir arch/x86_64/dir &&
  70        git reset --hard &&
  71        ln -s ../i386/dir arch/x86_64/dir &&
  72        git add arch/x86_64/dir &&
  73        git diff HEAD >add_symlink.patch &&
  74        git reset --hard &&
  75
  76        mkdir arch/x86_64/dir &&
  77        >arch/x86_64/dir/file &&
  78        git add arch/x86_64/dir/file &&
  79        git diff HEAD >add_file.patch &&
  80        git diff -R HEAD >del_file.patch &&
  81        git reset --hard &&
  82        rm -fr arch/x86_64/dir &&
  83
  84        cat add_symlink.patch add_file.patch >patch &&
  85        cat add_symlink.patch del_file.patch >tricky_del &&
  86
  87        mkdir arch/i386/dir
  88'
  89
  90test_expect_success SYMLINKS 'do not follow symbolic link (same input)' '
  91
  92        # same input creates a confusing symbolic link
  93        test_must_fail git apply patch 2>error-wt &&
  94        test_i18ngrep "beyond a symbolic link" error-wt &&
  95        test_path_is_missing arch/x86_64/dir &&
  96        test_path_is_missing arch/i386/dir/file &&
  97
  98        test_must_fail git apply --index patch 2>error-ix &&
  99        test_i18ngrep "beyond a symbolic link" error-ix &&
 100        test_path_is_missing arch/x86_64/dir &&
 101        test_path_is_missing arch/i386/dir/file &&
 102        test_must_fail git ls-files --error-unmatch arch/x86_64/dir &&
 103        test_must_fail git ls-files --error-unmatch arch/i386/dir &&
 104
 105        test_must_fail git apply --cached patch 2>error-ct &&
 106        test_i18ngrep "beyond a symbolic link" error-ct &&
 107        test_must_fail git ls-files --error-unmatch arch/x86_64/dir &&
 108        test_must_fail git ls-files --error-unmatch arch/i386/dir &&
 109
 110        >arch/i386/dir/file &&
 111        git add arch/i386/dir/file &&
 112
 113        test_must_fail git apply tricky_del &&
 114        test_path_is_file arch/i386/dir/file &&
 115
 116        test_must_fail git apply --index tricky_del &&
 117        test_path_is_file arch/i386/dir/file &&
 118        test_must_fail git ls-files --error-unmatch arch/x86_64/dir &&
 119        git ls-files --error-unmatch arch/i386/dir &&
 120
 121        test_must_fail git apply --cached tricky_del &&
 122        test_must_fail git ls-files --error-unmatch arch/x86_64/dir &&
 123        git ls-files --error-unmatch arch/i386/dir
 124'
 125
 126test_expect_success SYMLINKS 'do not follow symbolic link (existing)' '
 127
 128        # existing symbolic link
 129        git reset --hard &&
 130        ln -s ../i386/dir arch/x86_64/dir &&
 131        git add arch/x86_64/dir &&
 132
 133        test_must_fail git apply add_file.patch 2>error-wt-add &&
 134        test_i18ngrep "beyond a symbolic link" error-wt-add &&
 135        test_path_is_missing arch/i386/dir/file &&
 136
 137        mkdir arch/i386/dir &&
 138        >arch/i386/dir/file &&
 139        test_must_fail git apply del_file.patch 2>error-wt-del &&
 140        test_i18ngrep "beyond a symbolic link" error-wt-del &&
 141        test_path_is_file arch/i386/dir/file &&
 142        rm arch/i386/dir/file &&
 143
 144        test_must_fail git apply --index add_file.patch 2>error-ix-add &&
 145        test_i18ngrep "beyond a symbolic link" error-ix-add &&
 146        test_path_is_missing arch/i386/dir/file &&
 147        test_must_fail git ls-files --error-unmatch arch/i386/dir &&
 148
 149        test_must_fail git apply --cached add_file.patch 2>error-ct-file &&
 150        test_i18ngrep "beyond a symbolic link" error-ct-file &&
 151        test_must_fail git ls-files --error-unmatch arch/i386/dir
 152'
 153
 154test_done