blob: d42abff1ad59343fa1c84bded9a82c3212370da0 [file] [log] [blame]
Johannes Schindelin35cc4bc2005-08-17 09:01:07 +02001#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
Junio C Hamano5be60072007-07-02 22:52:14 -07006test_description='git apply handling copy/rename patch.
Johannes Schindelin35cc4bc2005-08-17 09:01:07 +02007
8'
9. ./test-lib.sh
10
11# setup
12
13cat >test-patch <<\EOF
14diff --git a/foo b/bar
15similarity index 47%
Johannes Schindeline5a94312006-07-28 17:46:11 +020016rename from foo
17rename to bar
Johannes Schindelin35cc4bc2005-08-17 09:01:07 +020018--- a/foo
19+++ b/bar
20@@ -1 +1 @@
21-This is foo
22+This is bar
23EOF
24
25echo 'This is foo' >foo
26chmod +x foo
27
28test_expect_success setup \
Junio C Hamano5be60072007-07-02 22:52:14 -070029 'git update-index --add foo'
Johannes Schindelin35cc4bc2005-08-17 09:01:07 +020030
31test_expect_success apply \
Junio C Hamano5be60072007-07-02 22:52:14 -070032 'git apply --index --stat --summary --apply test-patch'
Johannes Schindelin35cc4bc2005-08-17 09:01:07 +020033
Tom Princee0d10e12007-01-28 16:16:53 -080034if [ "$(git config --get core.filemode)" = false ]
Alex Riesenb484ef22006-01-05 12:55:58 +010035then
36 say 'filemode disabled on the filesystem'
37else
38 test_expect_success validate \
39 'test -f bar && ls -l bar | grep "^-..x......"'
40fi
Johannes Schindelin35cc4bc2005-08-17 09:01:07 +020041
Johannes Schindeline5a94312006-07-28 17:46:11 +020042test_expect_success 'apply reverse' \
Junio C Hamano5be60072007-07-02 22:52:14 -070043 'git apply -R --index --stat --summary --apply test-patch &&
Johannes Schindeline5a94312006-07-28 17:46:11 +020044 test "$(cat foo)" = "This is foo"'
45
46cat >test-patch <<\EOF
47diff --git a/foo b/bar
48similarity index 47%
49copy from foo
50copy to bar
51--- a/foo
52+++ b/bar
53@@ -1 +1 @@
54-This is foo
55+This is bar
56EOF
57
58test_expect_success 'apply copy' \
Junio C Hamano5be60072007-07-02 22:52:14 -070059 'git apply --index --stat --summary --apply test-patch &&
Johannes Schindeline5a94312006-07-28 17:46:11 +020060 test "$(cat bar)" = "This is bar" -a "$(cat foo)" = "This is foo"'
61
Johannes Schindelin35cc4bc2005-08-17 09:01:07 +020062test_done