Skip to content

Commit 9f6728d

Browse files
committed
Merge branch 'pw/rebase-i-regression-fix-tests' into maint
Fix a recent regression to "git rebase -i" and add tests that would have caught it and others. * pw/rebase-i-regression-fix-tests: t3420: fix under GETTEXT_POISON build rebase: add more regression tests for console output rebase: add regression tests for console output rebase -i: add test for reflog message sequencer: print autostash messages to stderr
2 parents f904494 + adf16c0 commit 9f6728d

File tree

4 files changed

+148
-12
lines changed

4 files changed

+148
-12
lines changed

git-rebase.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ apply_autostash () {
166166
stash_sha1=$(cat "$state_dir/autostash")
167167
if git stash apply $stash_sha1 2>&1 >/dev/null
168168
then
169-
echo "$(gettext 'Applied autostash.')"
169+
echo "$(gettext 'Applied autostash.')" >&2
170170
else
171171
git stash store -m "autostash" -q $stash_sha1 ||
172172
die "$(eval_gettext "Cannot store \$stash_sha1")"
173173
gettext 'Applying autostash resulted in conflicts.
174174
Your changes are safe in the stash.
175175
You can run "git stash pop" or "git stash drop" at any time.
176-
'
176+
' >&2
177177
fi
178178
fi
179179
}

sequencer.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,7 @@ static int apply_autostash(struct replay_opts *opts)
19211921
argv_array_push(&child.args, "apply");
19221922
argv_array_push(&child.args, stash_sha1.buf);
19231923
if (!run_command(&child))
1924-
printf(_("Applied autostash.\n"));
1924+
fprintf(stderr, _("Applied autostash.\n"));
19251925
else {
19261926
struct child_process store = CHILD_PROCESS_INIT;
19271927

@@ -1935,10 +1935,11 @@ static int apply_autostash(struct replay_opts *opts)
19351935
if (run_command(&store))
19361936
ret = error(_("cannot store %s"), stash_sha1.buf);
19371937
else
1938-
printf(_("Applying autostash resulted in conflicts.\n"
1939-
"Your changes are safe in the stash.\n"
1940-
"You can run \"git stash pop\" or"
1941-
" \"git stash drop\" at any time.\n"));
1938+
fprintf(stderr,
1939+
_("Applying autostash resulted in conflicts.\n"
1940+
"Your changes are safe in the stash.\n"
1941+
"You can run \"git stash pop\" or"
1942+
" \"git stash drop\" at any time.\n"));
19421943
}
19431944

19441945
strbuf_release(&stash_sha1);

t/t3404-rebase-interactive.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ test_expect_success 'reflog for the branch shows state before rebase' '
169169
test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
170170
'
171171

172+
test_expect_success 'reflog for the branch shows correct finish message' '
173+
printf "rebase -i (finish): refs/heads/branch1 onto %s\n" \
174+
"$(git rev-parse branch2)" >expected &&
175+
git log -g --pretty=%gs -1 refs/heads/branch1 >actual &&
176+
test_cmp expected actual
177+
'
178+
172179
test_expect_success 'exchange two commits' '
173180
set_fake_editor &&
174181
FAKE_LINES="2 1" git rebase -i HEAD~2 &&

t/t3420-rebase-autostash.sh

Lines changed: 133 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,123 @@ test_expect_success setup '
3333
git commit -m "related commit"
3434
'
3535

36-
testrebase() {
36+
create_expected_success_am () {
37+
cat >expected <<-EOF
38+
$(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
39+
HEAD is now at $(git rev-parse --short feature-branch) third commit
40+
First, rewinding head to replay your work on top of it...
41+
Applying: second commit
42+
Applying: third commit
43+
Applied autostash.
44+
EOF
45+
}
46+
47+
create_expected_success_interactive () {
48+
q_to_cr >expected <<-EOF
49+
$(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
50+
HEAD is now at $(git rev-parse --short feature-branch) third commit
51+
Rebasing (1/2)QRebasing (2/2)QApplied autostash.
52+
Successfully rebased and updated refs/heads/rebased-feature-branch.
53+
EOF
54+
}
55+
56+
create_expected_success_merge () {
57+
cat >expected <<-EOF
58+
$(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
59+
HEAD is now at $(git rev-parse --short feature-branch) third commit
60+
First, rewinding head to replay your work on top of it...
61+
Merging unrelated-onto-branch with HEAD~1
62+
Merging:
63+
$(git rev-parse --short unrelated-onto-branch) unrelated commit
64+
$(git rev-parse --short feature-branch^) second commit
65+
found 1 common ancestor:
66+
$(git rev-parse --short feature-branch~2) initial commit
67+
[detached HEAD $(git rev-parse --short rebased-feature-branch~1)] second commit
68+
Author: A U Thor <[email protected]>
69+
Date: Thu Apr 7 15:14:13 2005 -0700
70+
2 files changed, 2 insertions(+)
71+
create mode 100644 file1
72+
create mode 100644 file2
73+
Committed: 0001 second commit
74+
Merging unrelated-onto-branch with HEAD~0
75+
Merging:
76+
$(git rev-parse --short rebased-feature-branch~1) second commit
77+
$(git rev-parse --short feature-branch) third commit
78+
found 1 common ancestor:
79+
$(git rev-parse --short feature-branch~1) second commit
80+
[detached HEAD $(git rev-parse --short rebased-feature-branch)] third commit
81+
Author: A U Thor <[email protected]>
82+
Date: Thu Apr 7 15:15:13 2005 -0700
83+
1 file changed, 1 insertion(+)
84+
create mode 100644 file3
85+
Committed: 0002 third commit
86+
All done.
87+
Applied autostash.
88+
EOF
89+
}
90+
91+
create_expected_failure_am () {
92+
cat >expected <<-EOF
93+
$(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
94+
HEAD is now at $(git rev-parse --short feature-branch) third commit
95+
First, rewinding head to replay your work on top of it...
96+
Applying: second commit
97+
Applying: third commit
98+
Applying autostash resulted in conflicts.
99+
Your changes are safe in the stash.
100+
You can run "git stash pop" or "git stash drop" at any time.
101+
EOF
102+
}
103+
104+
create_expected_failure_interactive () {
105+
q_to_cr >expected <<-EOF
106+
$(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
107+
HEAD is now at $(git rev-parse --short feature-branch) third commit
108+
Rebasing (1/2)QRebasing (2/2)QApplying autostash resulted in conflicts.
109+
Your changes are safe in the stash.
110+
You can run "git stash pop" or "git stash drop" at any time.
111+
Successfully rebased and updated refs/heads/rebased-feature-branch.
112+
EOF
113+
}
114+
115+
create_expected_failure_merge () {
116+
cat >expected <<-EOF
117+
$(grep "^Created autostash: [0-9a-f][0-9a-f]*\$" actual)
118+
HEAD is now at $(git rev-parse --short feature-branch) third commit
119+
First, rewinding head to replay your work on top of it...
120+
Merging unrelated-onto-branch with HEAD~1
121+
Merging:
122+
$(git rev-parse --short unrelated-onto-branch) unrelated commit
123+
$(git rev-parse --short feature-branch^) second commit
124+
found 1 common ancestor:
125+
$(git rev-parse --short feature-branch~2) initial commit
126+
[detached HEAD $(git rev-parse --short rebased-feature-branch~1)] second commit
127+
Author: A U Thor <[email protected]>
128+
Date: Thu Apr 7 15:14:13 2005 -0700
129+
2 files changed, 2 insertions(+)
130+
create mode 100644 file1
131+
create mode 100644 file2
132+
Committed: 0001 second commit
133+
Merging unrelated-onto-branch with HEAD~0
134+
Merging:
135+
$(git rev-parse --short rebased-feature-branch~1) second commit
136+
$(git rev-parse --short feature-branch) third commit
137+
found 1 common ancestor:
138+
$(git rev-parse --short feature-branch~1) second commit
139+
[detached HEAD $(git rev-parse --short rebased-feature-branch)] third commit
140+
Author: A U Thor <[email protected]>
141+
Date: Thu Apr 7 15:15:13 2005 -0700
142+
1 file changed, 1 insertion(+)
143+
create mode 100644 file3
144+
Committed: 0002 third commit
145+
All done.
146+
Applying autostash resulted in conflicts.
147+
Your changes are safe in the stash.
148+
You can run "git stash pop" or "git stash drop" at any time.
149+
EOF
150+
}
151+
152+
testrebase () {
37153
type=$1
38154
dotest=$2
39155

@@ -51,14 +167,20 @@ testrebase() {
51167
test_config rebase.autostash true &&
52168
git reset --hard &&
53169
git checkout -b rebased-feature-branch feature-branch &&
54-
test_when_finished git branch -D rebased-feature-branch &&
55170
echo dirty >>file3 &&
56-
git rebase$type unrelated-onto-branch &&
171+
git rebase$type unrelated-onto-branch >actual 2>&1 &&
57172
grep unrelated file4 &&
58173
grep dirty file3 &&
59174
git checkout feature-branch
60175
'
61176

177+
test_expect_success "rebase$type --autostash: check output" '
178+
test_when_finished git branch -D rebased-feature-branch &&
179+
suffix=${type#\ --} && suffix=${suffix:-am} &&
180+
create_expected_success_$suffix &&
181+
test_i18ncmp expected actual
182+
'
183+
62184
test_expect_success "rebase$type: dirty index, non-conflicting rebase" '
63185
test_config rebase.autostash true &&
64186
git reset --hard &&
@@ -137,10 +259,9 @@ testrebase() {
137259
test_config rebase.autostash true &&
138260
git reset --hard &&
139261
git checkout -b rebased-feature-branch feature-branch &&
140-
test_when_finished git branch -D rebased-feature-branch &&
141262
echo dirty >file4 &&
142263
git add file4 &&
143-
git rebase$type unrelated-onto-branch &&
264+
git rebase$type unrelated-onto-branch >actual 2>&1 &&
144265
test_path_is_missing $dotest &&
145266
git reset --hard &&
146267
grep unrelated file4 &&
@@ -149,6 +270,13 @@ testrebase() {
149270
git stash pop &&
150271
grep dirty file4
151272
'
273+
274+
test_expect_success "rebase$type: check output with conflicting stash" '
275+
test_when_finished git branch -D rebased-feature-branch &&
276+
suffix=${type#\ --} && suffix=${suffix:-am} &&
277+
create_expected_failure_$suffix &&
278+
test_i18ncmp expected actual
279+
'
152280
}
153281

154282
test_expect_success "rebase: fast-forward rebase" '

0 commit comments

Comments
 (0)