git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
blob cc0ae9411a433ff373adb11e4797adc44662595e 6744 bytes (raw)
name: t/t3437-rebase-fixup-options.sh 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
 
#!/bin/sh
#
# Copyright (c) 2018 Phillip Wood
#

test_description='git rebase interactive fixup options

This test checks the "fixup [-C|-c]" command of rebase interactive.
In addition to amending the contents of the commit, "fixup -C"
replaces the original commit message with the message of the fixup
commit. "fixup -c" also replaces the original message, but opens the
editor to allow the user to edit the message before committing. Similar
to the "fixup" command that works with "fixup!", "fixup -C" works with
"amend!" upon --autosquash.
'

. ./test-lib.sh

. "$TEST_DIRECTORY"/lib-rebase.sh

EMPTY=""

# test_commit_message <rev> -m <msg>
# test_commit_message <rev> <path>
# Verify that the commit message of <rev> matches
# <msg> or the content of <path>.
test_commit_message () {
	git show --no-patch --pretty=format:%B "$1" >actual &&
	case "$2" in
	-m)
		echo "$3" >expect &&
		test_cmp expect actual ;;
	*)
		test_cmp "$2" actual ;;
	esac
}

get_author () {
	rev="$1" &&
	git log -1 --pretty=format:"%an %ae %at" "$rev"
}

test_expect_success 'setup' '
	cat >message <<-EOF &&
	amend! B
	${EMPTY}
	new subject
	${EMPTY}
	new
	body
	EOF

	test_commit A A &&
	test_commit B B &&
	get_author HEAD >expected-author &&
	ORIG_AUTHOR_NAME="$GIT_AUTHOR_NAME" &&
	ORIG_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" &&
	GIT_AUTHOR_NAME="Amend Author" &&
	GIT_AUTHOR_EMAIL="amend@example.com" &&
	test_commit "$(cat message)" A A1 A1 &&
	test_commit A2 A &&
	test_commit A3 A &&
	GIT_AUTHOR_NAME="$ORIG_AUTHOR_NAME" &&
	GIT_AUTHOR_EMAIL="$ORIG_AUTHOR_EMAIL" &&
	git checkout -b conflicts-branch A &&
	test_commit conflicts A &&

	set_fake_editor &&
	git checkout -b branch B &&
	echo B1 >B &&
	test_tick &&
	git commit --fixup=HEAD -a &&
	test_tick &&
	git commit --allow-empty -F - <<-EOF &&
	amend! B
	${EMPTY}
	B
	${EMPTY}
	edited 1
	EOF
	test_tick &&
	git commit --allow-empty -F - <<-EOF &&
	amend! amend! B
	${EMPTY}
	B
	${EMPTY}
	edited 1
	${EMPTY}
	edited 2
	EOF
	echo B2 >B &&
	test_tick &&
	FAKE_COMMIT_AMEND="edited squash" git commit --squash=HEAD -a &&
	echo B3 >B &&
	test_tick &&
	git commit -a -F - <<-EOF &&
	amend! amend! amend! B
	${EMPTY}
	B
	${EMPTY}
	edited 1
	${EMPTY}
	edited 2
	${EMPTY}
	edited 3
	EOF

	GIT_AUTHOR_NAME="Rebase Author" &&
	GIT_AUTHOR_EMAIL="rebase.author@example.com" &&
	GIT_COMMITTER_NAME="Rebase Committer" &&
	GIT_COMMITTER_EMAIL="rebase.committer@example.com"
'

test_expect_success 'simple fixup -C works' '
	test_when_finished "test_might_fail git rebase --abort" &&
	git checkout --detach A2 &&
	FAKE_LINES="1 fixup-C 2" git rebase -i B &&
	test_cmp_rev HEAD^ B &&
	test_cmp_rev HEAD^{tree} A2^{tree} &&
	test_commit_message HEAD -m "A2"
'

test_expect_success 'simple fixup -c works' '
	test_when_finished "test_might_fail git rebase --abort" &&
	git checkout --detach A2 &&
	git log -1 --pretty=format:%B >expected-fixup-message &&
	test_write_lines "" "Modified A2" >>expected-fixup-message &&
	FAKE_LINES="1 fixup-c 2" \
		FAKE_COMMIT_AMEND="Modified A2" \
		git rebase -i B &&
	test_cmp_rev HEAD^ B &&
	test_cmp_rev HEAD^{tree} A2^{tree} &&
	test_commit_message HEAD expected-fixup-message
'

test_expect_success 'fixup -C removes amend! from message' '
	test_when_finished "test_might_fail git rebase --abort" &&
	git checkout --detach A1 &&
	git log -1 --pretty=format:%b >expected-message &&
	FAKE_LINES="1 fixup-C 2" git rebase -i A &&
	test_cmp_rev HEAD^ A &&
	test_cmp_rev HEAD^{tree} A1^{tree} &&
	test_commit_message HEAD expected-message &&
	get_author HEAD >actual-author &&
	test_cmp expected-author actual-author
'

test_expect_success 'fixup -C with conflicts gives correct message' '
	test_when_finished "test_might_fail git rebase --abort" &&
	git checkout --detach A1 &&
	git log -1 --pretty=format:%b >expected-message &&
	test_write_lines "" "edited" >>expected-message &&
	test_must_fail env FAKE_LINES="1 fixup-C 2" git rebase -i conflicts &&
	git checkout --theirs -- A &&
	git add A &&
	FAKE_COMMIT_AMEND=edited git rebase --continue &&
	test_cmp_rev HEAD^ conflicts &&
	test_cmp_rev HEAD^{tree} A1^{tree} &&
	test_commit_message HEAD expected-message &&
	get_author HEAD >actual-author &&
	test_cmp expected-author actual-author
'

test_expect_success 'skipping fixup -C after fixup gives correct message' '
	test_when_finished "test_might_fail git rebase --abort" &&
	git checkout --detach A3 &&
	test_must_fail env FAKE_LINES="1 fixup 2 fixup-C 4" git rebase -i A &&
	git reset --hard &&
	FAKE_COMMIT_AMEND=edited git rebase --continue &&
	test_commit_message HEAD -m "B"
'

test_expect_success 'sequence of fixup, fixup -C & squash --signoff works' '
	git checkout --detach branch &&
	FAKE_LINES="1 fixup 2 fixup-C 3 fixup-C 4 squash 5 fixup-C 6" \
		FAKE_COMMIT_AMEND=squashed \
		FAKE_MESSAGE_COPY=actual-squash-message \
		git -c commit.status=false rebase -ik --signoff A &&
	git diff-tree --exit-code --patch HEAD branch -- &&
	test_cmp_rev HEAD^ A &&
	test_i18ncmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
		actual-squash-message
'

test_expect_success 'first fixup -C commented out in sequence fixup fixup -C fixup -C' '
	test_when_finished "test_might_fail git rebase --abort" &&
	git checkout branch && git checkout --detach branch~2 &&
	git log -1 --pretty=format:%b >expected-message &&
	FAKE_LINES="1 fixup 2 fixup-C 3 fixup-C 4" git rebase -i A &&
	test_cmp_rev HEAD^ A &&
	test_commit_message HEAD expected-message
'

test_expect_success 'multiple fixup -c opens editor once' '
	test_when_finished "test_might_fail git rebase --abort" &&
	git checkout --detach A3 &&
	base=$(git rev-parse HEAD~4) &&
	FAKE_COMMIT_MESSAGE="Modified-A3" \
		FAKE_LINES="1 fixup-C 2 fixup-c 3 fixup-c 4" \
		EXPECT_HEADER_COUNT=4 \
		git rebase -i $base &&
	test_cmp_rev $base HEAD^ &&
	get_author HEAD >actual-author &&
	test_cmp expected-author actual-author &&
	test 1 = $(git show | grep Modified-A3 | wc -l)
'

test_expect_success 'sequence squash, fixup & fixup -c gives combined message' '
	test_when_finished "test_might_fail git rebase --abort" &&
	git checkout --detach A3 &&
	FAKE_LINES="1 squash 2 fixup 3 fixup-c 4" \
		FAKE_MESSAGE_COPY=actual-combined-message \
		git -c commit.status=false rebase -i A &&
	test_i18ncmp "$TEST_DIRECTORY/t3437/expected-combined-message" \
		actual-combined-message &&
	test_cmp_rev HEAD^ A
'

test_expect_success 'fixup -C works upon --autosquash with amend!' '
	git checkout --detach branch &&
	FAKE_COMMIT_AMEND=squashed \
		FAKE_MESSAGE_COPY=actual-squash-message \
		git -c commit.status=false rebase -ik --autosquash \
						--signoff A &&
	git diff-tree --exit-code --patch HEAD branch -- &&
	test_cmp_rev HEAD^ A &&
	test_i18ncmp "$TEST_DIRECTORY/t3437/expected-squash-message" \
		actual-squash-message
'

test_done

debug log:

solving cc0ae9411a ...
found cc0ae9411a in https://public-inbox.org/git/20210208192528.21399-9-charvi077@gmail.com/
found 180fc50248 in https://public-inbox.org/git/20210208192528.21399-8-charvi077@gmail.com/
found 242770a3ec in https://public-inbox.org/git/20210208192528.21399-7-charvi077@gmail.com/
found 3de899f68a in https://public-inbox.org/git/20210207181439.1178-6-charvi077@gmail.com/ ||
	https://public-inbox.org/git/20210208192528.21399-6-charvi077@gmail.com/
found 36dee15c4b in https://public-inbox.org/git/20210207181439.1178-5-charvi077@gmail.com/ ||
	https://public-inbox.org/git/20210208192528.21399-5-charvi077@gmail.com/
found 945df2555b in https://80x24.org/mirrors/git.git
preparing index
index prepared:
100755 945df2555bced44f58885e667a15f2c4d7b10860	t/t3437-rebase-fixup-options.sh

applying [1/5] https://public-inbox.org/git/20210207181439.1178-5-charvi077@gmail.com/
diff --git a/t/t3437-rebase-fixup-options.sh b/t/t3437-rebase-fixup-options.sh
index 945df2555b..36dee15c4b 100755

Checking patch t/t3437-rebase-fixup-options.sh...
Applied patch t/t3437-rebase-fixup-options.sh cleanly.

skipping https://public-inbox.org/git/20210208192528.21399-5-charvi077@gmail.com/ for 36dee15c4b
index at:
100755 36dee15c4bf18f39df61dca91023f3848b7edd44	t/t3437-rebase-fixup-options.sh

applying [2/5] https://public-inbox.org/git/20210207181439.1178-6-charvi077@gmail.com/
diff --git a/t/t3437-rebase-fixup-options.sh b/t/t3437-rebase-fixup-options.sh
index 36dee15c4b..3de899f68a 100755

Checking patch t/t3437-rebase-fixup-options.sh...
Applied patch t/t3437-rebase-fixup-options.sh cleanly.

skipping https://public-inbox.org/git/20210208192528.21399-6-charvi077@gmail.com/ for 3de899f68a
index at:
100755 3de899f68aa1a7057d4c06405654c59ae2bfef1a	t/t3437-rebase-fixup-options.sh

applying [3/5] https://public-inbox.org/git/20210208192528.21399-7-charvi077@gmail.com/
diff --git a/t/t3437-rebase-fixup-options.sh b/t/t3437-rebase-fixup-options.sh
index 3de899f68a..242770a3ec 100755


applying [4/5] https://public-inbox.org/git/20210208192528.21399-8-charvi077@gmail.com/
diff --git a/t/t3437-rebase-fixup-options.sh b/t/t3437-rebase-fixup-options.sh
index 242770a3ec..180fc50248 100755


applying [5/5] https://public-inbox.org/git/20210208192528.21399-9-charvi077@gmail.com/
diff --git a/t/t3437-rebase-fixup-options.sh b/t/t3437-rebase-fixup-options.sh
index 180fc50248..cc0ae9411a 100755

Checking patch t/t3437-rebase-fixup-options.sh...
Applied patch t/t3437-rebase-fixup-options.sh cleanly.
Checking patch t/t3437-rebase-fixup-options.sh...
Applied patch t/t3437-rebase-fixup-options.sh cleanly.
Checking patch t/t3437-rebase-fixup-options.sh...
Applied patch t/t3437-rebase-fixup-options.sh cleanly.

index at:
100755 cc0ae9411a433ff373adb11e4797adc44662595e	t/t3437-rebase-fixup-options.sh

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).