Skip to content

Commit 5c30b8f

Browse files
committed
Merge branch 'mm/maint-merge-ff-error-message-fix' into maint
* mm/maint-merge-ff-error-message-fix: builtin-merge: show user-friendly error messages for fast-forward too. merge-recursive: make the error-message generation an extern function Conflicts: merge-recursive.c
2 parents 389e0ba + e2ced7d commit 5c30b8f

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

builtin-merge.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ static int checkout_fast_forward(unsigned char *head, unsigned char *remote)
650650
opts.verbose_update = 1;
651651
opts.merge = 1;
652652
opts.fn = twoway_merge;
653+
opts.msgs = get_porcelain_error_msgs();
653654

654655
trees[nr_trees] = parse_tree_indirect(head);
655656
if (!trees[nr_trees++])

merge-recursive.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,6 @@ static int git_merge_trees(int index_only,
171171
int rc;
172172
struct tree_desc t[3];
173173
struct unpack_trees_options opts;
174-
struct unpack_trees_error_msgs msgs = {
175-
/* would_overwrite */
176-
"Your local changes to '%s' would be overwritten by merge. Aborting.",
177-
/* not_uptodate_file */
178-
"Your local changes to '%s' would be overwritten by merge. Aborting.",
179-
/* not_uptodate_dir */
180-
"Updating '%s' would lose untracked files in it. Aborting.",
181-
/* would_lose_untracked */
182-
"Untracked working tree file '%s' would be %s by merge. Aborting",
183-
/* bind_overlap -- will not happen here */
184-
NULL,
185-
};
186-
if (advice_commit_before_merge) {
187-
msgs.would_overwrite = msgs.not_uptodate_file =
188-
"Your local changes to '%s' would be overwritten by merge. Aborting.\n"
189-
"Please, commit your changes or stash them before you can merge.";
190-
}
191174

192175
memset(&opts, 0, sizeof(opts));
193176
if (index_only)
@@ -199,7 +182,7 @@ static int git_merge_trees(int index_only,
199182
opts.fn = threeway_merge;
200183
opts.src_index = &the_index;
201184
opts.dst_index = &the_index;
202-
opts.msgs = msgs;
185+
opts.msgs = get_porcelain_error_msgs();
203186

204187
init_tree_desc_from_tree(t+0, common);
205188
init_tree_desc_from_tree(t+1, head);
@@ -1186,6 +1169,28 @@ static int process_entry(struct merge_options *o,
11861169
return clean_merge;
11871170
}
11881171

1172+
struct unpack_trees_error_msgs get_porcelain_error_msgs(void)
1173+
{
1174+
struct unpack_trees_error_msgs msgs = {
1175+
/* would_overwrite */
1176+
"Your local changes to '%s' would be overwritten by merge. Aborting.",
1177+
/* not_uptodate_file */
1178+
"Your local changes to '%s' would be overwritten by merge. Aborting.",
1179+
/* not_uptodate_dir */
1180+
"Updating '%s' would lose untracked files in it. Aborting.",
1181+
/* would_lose_untracked */
1182+
"Untracked working tree file '%s' would be %s by merge. Aborting",
1183+
/* bind_overlap -- will not happen here */
1184+
NULL,
1185+
};
1186+
if (advice_commit_before_merge) {
1187+
msgs.would_overwrite = msgs.not_uptodate_file =
1188+
"Your local changes to '%s' would be overwritten by merge. Aborting.\n"
1189+
"Please, commit your changes or stash them before you can merge.";
1190+
}
1191+
return msgs;
1192+
}
1193+
11891194
int merge_trees(struct merge_options *o,
11901195
struct tree *head,
11911196
struct tree *merge,

merge-recursive.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ struct merge_options {
1717
struct string_list current_directory_set;
1818
};
1919

20+
/* Return a list of user-friendly error messages to be used by merge */
21+
struct unpack_trees_error_msgs get_porcelain_error_msgs(void);
22+
2023
/* merge_trees() but with recursive ancestor consolidation */
2124
int merge_recursive(struct merge_options *o,
2225
struct commit *h1,

0 commit comments

Comments
 (0)