t6012-rev-list-simplify.sh 6.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
#!/bin/sh

test_description='merge simplification'

. ./test-lib.sh

note () {
	git tag "$1"
}

unnote () {
B
brian m. carlson 已提交
12
	git name-rev --tags --stdin | sed -e "s|$OID_REGEX (tags/\([^)]*\)) |\1 |g"
13 14
}

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#
# Create a test repo with interesting commit graph:
#
# A--B----------G--H--I--K--L
#  \  \           /     /
#   \  \         /     /
#    C------E---F     J
#        \_/
#
# The commits are laid out from left-to-right starting with
# the root commit A and terminating at the tip commit L.
#
# There are a few places where we adjust the commit date or
# author date to make the --topo-order, --date-order, and
# --author-date-order flags produce different output.

31 32
test_expect_success setup '
	echo "Hi there" >file &&
33 34 35
	echo "initial" >lost &&
	git add file lost &&
	test_tick && git commit -m "Initial file and lost" &&
36 37 38 39
	note A &&

	git branch other-branch &&

40 41 42 43 44 45 46 47
	git symbolic-ref HEAD refs/heads/unrelated &&
	git rm -f "*" &&
	echo "Unrelated branch" >side &&
	git add side &&
	test_tick && git commit -m "Side root" &&
	note J &&
	git checkout master &&

48
	echo "Hello" >file &&
49 50
	echo "second" >lost &&
	git add file lost &&
51
	test_tick && GIT_AUTHOR_DATE=$(($test_tick + 120)) git commit -m "Modified file and lost" &&
52 53 54 55 56
	note B &&

	git checkout other-branch &&

	echo "Hello" >file &&
57 58
	>lost &&
	git add file lost &&
59 60 61 62 63 64 65 66
	test_tick && git commit -m "Modified the file identically" &&
	note C &&

	echo "This is a stupid example" >another-file &&
	git add another-file &&
	test_tick && git commit -m "Add another file" &&
	note D &&

67 68 69
	test_tick &&
	test_must_fail git merge -m "merge" master &&
	>lost && git commit -a -m "merge" &&
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
	note E &&

	echo "Yet another" >elif &&
	git add elif &&
	test_tick && git commit -m "Irrelevant change" &&
	note F &&

	git checkout master &&
	echo "Yet another" >elif &&
	git add elif &&
	test_tick && git commit -m "Another irrelevant change" &&
	note G &&

	test_tick && git merge -m "merge" other-branch &&
	note H &&

	echo "Final change" >file &&
	test_tick && git commit -a -m "Final change" &&
88 89 90
	note I &&

	git checkout master &&
91
	test_tick && git merge --allow-unrelated-histories -m "Coolest" unrelated &&
92 93 94 95 96 97
	note K &&

	echo "Immaterial" >elif &&
	git add elif &&
	test_tick && git commit -m "Last" &&
	note L
98 99 100 101
'

FMT='tformat:%P 	%H | %s'

102 103 104
check_outcome () {
	outcome=$1
	shift
105 106 107 108 109 110
	for c in $1
	do
		echo "$c"
	done >expect &&
	shift &&
	param="$*" &&
111
	test_expect_$outcome "log $param" '
112 113 114
		git log --pretty="$FMT" --parents $param |
		unnote >actual &&
		sed -e "s/^.*	\([^ ]*\) .*/\1/" >check <actual &&
115
		test_cmp expect check
116 117 118
	'
}

119 120 121 122
check_result () {
	check_outcome success "$@"
}

123 124 125 126
check_result 'L K J I H F E D C G B A' --full-history --topo-order
check_result 'L K I H G F E D C B J A' --full-history
check_result 'L K I H G F E D C B J A' --full-history --date-order
check_result 'L K I H G F E D B C J A' --full-history --author-date-order
127 128 129
check_result 'K I H E C B A' --full-history -- file
check_result 'K I H E C B A' --full-history --topo-order -- file
check_result 'K I H E C B A' --full-history --date-order -- file
130
check_result 'K I H E B C A' --full-history --author-date-order -- file
131
check_result 'I E C B A' --simplify-merges -- file
132 133 134
check_result 'I E C B A' --simplify-merges --topo-order -- file
check_result 'I E C B A' --simplify-merges --date-order -- file
check_result 'I E B C A' --simplify-merges --author-date-order -- file
135 136
check_result 'I B A' -- file
check_result 'I B A' --topo-order -- file
137 138
check_result 'I B A' --date-order -- file
check_result 'I B A' --author-date-order -- file
139
check_result 'H' --first-parent -- another-file
140
check_result 'H' --first-parent --topo-order -- another-file
141

142 143 144 145 146 147
check_result 'E C B A' --full-history E -- lost
test_expect_success 'full history simplification without parent' '
	printf "%s\n" E C B A >expect &&
	git log --pretty="$FMT" --full-history E -- lost |
	unnote >actual &&
	sed -e "s/^.*	\([^ ]*\) .*/\1/" >check <actual &&
148
	test_cmp expect check
149 150
'

151 152 153 154 155 156
test_expect_success '--full-diff is not affected by --parents' '
	git log -p --pretty="%H" --full-diff -- file >expected &&
	git log -p --pretty="%H" --full-diff --parents -- file >actual &&
	test_cmp expected actual
'

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
#
# Create a new history to demonstrate the value of --show-pulls
# with respect to the subtleties of simplified history, --full-history,
# and --simplify-merges.
#
#   .-A---M-----C--N---O---P
#  /     / \  \  \/   /   /
# I     B   \  R-'`-Z'   /
#  \   /     \/         /
#   \ /      /\        /
#    `---X--'  `---Y--'
#
# This example is explained in Documentation/rev-list-options.txt

test_expect_success 'rebuild repo' '
	rm -rf .git * &&
	git init &&
174
	git switch -c topic &&
175 176 177 178 179 180 181 182 183 184 185 186 187 188

	echo base >file &&
	git add file &&
	test_commit I &&

	echo A >file &&
	git add file &&
	test_commit A &&

	git switch -c branchB I &&
	echo B >file &&
	git add file &&
	test_commit B &&

189
	git switch topic &&
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
	test_must_fail git merge -m "M" B &&
	echo A >file &&
	echo B >>file &&
	git add file &&
	git merge --continue &&
	note M &&

	echo C >other &&
	git add other &&
	test_commit C &&

	git switch -c branchX I &&
	echo X >file &&
	git add file &&
	test_commit X &&

	git switch -c branchR M &&
	git merge -m R -Xtheirs X &&
	note R &&

210
	git switch topic &&
211 212 213 214 215 216 217 218 219 220 221 222 223
	git merge -m N R &&
	note N &&

	git switch -c branchY M &&
	echo Y >y &&
	git add y &&
	test_commit Y &&

	git switch -c branchZ C &&
	echo Z >z &&
	git add z &&
	test_commit Z &&

224
	git switch topic &&
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
	git merge -m O Z &&
	note O &&

	git merge -m P Y &&
	note P
'

check_result 'X I' -- file
check_result 'N R X I' --show-pulls -- file

check_result 'P O N R X M B A I' --full-history --topo-order -- file
check_result 'N R X M B A I' --simplify-merges --topo-order --show-pulls -- file
check_result 'R X M B A I' --simplify-merges --topo-order -- file
check_result 'N M A I' --first-parent -- file
check_result 'N M A I' --first-parent --show-pulls -- file

# --ancestry-path implies --full-history
check_result 'P O N R M' --topo-order \
	--ancestry-path A..HEAD -- file
check_result 'P O N R M' --topo-order \
	--show-pulls \
	--ancestry-path A..HEAD -- file
check_result 'P O N R M' --topo-order \
	--full-history \
	--ancestry-path A..HEAD -- file
check_result 'R M' --topo-order \
	--simplify-merges \
	--ancestry-path A..HEAD -- file
check_result 'N R M' --topo-order \
	--simplify-merges --show-pulls \
	--ancestry-path A..HEAD -- file

test_expect_success 'log --graph --simplify-merges --show-pulls' '
	cat >expect <<-\EOF &&
	* N
	*   R
	|\  
	| * X
	* |   M
	|\ \  
	| * | B
	| |/  
	* / A
	|/  
	* I
	EOF
	git log --graph --pretty="%s" \
		--simplify-merges --show-pulls \
		-- file >actual &&
	test_cmp expect actual
'

277
test_done