1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5test_description='git apply handling copy/rename patch.
   7'
   9. ./test-lib.sh
  10# setup
  12cat >test-patch <<\EOF
  14diff --git a/foo b/bar
  15similarity index 47%
  16rename from foo
  17rename to bar
  18--- a/foo
  19+++ b/bar
  20@@ -1 +1 @@
  21-This is foo
  22+This is bar
  23EOF
  24echo 'This is foo' >foo
  26chmod +x foo
  27test_expect_success setup \
  29    'git update-index --add foo'
  30test_expect_success apply \
  32    'git apply --index --stat --summary --apply test-patch'
  33if test "$(git config --bool core.filemode)" = false
  35then
  36        say 'filemode disabled on the filesystem'
  37else
  38        test_set_prereq FILEMODE
  39fi
  40test_expect_success FILEMODE validate \
  42            'test -f bar && ls -l bar | grep "^-..x......"'
  43test_expect_success 'apply reverse' \
  45    'git apply -R --index --stat --summary --apply test-patch &&
  46     test "$(cat foo)" = "This is foo"'
  47cat >test-patch <<\EOF
  49diff --git a/foo b/bar
  50similarity index 47%
  51copy from foo
  52copy to bar
  53--- a/foo
  54+++ b/bar
  55@@ -1 +1 @@
  56-This is foo
  57+This is bar
  58EOF
  59test_expect_success 'apply copy' \
  61    'git apply --index --stat --summary --apply test-patch &&
  62     test "$(cat bar)" = "This is bar" -a "$(cat foo)" = "This is foo"'
  63test_done