t / t4111-apply-subdir.shon commit tests: try git apply from subdir of toplevel (9f41a91)
   1#!/bin/sh
   2
   3test_description='patching from inconvenient places'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'setup' '
   8        cat >patch <<-\EOF &&
   9        diff file.orig file
  10        --- a/file.orig
  11        +++ b/file
  12        @@ -1 +1,2 @@
  13         1
  14        +2
  15        EOF
  16        patch="$(pwd)/patch" &&
  17
  18        echo 1 >preimage &&
  19        printf "%s\n" 1 2 >postimage &&
  20        echo 3 >other &&
  21
  22        test_tick &&
  23        git commit --allow-empty -m basis
  24'
  25
  26test_expect_success 'setup: subdir' '
  27        reset_subdir() {
  28                git reset &&
  29                mkdir -p sub/dir/b &&
  30                mkdir -p objects &&
  31                cp "$1" file &&
  32                cp "$1" objects/file &&
  33                cp "$1" sub/dir/file &&
  34                cp "$1" sub/dir/b/file &&
  35                git add file sub/dir/file sub/dir/b/file objects/file &&
  36                cp "$2" file &&
  37                cp "$2" sub/dir/file &&
  38                cp "$2" sub/dir/b/file &&
  39                cp "$2" objects/file
  40        }
  41'
  42
  43test_expect_success 'apply from subdir of toplevel' '
  44        cp postimage expected &&
  45        reset_subdir other preimage &&
  46        (
  47                cd sub/dir &&
  48                git apply "$patch"
  49        ) &&
  50        test_cmp expected sub/dir/file
  51'
  52
  53test_expect_success 'apply --cached from subdir of toplevel' '
  54        cp postimage expected &&
  55        cp other expected.working &&
  56        reset_subdir preimage other &&
  57        (
  58                cd sub/dir &&
  59                git apply --cached "$patch"
  60        ) &&
  61        git show :sub/dir/file >actual &&
  62        test_cmp expected actual &&
  63        test_cmp expected.working sub/dir/file
  64'
  65
  66test_expect_success 'apply --index from subdir of toplevel' '
  67        cp postimage expected &&
  68        reset_subdir preimage other &&
  69        (
  70                cd sub/dir &&
  71                test_must_fail git apply --index "$patch"
  72        ) &&
  73        reset_subdir other preimage &&
  74        (
  75                cd sub/dir &&
  76                test_must_fail git apply --index "$patch"
  77        ) &&
  78        reset_subdir preimage preimage &&
  79        (
  80                cd sub/dir &&
  81                git apply --index "$patch"
  82        ) &&
  83        git show :sub/dir/file >actual &&
  84        test_cmp expected actual &&
  85        test_cmp expected sub/dir/file
  86'
  87
  88test_expect_success 'apply from .git dir' '
  89        cp postimage expected &&
  90        cp preimage .git/file &&
  91        cp preimage .git/objects/file
  92        (
  93                cd .git &&
  94                git apply "$patch"
  95        ) &&
  96        test_cmp expected .git/file
  97'
  98
  99test_expect_failure 'apply from subdir of .git dir' '
 100        cp postimage expected &&
 101        cp preimage .git/file &&
 102        cp preimage .git/objects/file
 103        (
 104                cd .git/objects &&
 105                git apply "$patch"
 106        ) &&
 107        test_cmp expected .git/objects/file
 108'
 109
 110test_expect_success 'apply --cached from .git dir' '
 111        cp postimage expected &&
 112        cp other expected.working &&
 113        cp other .git/file &&
 114        reset_subdir preimage other &&
 115        (
 116                cd .git &&
 117                git apply --cached "$patch"
 118        ) &&
 119        git show :file >actual &&
 120        test_cmp expected actual &&
 121        test_cmp expected.working file &&
 122        test_cmp expected.working .git/file
 123'
 124
 125test_expect_success 'apply --cached from subdir of .git dir' '
 126        cp postimage expected &&
 127        cp preimage expected.subdir &&
 128        cp other .git/file &&
 129        cp other .git/objects/file &&
 130        reset_subdir preimage other &&
 131        (
 132                cd .git/objects &&
 133                git apply --cached "$patch"
 134        ) &&
 135        git show :file >actual &&
 136        git show :objects/file >actual.subdir &&
 137        test_cmp expected actual &&
 138        test_cmp expected.subdir actual.subdir
 139'
 140
 141test_done