Junio C Hamano | acb4441 | 2007-01-14 22:00:02 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test cherry-pick and revert with renames |
| 4 | |
| 5 | -- |
| 6 | + rename2: renames oops to opos |
| 7 | + rename1: renames oops to spoo |
| 8 | + added: adds extra line to oops |
| 9 | ++ initial: has lines in oops |
| 10 | |
| 11 | ' |
| 12 | |
| 13 | . ./test-lib.sh |
| 14 | |
| 15 | test_expect_success setup ' |
| 16 | |
| 17 | for l in a b c d e f g h i j k l m n o |
| 18 | do |
| 19 | echo $l$l$l$l$l$l$l$l$l |
| 20 | done >oops && |
| 21 | |
| 22 | test_tick && |
| 23 | git add oops && |
| 24 | git commit -m initial && |
| 25 | git tag initial && |
| 26 | |
| 27 | test_tick && |
| 28 | echo "Add extra line at the end" >>oops && |
| 29 | git commit -a -m added && |
| 30 | git tag added && |
| 31 | |
| 32 | test_tick && |
| 33 | git mv oops spoo && |
| 34 | git commit -m rename1 && |
| 35 | git tag rename1 && |
| 36 | |
| 37 | test_tick && |
| 38 | git checkout -b side initial && |
| 39 | git mv oops opos && |
| 40 | git commit -m rename2 && |
| 41 | git tag rename2 |
| 42 | ' |
| 43 | |
Jonathan Nieder | e0ef849 | 2010-06-14 00:32:09 -0500 | [diff] [blame] | 44 | test_expect_success 'cherry-pick --nonsense' ' |
| 45 | |
| 46 | pos=$(git rev-parse HEAD) && |
| 47 | git diff --exit-code HEAD && |
| 48 | test_must_fail git cherry-pick --nonsense 2>msg && |
| 49 | git diff --exit-code HEAD "$pos" && |
Jiang Xin | 9a00138 | 2012-08-27 13:36:55 +0800 | [diff] [blame] | 50 | test_i18ngrep '[Uu]sage:' msg |
Jonathan Nieder | e0ef849 | 2010-06-14 00:32:09 -0500 | [diff] [blame] | 51 | ' |
| 52 | |
| 53 | test_expect_success 'revert --nonsense' ' |
| 54 | |
| 55 | pos=$(git rev-parse HEAD) && |
| 56 | git diff --exit-code HEAD && |
| 57 | test_must_fail git revert --nonsense 2>msg && |
| 58 | git diff --exit-code HEAD "$pos" && |
Jiang Xin | 9a00138 | 2012-08-27 13:36:55 +0800 | [diff] [blame] | 59 | test_i18ngrep '[Uu]sage:' msg |
Jonathan Nieder | e0ef849 | 2010-06-14 00:32:09 -0500 | [diff] [blame] | 60 | ' |
| 61 | |
Junio C Hamano | acb4441 | 2007-01-14 22:00:02 -0800 | [diff] [blame] | 62 | test_expect_success 'cherry-pick after renaming branch' ' |
| 63 | |
| 64 | git checkout rename2 && |
Kristian Høgsberg | 9e54dc6 | 2007-11-02 11:33:07 -0400 | [diff] [blame] | 65 | git cherry-pick added && |
Stephan Beyer | 944019c | 2009-01-15 14:03:17 +0100 | [diff] [blame] | 66 | test $(git rev-parse HEAD^) = $(git rev-parse rename2) && |
Junio C Hamano | acb4441 | 2007-01-14 22:00:02 -0800 | [diff] [blame] | 67 | test -f opos && |
Christian Couder | 643cb5f | 2010-06-12 18:05:12 +0200 | [diff] [blame] | 68 | grep "Add extra line at the end" opos && |
| 69 | git reflog -1 | grep cherry-pick |
Junio C Hamano | acb4441 | 2007-01-14 22:00:02 -0800 | [diff] [blame] | 70 | |
| 71 | ' |
| 72 | |
| 73 | test_expect_success 'revert after renaming branch' ' |
| 74 | |
| 75 | git checkout rename1 && |
Kristian Høgsberg | 9e54dc6 | 2007-11-02 11:33:07 -0400 | [diff] [blame] | 76 | git revert added && |
Stephan Beyer | 944019c | 2009-01-15 14:03:17 +0100 | [diff] [blame] | 77 | test $(git rev-parse HEAD^) = $(git rev-parse rename1) && |
Junio C Hamano | acb4441 | 2007-01-14 22:00:02 -0800 | [diff] [blame] | 78 | test -f spoo && |
Christian Couder | 643cb5f | 2010-06-12 18:05:12 +0200 | [diff] [blame] | 79 | ! grep "Add extra line at the end" spoo && |
| 80 | git reflog -1 | grep revert |
Junio C Hamano | acb4441 | 2007-01-14 22:00:02 -0800 | [diff] [blame] | 81 | |
| 82 | ' |
| 83 | |
Jonathan Nieder | f6ce1f2 | 2010-10-31 14:59:33 -0500 | [diff] [blame] | 84 | test_expect_success 'cherry-pick on stat-dirty working tree' ' |
| 85 | git clone . copy && |
| 86 | ( |
| 87 | cd copy && |
| 88 | git checkout initial && |
| 89 | test-chmtime +40 oops && |
| 90 | git cherry-pick added |
| 91 | ) |
| 92 | ' |
| 93 | |
Junio C Hamano | fff1bb3 | 2011-04-12 16:23:01 -0700 | [diff] [blame] | 94 | test_expect_success 'revert forbidden on dirty working tree' ' |
Jeff King | 0f2d447 | 2008-03-03 01:30:56 -0500 | [diff] [blame] | 95 | |
| 96 | echo content >extra_file && |
| 97 | git add extra_file && |
| 98 | test_must_fail git revert HEAD 2>errors && |
Junio C Hamano | fff1bb3 | 2011-04-12 16:23:01 -0700 | [diff] [blame] | 99 | test_i18ngrep "Your local changes would be overwritten by " errors |
Jeff King | 0f2d447 | 2008-03-03 01:30:56 -0500 | [diff] [blame] | 100 | |
| 101 | ' |
| 102 | |
Junio C Hamano | 7a96c38 | 2013-09-05 14:51:17 -0700 | [diff] [blame] | 103 | test_expect_success 'cherry-pick on unborn branch' ' |
Martin von Zweigbergk | 334ae39 | 2012-12-21 11:10:11 -0800 | [diff] [blame] | 104 | git checkout --orphan unborn && |
| 105 | git rm --cached -r . && |
| 106 | rm -rf * && |
| 107 | git cherry-pick initial && |
| 108 | git diff --quiet initial && |
| 109 | ! test_cmp_rev initial HEAD |
| 110 | ' |
| 111 | |
Hiroshige Umino | 182d7dc | 2013-09-05 23:57:23 +0900 | [diff] [blame] | 112 | test_expect_success 'cherry-pick "-" to pick from previous branch' ' |
| 113 | git checkout unborn && |
| 114 | test_commit to-pick actual content && |
| 115 | git checkout master && |
| 116 | git cherry-pick - && |
| 117 | echo content >expect && |
| 118 | test_cmp expect actual |
| 119 | ' |
| 120 | |
| 121 | test_expect_success 'cherry-pick "-" is meaningless without checkout' ' |
| 122 | test_create_repo afresh && |
| 123 | ( |
| 124 | cd afresh && |
| 125 | test_commit one && |
| 126 | test_commit two && |
| 127 | test_commit three && |
| 128 | test_must_fail git cherry-pick - |
| 129 | ) |
| 130 | ' |
| 131 | |
Jeff King | d644c55 | 2013-10-10 12:41:17 -0400 | [diff] [blame] | 132 | test_expect_success 'cherry-pick "-" works with arguments' ' |
| 133 | git checkout -b side-branch && |
| 134 | test_commit change actual change && |
| 135 | git checkout master && |
| 136 | git cherry-pick -s - && |
| 137 | echo "Signed-off-by: C O Mitter <committer@example.com>" >expect && |
| 138 | git cat-file commit HEAD | grep ^Signed-off-by: >signoff && |
| 139 | test_cmp expect signoff && |
| 140 | echo change >expect && |
| 141 | test_cmp expect actual |
| 142 | ' |
| 143 | |
Junio C Hamano | acb4441 | 2007-01-14 22:00:02 -0800 | [diff] [blame] | 144 | test_done |