Johannes Schindelin | c4730f3 | 2008-07-01 00:44:47 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='apply same filename' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success 'setup' ' |
| 8 | |
| 9 | mkdir -p some/sub/dir && |
| 10 | echo Hello > some/sub/dir/file && |
Junio C Hamano | 8ee4a6c | 2008-07-02 15:28:22 -0700 | [diff] [blame] | 11 | git add some/sub/dir/file && |
| 12 | git commit -m initial && |
| 13 | git tag initial |
Johannes Schindelin | c4730f3 | 2008-07-01 00:44:47 +0100 | [diff] [blame] | 14 | |
| 15 | ' |
| 16 | |
| 17 | cat > patch << EOF |
| 18 | diff a/bla/blub/dir/file b/bla/blub/dir/file |
| 19 | --- a/bla/blub/dir/file |
| 20 | +++ b/bla/blub/dir/file |
| 21 | @@ -1,1 +1,1 @@ |
| 22 | -Hello |
| 23 | +Bello |
| 24 | EOF |
| 25 | |
Junio C Hamano | f556388 | 2008-07-06 18:36:01 -0700 | [diff] [blame] | 26 | test_expect_success 'apply --directory -p (1)' ' |
Johannes Schindelin | c4730f3 | 2008-07-01 00:44:47 +0100 | [diff] [blame] | 27 | |
Junio C Hamano | f556388 | 2008-07-06 18:36:01 -0700 | [diff] [blame] | 28 | git apply --directory=some/sub -p3 --index patch && |
Johannes Schindelin | c4730f3 | 2008-07-01 00:44:47 +0100 | [diff] [blame] | 29 | test Bello = $(git show :some/sub/dir/file) && |
| 30 | test Bello = $(cat some/sub/dir/file) |
| 31 | |
| 32 | ' |
| 33 | |
Junio C Hamano | f556388 | 2008-07-06 18:36:01 -0700 | [diff] [blame] | 34 | test_expect_success 'apply --directory -p (2) ' ' |
Junio C Hamano | 8ee4a6c | 2008-07-02 15:28:22 -0700 | [diff] [blame] | 35 | |
| 36 | git reset --hard initial && |
Junio C Hamano | f556388 | 2008-07-06 18:36:01 -0700 | [diff] [blame] | 37 | git apply --directory=some/sub/ -p3 --index patch && |
Junio C Hamano | 8ee4a6c | 2008-07-02 15:28:22 -0700 | [diff] [blame] | 38 | test Bello = $(git show :some/sub/dir/file) && |
| 39 | test Bello = $(cat some/sub/dir/file) |
| 40 | |
| 41 | ' |
| 42 | |
Jeff King | 969c877 | 2008-10-12 00:06:11 -0400 | [diff] [blame] | 43 | cat > patch << EOF |
| 44 | diff --git a/newfile b/newfile |
| 45 | new file mode 100644 |
| 46 | index 0000000..d95f3ad |
| 47 | --- /dev/null |
| 48 | +++ b/newfile |
| 49 | @@ -0,0 +1 @@ |
| 50 | +content |
| 51 | EOF |
| 52 | |
| 53 | test_expect_success 'apply --directory (new file)' ' |
| 54 | git reset --hard initial && |
| 55 | git apply --directory=some/sub/dir/ --index patch && |
| 56 | test content = $(git show :some/sub/dir/newfile) && |
| 57 | test content = $(cat some/sub/dir/newfile) |
| 58 | ' |
| 59 | |
| 60 | cat > patch << EOF |
Junio C Hamano | ec7fc0b | 2009-11-25 02:56:54 -0800 | [diff] [blame] | 61 | diff --git a/c/newfile2 b/c/newfile2 |
| 62 | new file mode 100644 |
| 63 | index 0000000..d95f3ad |
| 64 | --- /dev/null |
| 65 | +++ b/c/newfile2 |
| 66 | @@ -0,0 +1 @@ |
| 67 | +content |
| 68 | EOF |
| 69 | |
| 70 | test_expect_success 'apply --directory -p (new file)' ' |
| 71 | git reset --hard initial && |
| 72 | git apply -p2 --directory=some/sub/dir/ --index patch && |
| 73 | test content = $(git show :some/sub/dir/newfile2) && |
| 74 | test content = $(cat some/sub/dir/newfile2) |
| 75 | ' |
| 76 | |
| 77 | cat > patch << EOF |
Jeff King | 969c877 | 2008-10-12 00:06:11 -0400 | [diff] [blame] | 78 | diff --git a/delfile b/delfile |
| 79 | deleted file mode 100644 |
| 80 | index d95f3ad..0000000 |
| 81 | --- a/delfile |
| 82 | +++ /dev/null |
| 83 | @@ -1 +0,0 @@ |
| 84 | -content |
| 85 | EOF |
| 86 | |
| 87 | test_expect_success 'apply --directory (delete file)' ' |
| 88 | git reset --hard initial && |
| 89 | echo content >some/sub/dir/delfile && |
| 90 | git add some/sub/dir/delfile && |
| 91 | git apply --directory=some/sub/dir/ --index patch && |
Jeff King | 80bfd76 | 2008-10-13 05:35:59 -0400 | [diff] [blame] | 92 | ! (git ls-files | grep delfile) |
Jeff King | 969c877 | 2008-10-12 00:06:11 -0400 | [diff] [blame] | 93 | ' |
| 94 | |
| 95 | cat > patch << 'EOF' |
| 96 | diff --git "a/qu\157tefile" "b/qu\157tefile" |
| 97 | new file mode 100644 |
| 98 | index 0000000..d95f3ad |
| 99 | --- /dev/null |
| 100 | +++ "b/qu\157tefile" |
| 101 | @@ -0,0 +1 @@ |
| 102 | +content |
| 103 | EOF |
| 104 | |
| 105 | test_expect_success 'apply --directory (quoted filename)' ' |
| 106 | git reset --hard initial && |
| 107 | git apply --directory=some/sub/dir/ --index patch && |
| 108 | test content = $(git show :some/sub/dir/quotefile) && |
| 109 | test content = $(cat some/sub/dir/quotefile) |
| 110 | ' |
| 111 | |
Johannes Schindelin | c4730f3 | 2008-07-01 00:44:47 +0100 | [diff] [blame] | 112 | test_done |