t / t4111-apply-subdir.shon commit Merge branch 'dk/send-email-avoid-net-smtp-ssl-when-able' into maint (f381e42)
   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                test_might_fail git update-index --refresh -q
  41        }
  42'
  43
  44test_expect_success 'apply from subdir of toplevel' '
  45        cp postimage expected &&
  46        reset_subdir other preimage &&
  47        (
  48                cd sub/dir &&
  49                git apply "$patch"
  50        ) &&
  51        test_cmp expected sub/dir/file
  52'
  53
  54test_expect_success 'apply --cached from subdir of toplevel' '
  55        cp postimage expected &&
  56        cp other expected.working &&
  57        reset_subdir preimage other &&
  58        (
  59                cd sub/dir &&
  60                git apply --cached "$patch"
  61        ) &&
  62        git show :sub/dir/file >actual &&
  63        test_cmp expected actual &&
  64        test_cmp expected.working sub/dir/file
  65'
  66
  67test_expect_success 'apply --index from subdir of toplevel' '
  68        cp postimage expected &&
  69        reset_subdir preimage other &&
  70        (
  71                cd sub/dir &&
  72                test_must_fail git apply --index "$patch"
  73        ) &&
  74        reset_subdir other preimage &&
  75        (
  76                cd sub/dir &&
  77                test_must_fail git apply --index "$patch"
  78        ) &&
  79        reset_subdir preimage preimage &&
  80        (
  81                cd sub/dir &&
  82                git apply --index "$patch"
  83        ) &&
  84        git show :sub/dir/file >actual &&
  85        test_cmp expected actual &&
  86        test_cmp expected sub/dir/file
  87'
  88
  89test_expect_success 'apply half-broken patch from subdir of toplevel' '
  90        (
  91                cd sub/dir &&
  92                test_must_fail git apply <<-EOF
  93                --- sub/dir/file
  94                +++ sub/dir/file
  95                @@ -1,0 +1,0 @@
  96                --- file_in_root
  97                +++ file_in_root
  98                @@ -1,0 +1,0 @@
  99                EOF
 100        )
 101'
 102
 103test_expect_success 'apply from .git dir' '
 104        cp postimage expected &&
 105        cp preimage .git/file &&
 106        cp preimage .git/objects/file &&
 107        (
 108                cd .git &&
 109                git apply "$patch"
 110        ) &&
 111        test_cmp expected .git/file
 112'
 113
 114test_expect_success 'apply from subdir of .git dir' '
 115        cp postimage expected &&
 116        cp preimage .git/file &&
 117        cp preimage .git/objects/file &&
 118        (
 119                cd .git/objects &&
 120                git apply "$patch"
 121        ) &&
 122        test_cmp expected .git/objects/file
 123'
 124
 125test_expect_success 'apply --cached from .git dir' '
 126        cp postimage expected &&
 127        cp other expected.working &&
 128        cp other .git/file &&
 129        reset_subdir preimage other &&
 130        (
 131                cd .git &&
 132                git apply --cached "$patch"
 133        ) &&
 134        git show :file >actual &&
 135        test_cmp expected actual &&
 136        test_cmp expected.working file &&
 137        test_cmp expected.working .git/file
 138'
 139
 140test_expect_success 'apply --cached from subdir of .git dir' '
 141        cp postimage expected &&
 142        cp preimage expected.subdir &&
 143        cp other .git/file &&
 144        cp other .git/objects/file &&
 145        reset_subdir preimage other &&
 146        (
 147                cd .git/objects &&
 148                git apply --cached "$patch"
 149        ) &&
 150        git show :file >actual &&
 151        git show :objects/file >actual.subdir &&
 152        test_cmp expected actual &&
 153        test_cmp expected.subdir actual.subdir
 154'
 155
 156test_done