commit: do not lose SQUASH_MSG contents
When concluding a conflicted "git merge --squash", the command failed to read SQUASH_MSG that was prepared by "git merge", and showed only the "# Conflicts:" list of conflicted paths. Place the contents from SQUASH_MSG at the beginning, just like we show the commit log skeleton first when concluding a normal merge, and then show the "# Conflicts:" list, to help the user write the log message for the resulting commit. Test by Junio C Hamano <gitster@pobox.com>. Signed-off-by: Sven Strickroth <sven@cs-ware.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Sven Strickroth committed
Mar 21, 2016 at 23:29 UTC
b64c1e0718f4a54d75b8faf0421471faa531af68
2 files changed
+38
-1
builtin/commit.c
+10
-1
@@ -726,9 +726,18 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
726
&sb, &ctx);
727
hook_arg1 = "message";
728
} else if (!stat(git_path_merge_msg(), &statbuf)) {
729
+ /*
730
+ * prepend SQUASH_MSG here if it exists and a
731
+ * "merge --squash" was originally performed
732
+ */
733
+ if (!stat(git_path_squash_msg(), &statbuf)) {
734
+ if (strbuf_read_file(&sb, git_path_squash_msg(), 0) < 0)
735
+ die_errno(_("could not read SQUASH_MSG"));
736
+ hook_arg1 = "squash";
737
+ } else
738
+ hook_arg1 = "merge";
739
if (strbuf_read_file(&sb, git_path_merge_msg(), 0) < 0)
740
die_errno(_("could not read MERGE_MSG"));
731
- hook_arg1 = "merge";
741
} else if (!stat(git_path_squash_msg(), &statbuf)) {
742
if (strbuf_read_file(&sb, git_path_squash_msg(), 0) < 0)
743
die_errno(_("could not read SQUASH_MSG"));
t/t7600-merge.sh
+28
@@ -33,9 +33,11 @@ printf '%s\n' 1 2 3 4 5 6 7 8 9 >file
33
printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >file.1
34
printf '%s\n' 1 2 3 4 '5 X' 6 7 8 9 >file.5
35
printf '%s\n' 1 2 3 4 5 6 7 8 '9 X' >file.9
36
+printf '%s\n' 1 2 3 4 5 6 7 8 '9 Y' >file.9y
37
printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >result.1
38
printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5
39
printf '%s\n' '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9
40
+printf '%s\n' 1 2 3 4 5 6 7 8 '9 Z' >result.9z
41
>empty
42
43
create_merge_msgs () {
@@ -128,6 +130,12 @@ test_expect_success 'setup' '
130
git tag c2 &&
131
c2=$(git rev-parse HEAD) &&
132
git reset --hard "$c0" &&
133
+ cp file.9y file &&
134
+ git add file &&
135
+ test_tick &&
136
+ git commit -m "commit 7" &&
137
+ git tag c7 &&
138
+ git reset --hard "$c0" &&
139
cp file.9 file &&
140
git add file &&
141
test_tick &&
@@ -218,6 +226,26 @@ test_expect_success 'merge c1 with c2' '
226
verify_parents $c1 $c2
227
'
228
229
+test_expect_success 'merge --squash c3 with c7' '
230
+ git reset --hard c3 &&
231
+ test_must_fail git merge --squash c7 &&
232
+ cat result.9z >file &&
233
+ git commit --no-edit -a &&
234
+
235
+ {
236
+ cat <<-EOF
237
+ Squashed commit of the following:
238
+
239
+ $(git show -s c7)
240
+
241
+ # Conflicts:
242
+ # file
243
+ EOF
244
+ } >expect &&
245
+ git cat-file commit HEAD | sed -e '1,/^$/d' >actual &&
246
+ test_cmp expect actual
247
+'
248
+
249
test_debug 'git log --graph --decorate --oneline --all'
250
251
test_expect_success 'merge c1 with c2 and c3' '