t / t4120-apply-popt.shon commit difftool: print list of valid tools with '--tool-help' (bf73fc2)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Shawn O. Pearce
   4#
   5
   6test_description='git apply -p handling.'
   7
   8. ./test-lib.sh
   9. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh
  10
  11test_expect_success setup '
  12        mkdir sub &&
  13        echo A >sub/file1 &&
  14        cp sub/file1 file1.saved &&
  15        git add sub/file1 &&
  16        echo B >sub/file1 &&
  17        git diff >patch.file &&
  18        git checkout -- sub/file1 &&
  19        git mv sub süb &&
  20        echo B >süb/file1 &&
  21        git diff >patch.escaped &&
  22        grep "[\]" patch.escaped &&
  23        rm süb/file1 &&
  24        rmdir süb
  25'
  26
  27test_expect_success 'apply git diff with -p2' '
  28        cp file1.saved file1 &&
  29        git apply -p2 patch.file
  30'
  31
  32test_expect_success 'apply with too large -p' '
  33        cp file1.saved file1 &&
  34        test_must_fail git apply --stat -p3 patch.file 2>err &&
  35        grep "removing 3 leading" err
  36'
  37
  38test_expect_success 'apply (-p2) traditional diff with funny filenames' '
  39        cat >patch.quotes <<-\EOF &&
  40        diff -u "a/"sub/file1 "b/"sub/file1
  41        --- "a/"sub/file1
  42        +++ "b/"sub/file1
  43        @@ -1 +1 @@
  44        -A
  45        +B
  46        EOF
  47        echo B >expected &&
  48
  49        cp file1.saved file1 &&
  50        git apply -p2 patch.quotes &&
  51        test_cmp expected file1
  52'
  53
  54test_expect_success 'apply with too large -p and fancy filename' '
  55        cp file1.saved file1 &&
  56        test_must_fail git apply --stat -p3 patch.escaped 2>err &&
  57        grep "removing 3 leading" err
  58'
  59
  60test_expect_success 'apply (-p2) diff, mode change only' '
  61        cat >patch.chmod <<-\EOF &&
  62        diff --git a/sub/file1 b/sub/file1
  63        old mode 100644
  64        new mode 100755
  65        EOF
  66        test_chmod -x file1 &&
  67        git apply --index -p2 patch.chmod &&
  68        case $(git ls-files -s file1) in 100755*) : good;; *) false;; esac
  69'
  70
  71test_expect_success FILEMODE 'file mode was changed' '
  72        test -x file1
  73'
  74
  75test_expect_success 'apply (-p2) diff, rename' '
  76        cat >patch.rename <<-\EOF &&
  77        diff --git a/sub/file1 b/sub/file2
  78        similarity index 100%
  79        rename from sub/file1
  80        rename to sub/file2
  81        EOF
  82        echo A >expected &&
  83
  84        cp file1.saved file1 &&
  85        rm -f file2 &&
  86        git apply -p2 patch.rename &&
  87        test_cmp expected file2
  88'
  89
  90test_done