035c080581d5c10371e95d69d3219c619987c364
   1#!/bin/sh
   2
   3test_description='apply to deeper directory without getting fooled with symlink'
   4. ./test-lib.sh
   5
   6lecho () {
   7        for l_
   8        do
   9                echo "$l_"
  10        done
  11}
  12
  13test_expect_success setup '
  14
  15        mkdir -p arch/i386/boot arch/x86_64 &&
  16        lecho 1 2 3 4 5 >arch/i386/boot/Makefile &&
  17        test_ln_s_add ../i386/boot arch/x86_64/boot &&
  18        git add . &&
  19        test_tick &&
  20        git commit -m initial &&
  21        git branch test &&
  22
  23        rm arch/x86_64/boot &&
  24        mkdir arch/x86_64/boot &&
  25        lecho 2 3 4 5 6 >arch/x86_64/boot/Makefile &&
  26        git add . &&
  27        test_tick &&
  28        git commit -a -m second &&
  29
  30        git format-patch --binary -1 --stdout >test.patch
  31
  32'
  33
  34test_expect_success apply '
  35
  36        git checkout test &&
  37        git diff --exit-code test &&
  38        git diff --exit-code --cached test &&
  39        git apply --index test.patch
  40
  41'
  42
  43test_expect_success 'check result' '
  44
  45        git diff --exit-code master &&
  46        git diff --exit-code --cached master &&
  47        test_tick &&
  48        git commit -m replay &&
  49        T1=$(git rev-parse "master^{tree}") &&
  50        T2=$(git rev-parse "HEAD^{tree}") &&
  51        test "z$T1" = "z$T2"
  52
  53'
  54
  55test_expect_success SYMLINKS 'do not read from beyond symbolic link' '
  56        git reset --hard &&
  57        mkdir -p arch/x86_64/dir &&
  58        >arch/x86_64/dir/file &&
  59        git add arch/x86_64/dir/file &&
  60        echo line >arch/x86_64/dir/file &&
  61        git diff >patch &&
  62        git reset --hard &&
  63
  64        mkdir arch/i386/dir &&
  65        >arch/i386/dir/file &&
  66        ln -s ../i386/dir arch/x86_64/dir &&
  67
  68        test_must_fail git apply patch &&
  69        test_must_fail git apply --cached patch &&
  70        test_must_fail git apply --index patch
  71
  72'
  73
  74test_done