t3508-cherry-pick-many-commits.sh 4.6 KB
Newer Older
1 2 3 4 5 6
#!/bin/sh

test_description='test cherry-picking many commits'

. ./test-lib.sh

7
check_head_differs_from() {
8
	! test_cmp_rev HEAD "$1"
9 10 11
}

check_head_equals() {
12
	test_cmp_rev HEAD "$1"
13 14
}

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
test_expect_success setup '
	echo first > file1 &&
	git add file1 &&
	test_tick &&
	git commit -m "first" &&
	git tag first &&

	git checkout -b other &&
	for val in second third fourth
	do
		echo $val >> file1 &&
		git add file1 &&
		test_tick &&
		git commit -m "$val" &&
		git tag $val
	done
'

test_expect_success 'cherry-pick first..fourth works' '
34 35 36 37 38 39 40 41 42
	git checkout -f master &&
	git reset --hard first &&
	test_tick &&
	git cherry-pick first..fourth &&
	git diff --quiet other &&
	git diff --quiet HEAD other &&
	check_head_differs_from fourth
'

43
test_expect_success 'cherry-pick three one two works' '
44 45 46 47 48 49 50 51 52 53 54 55 56 57
	git checkout -f first &&
	test_commit one &&
	test_commit two &&
	test_commit three &&
	git checkout -f master &&
	git reset --hard first &&
	git cherry-pick three one two &&
	git diff --quiet three &&
	git diff --quiet HEAD three &&
	test "$(git log --reverse --format=%s first..)" = "three
one
two"
'

58 59 60 61 62 63
test_expect_success 'cherry-pick three one two: fails' '
	git checkout -f master &&
	git reset --hard first &&
	test_must_fail git cherry-pick three one two:
'

64
test_expect_success 'output to keep user entertained during multi-pick' '
65 66 67
	cat <<-\EOF >expected &&
	[master OBJID] second
	 Author: A U Thor <author@example.com>
68
	 1 file changed, 1 insertion(+)
69 70
	[master OBJID] third
	 Author: A U Thor <author@example.com>
71
	 1 file changed, 1 insertion(+)
72 73
	[master OBJID] fourth
	 Author: A U Thor <author@example.com>
74
	 1 file changed, 1 insertion(+)
75 76 77 78 79
	EOF

	git checkout -f master &&
	git reset --hard first &&
	test_tick &&
80
	git cherry-pick first..fourth >actual &&
81 82 83 84 85 86 87 88 89 90
	sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
	test_line_count -ge 3 actual.fuzzy &&
	test_i18ncmp expected actual.fuzzy
'

test_expect_success 'cherry-pick --strategy resolve first..fourth works' '
	git checkout -f master &&
	git reset --hard first &&
	test_tick &&
	git cherry-pick --strategy resolve first..fourth &&
91 92
	git diff --quiet other &&
	git diff --quiet HEAD other &&
93
	check_head_differs_from fourth
94 95
'

96
test_expect_success 'output during multi-pick indicates merge strategy' '
97 98 99 100
	cat <<-\EOF >expected &&
	Trying simple merge.
	[master OBJID] second
	 Author: A U Thor <author@example.com>
101
	 1 file changed, 1 insertion(+)
102 103 104
	Trying simple merge.
	[master OBJID] third
	 Author: A U Thor <author@example.com>
105
	 1 file changed, 1 insertion(+)
106 107 108
	Trying simple merge.
	[master OBJID] fourth
	 Author: A U Thor <author@example.com>
109
	 1 file changed, 1 insertion(+)
110 111
	EOF

112
	git checkout -f master &&
113 114
	git reset --hard first &&
	test_tick &&
115 116
	git cherry-pick --strategy resolve first..fourth >actual &&
	sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
117
	test_i18ncmp expected actual.fuzzy
118 119 120
'

test_expect_success 'cherry-pick --ff first..fourth works' '
121
	git checkout -f master &&
122 123 124 125 126
	git reset --hard first &&
	test_tick &&
	git cherry-pick --ff first..fourth &&
	git diff --quiet other &&
	git diff --quiet HEAD other &&
127
	check_head_equals fourth
128 129 130
'

test_expect_success 'cherry-pick -n first..fourth works' '
131
	git checkout -f master &&
132 133 134 135 136 137 138 139 140
	git reset --hard first &&
	test_tick &&
	git cherry-pick -n first..fourth &&
	git diff --quiet other &&
	git diff --cached --quiet other &&
	git diff --quiet HEAD first
'

test_expect_success 'revert first..fourth works' '
141
	git checkout -f master &&
142 143 144 145 146 147 148 149 150
	git reset --hard fourth &&
	test_tick &&
	git revert first..fourth &&
	git diff --quiet first &&
	git diff --cached --quiet first &&
	git diff --quiet HEAD first
'

test_expect_success 'revert ^first fourth works' '
151
	git checkout -f master &&
152 153 154 155 156 157 158 159 160
	git reset --hard fourth &&
	test_tick &&
	git revert ^first fourth &&
	git diff --quiet first &&
	git diff --cached --quiet first &&
	git diff --quiet HEAD first
'

test_expect_success 'revert fourth fourth~1 fourth~2 works' '
161
	git checkout -f master &&
162 163 164 165 166 167 168 169
	git reset --hard fourth &&
	test_tick &&
	git revert fourth fourth~1 fourth~2 &&
	git diff --quiet first &&
	git diff --cached --quiet first &&
	git diff --quiet HEAD first
'

170
test_expect_success 'cherry-pick -3 fourth works' '
171
	git checkout -f master &&
172 173 174 175 176
	git reset --hard first &&
	test_tick &&
	git cherry-pick -3 fourth &&
	git diff --quiet other &&
	git diff --quiet HEAD other &&
177
	check_head_differs_from fourth
178 179
'

180 181 182 183 184 185 186
test_expect_success 'cherry-pick --stdin works' '
	git checkout -f master &&
	git reset --hard first &&
	test_tick &&
	git rev-list --reverse first..fourth | git cherry-pick --stdin &&
	git diff --quiet other &&
	git diff --quiet HEAD other &&
187
	check_head_differs_from fourth
188 189
'

190
test_done