summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-06-30 20:45:24 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-06-30 20:45:24 (GMT)
commit53ee6b8f1a2d7445db914e692bdf9eb2ec0cc780 (patch)
tree7f7762e0c7e9b2f337ec2bd22309429c5b181eb4 /t
parentca069a3c5ce86303865cf49260ab8f4ff758d1d8 (diff)
parentd70e9c5c8c865626b6e69c2bf9fd0e368543617b (diff)
downloadgit-53ee6b8f1a2d7445db914e692bdf9eb2ec0cc780.zip
git-53ee6b8f1a2d7445db914e692bdf9eb2ec0cc780.tar.gz
git-53ee6b8f1a2d7445db914e692bdf9eb2ec0cc780.tar.bz2
Merge branch 'rs/apply-validate-input'
Tighten error checks for invalid "git apply" input. * rs/apply-validate-input: apply: check git diffs for mutually exclusive header lines apply: check git diffs for invalid file modes apply: check git diffs for missing old filenames
Diffstat (limited to 't')
-rwxr-xr-xt/t4129-apply-samemode.sh16
-rwxr-xr-xt/t4133-apply-filenames.sh24
-rwxr-xr-xt/t4136-apply-check.sh18
3 files changed, 57 insertions, 1 deletions
diff --git a/t/t4129-apply-samemode.sh b/t/t4129-apply-samemode.sh
index c268298..5cdd76d 100755
--- a/t/t4129-apply-samemode.sh
+++ b/t/t4129-apply-samemode.sh
@@ -13,7 +13,9 @@ test_expect_success setup '
echo modified >file &&
git diff --stat -p >patch-0.txt &&
chmod +x file &&
- git diff --stat -p >patch-1.txt
+ git diff --stat -p >patch-1.txt &&
+ sed "s/^\(new mode \).*/\1/" <patch-1.txt >patch-empty-mode.txt &&
+ sed "s/^\(new mode \).*/\1garbage/" <patch-1.txt >patch-bogus-mode.txt
'
test_expect_success FILEMODE 'same mode (no index)' '
@@ -59,4 +61,16 @@ test_expect_success FILEMODE 'mode update (index only)' '
git ls-files -s file | grep "^100755"
'
+test_expect_success FILEMODE 'empty mode is rejected' '
+ git reset --hard &&
+ test_must_fail git apply patch-empty-mode.txt 2>err &&
+ test_i18ngrep "invalid mode" err
+'
+
+test_expect_success FILEMODE 'bogus mode is rejected' '
+ git reset --hard &&
+ test_must_fail git apply patch-bogus-mode.txt 2>err &&
+ test_i18ngrep "invalid mode" err
+'
+
test_done
diff --git a/t/t4133-apply-filenames.sh b/t/t4133-apply-filenames.sh
index 2ecb421..c5ed3b1 100755
--- a/t/t4133-apply-filenames.sh
+++ b/t/t4133-apply-filenames.sh
@@ -35,4 +35,28 @@ test_expect_success 'apply diff with inconsistent filenames in headers' '
test_i18ngrep "inconsistent old filename" err
'
+test_expect_success 'apply diff with new filename missing from headers' '
+ cat >missing_new_filename.diff <<-\EOF &&
+ diff --git a/f b/f
+ index 0000000..d00491f
+ --- a/f
+ @@ -0,0 +1 @@
+ +1
+ EOF
+ test_must_fail git apply missing_new_filename.diff 2>err &&
+ test_i18ngrep "lacks filename information" err
+'
+
+test_expect_success 'apply diff with old filename missing from headers' '
+ cat >missing_old_filename.diff <<-\EOF &&
+ diff --git a/f b/f
+ index d00491f..0000000
+ +++ b/f
+ @@ -1 +0,0 @@
+ -1
+ EOF
+ test_must_fail git apply missing_old_filename.diff 2>err &&
+ test_i18ngrep "lacks filename information" err
+'
+
test_done
diff --git a/t/t4136-apply-check.sh b/t/t4136-apply-check.sh
index 4b0a374..6d92872 100755
--- a/t/t4136-apply-check.sh
+++ b/t/t4136-apply-check.sh
@@ -29,4 +29,22 @@ test_expect_success 'apply exits non-zero with no-op patch' '
test_must_fail git apply --check input
'
+test_expect_success 'invalid combination: create and copy' '
+ test_must_fail git apply --check - <<-\EOF
+ diff --git a/1 b/2
+ new file mode 100644
+ copy from 1
+ copy to 2
+ EOF
+'
+
+test_expect_success 'invalid combination: create and rename' '
+ test_must_fail git apply --check - <<-\EOF
+ diff --git a/1 b/2
+ new file mode 100644
+ rename from 1
+ rename to 2
+ EOF
+'
+
test_done