Skip to content

Commit 8b54f63

Browse files
committed
Merge branch 'jc/merge-saner-messages'
* jc/merge-saner-messages: merge-recursive: give less scary messages when merge did not start
2 parents 1cdd64e + fadd069 commit 8b54f63

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

merge-recursive.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ static int git_merge_trees(int index_only,
170170
int rc;
171171
struct tree_desc t[3];
172172
struct unpack_trees_options opts;
173+
static const struct unpack_trees_error_msgs msgs = {
174+
/* would_overwrite */
175+
"Your local changes to '%s' would be overwritten by merge. Aborting.",
176+
/* not_uptodate_file */
177+
"Your local changes to '%s' would be overwritten by merge. Aborting.",
178+
/* not_uptodate_dir */
179+
"Updating '%s' would lose untracked files in it. Aborting.",
180+
/* would_lose_untracked */
181+
"Untracked working tree file '%s' would be %s by merge. Aborting",
182+
/* bind_overlap -- will not happen here */
183+
NULL,
184+
};
173185

174186
memset(&opts, 0, sizeof(opts));
175187
if (index_only)
@@ -181,6 +193,7 @@ static int git_merge_trees(int index_only,
181193
opts.fn = threeway_merge;
182194
opts.src_index = &the_index;
183195
opts.dst_index = &the_index;
196+
opts.msgs = msgs;
184197

185198
init_tree_desc_from_tree(t+0, common);
186199
init_tree_desc_from_tree(t+1, head);
@@ -1188,10 +1201,14 @@ int merge_trees(struct merge_options *o,
11881201

11891202
code = git_merge_trees(o->call_depth, common, head, merge);
11901203

1191-
if (code != 0)
1192-
die("merging of trees %s and %s failed",
1193-
sha1_to_hex(head->object.sha1),
1194-
sha1_to_hex(merge->object.sha1));
1204+
if (code != 0) {
1205+
if (show(o, 4) || o->call_depth)
1206+
die("merging of trees %s and %s failed",
1207+
sha1_to_hex(head->object.sha1),
1208+
sha1_to_hex(merge->object.sha1));
1209+
else
1210+
exit(128);
1211+
}
11951212

11961213
if (unmerged_cache()) {
11971214
struct string_list *entries, *re_head, *re_merge;

0 commit comments

Comments
 (0)