Skip to content

Commit c208e05

Browse files
committed
Merge branch 'dg/local-mod-error-messages'
* dg/local-mod-error-messages: t7609-merge-co-error-msgs: test non-fast forward case too. Move "show_all_errors = 1" to setup_unpack_trees_porcelain() setup_unpack_trees_porcelain: take the whole options struct as parameter Move set_porcelain_error_msgs to unpack-trees.c and rename it Conflicts: merge-recursive.c
2 parents f92d62e + c5978a5 commit c208e05

File tree

7 files changed

+69
-64
lines changed

7 files changed

+69
-64
lines changed

builtin/checkout.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ static int merge_working_tree(struct checkout_opts *opts,
380380
topts.src_index = &the_index;
381381
topts.dst_index = &the_index;
382382

383-
set_porcelain_error_msgs(topts.msgs, "checkout");
383+
setup_unpack_trees_porcelain(&topts, "checkout");
384384

385385
refresh_cache(REFRESH_QUIET);
386386

@@ -399,7 +399,6 @@ static int merge_working_tree(struct checkout_opts *opts,
399399
topts.dir = xcalloc(1, sizeof(*topts.dir));
400400
topts.dir->flags |= DIR_SHOW_IGNORED;
401401
topts.dir->exclude_per_dir = ".gitignore";
402-
topts.show_all_errors = 1;
403402
tree = parse_tree_indirect(old->commit ?
404403
old->commit->object.sha1 :
405404
(unsigned char *)EMPTY_TREE_SHA1_BIN);

builtin/merge.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,7 @@ int checkout_fast_forward(const unsigned char *head, const unsigned char *remote
718718
opts.verbose_update = 1;
719719
opts.merge = 1;
720720
opts.fn = twoway_merge;
721-
opts.show_all_errors = 1;
722-
set_porcelain_error_msgs(opts.msgs, "merge");
721+
setup_unpack_trees_porcelain(&opts, "merge");
723722

724723
trees[nr_trees] = parse_tree_indirect(head);
725724
if (!trees[nr_trees++])

merge-recursive.c

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static int git_merge_trees(int index_only,
180180
opts.fn = threeway_merge;
181181
opts.src_index = &the_index;
182182
opts.dst_index = &the_index;
183-
set_porcelain_error_msgs(opts.msgs, "merge");
183+
setup_unpack_trees_porcelain(&opts, "merge");
184184

185185
init_tree_desc_from_tree(t+0, common);
186186
init_tree_desc_from_tree(t+1, head);
@@ -1288,50 +1288,6 @@ static int process_df_entry(struct merge_options *o,
12881288
return clean_merge;
12891289
}
12901290

1291-
void set_porcelain_error_msgs(const char **msgs, const char *cmd)
1292-
{
1293-
const char *msg;
1294-
char *tmp;
1295-
const char *cmd2 = strcmp(cmd, "checkout") ? cmd : "switch branches";
1296-
if (advice_commit_before_merge)
1297-
msg = "Your local changes to the following files would be overwritten by %s:\n%%s"
1298-
"Please, commit your changes or stash them before you can %s.";
1299-
else
1300-
msg = "Your local changes to the following files would be overwritten by %s:\n%%s";
1301-
tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen(cmd2) - 2);
1302-
sprintf(tmp, msg, cmd, cmd2);
1303-
msgs[ERROR_WOULD_OVERWRITE] = tmp;
1304-
msgs[ERROR_NOT_UPTODATE_FILE] = tmp;
1305-
1306-
msgs[ERROR_NOT_UPTODATE_DIR] =
1307-
"Updating the following directories would lose untracked files in it:\n%s";
1308-
1309-
if (advice_commit_before_merge)
1310-
msg = "The following untracked working tree files would be %s by %s:\n%%s"
1311-
"Please move or remove them before you can %s.";
1312-
else
1313-
msg = "The following untracked working tree files would be %s by %s:\n%%s";
1314-
tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen("removed") + strlen(cmd2) - 4);
1315-
sprintf(tmp, msg, "removed", cmd, cmd2);
1316-
msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = tmp;
1317-
tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen("overwritten") + strlen(cmd2) - 4);
1318-
sprintf(tmp, msg, "overwritten", cmd, cmd2);
1319-
msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = tmp;
1320-
1321-
/*
1322-
* Special case: ERROR_BIND_OVERLAP refers to a pair of paths, we
1323-
* cannot easily display it as a list.
1324-
*/
1325-
msgs[ERROR_BIND_OVERLAP] = "Entry '%s' overlaps with '%s'. Cannot bind.";
1326-
1327-
msgs[ERROR_SPARSE_NOT_UPTODATE_FILE] =
1328-
"Cannot update sparse checkout: the following entries are not up-to-date:\n%s";
1329-
msgs[ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN] =
1330-
"The following Working tree files would be overwritten by sparse checkout update:\n%s";
1331-
msgs[ERROR_WOULD_LOSE_ORPHANED_REMOVED] =
1332-
"The following Working tree files would be removed by sparse checkout update:\n%s";
1333-
}
1334-
13351291
int merge_trees(struct merge_options *o,
13361292
struct tree *head,
13371293
struct tree *merge,

merge-recursive.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ struct merge_options {
2424
struct string_list current_directory_set;
2525
};
2626

27-
/*
28-
* Sets the list of user-friendly error messages to be used by the
29-
* command "cmd" (either merge or checkout)
30-
*/
31-
void set_porcelain_error_msgs(const char **msgs, const char *cmd);
32-
3327
/* merge_trees() but with recursive ancestor consolidation */
3428
int merge_recursive(struct merge_options *o,
3529
struct commit *h1,

t/t7609-merge-co-error-msgs.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,17 @@ error: The following untracked working tree files would be overwritten by merge:
3434
Please move or remove them before you can merge.
3535
EOF
3636

37-
test_expect_success 'untracked files overwritten by merge' '
37+
test_expect_success 'untracked files overwritten by merge (fast and non-fast forward)' '
3838
test_must_fail git merge branch 2>out &&
39-
test_cmp out expect
39+
test_cmp out expect &&
40+
git commit --allow-empty -m empty &&
41+
(
42+
GIT_MERGE_VERBOSITY=0 &&
43+
export GIT_MERGE_VERBOSITY &&
44+
test_must_fail git merge branch 2>out2
45+
) &&
46+
test_cmp out2 expect &&
47+
git reset --hard HEAD^
4048
'
4149

4250
cat >expect <<\EOF

unpack-trees.c

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* read-tree. Non-scripted Porcelain is not required to use these messages
1515
* and in fact are encouraged to reword them to better suit their particular
1616
* situation better. See how "git checkout" and "git merge" replaces
17-
* them using set_porcelain_error_msgs(), for example.
17+
* them using setup_unpack_trees_porcelain(), for example.
1818
*/
1919
const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
2020
/* ERROR_WOULD_OVERWRITE */
@@ -50,6 +50,54 @@ const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
5050
? ((o)->msgs[(type)]) \
5151
: (unpack_plumbing_errors[(type)]) )
5252

53+
void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
54+
const char *cmd)
55+
{
56+
const char **msgs = opts->msgs;
57+
const char *msg;
58+
char *tmp;
59+
const char *cmd2 = strcmp(cmd, "checkout") ? cmd : "switch branches";
60+
if (advice_commit_before_merge)
61+
msg = "Your local changes to the following files would be overwritten by %s:\n%%s"
62+
"Please, commit your changes or stash them before you can %s.";
63+
else
64+
msg = "Your local changes to the following files would be overwritten by %s:\n%%s";
65+
tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen(cmd2) - 2);
66+
sprintf(tmp, msg, cmd, cmd2);
67+
msgs[ERROR_WOULD_OVERWRITE] = tmp;
68+
msgs[ERROR_NOT_UPTODATE_FILE] = tmp;
69+
70+
msgs[ERROR_NOT_UPTODATE_DIR] =
71+
"Updating the following directories would lose untracked files in it:\n%s";
72+
73+
if (advice_commit_before_merge)
74+
msg = "The following untracked working tree files would be %s by %s:\n%%s"
75+
"Please move or remove them before you can %s.";
76+
else
77+
msg = "The following untracked working tree files would be %s by %s:\n%%s";
78+
tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen("removed") + strlen(cmd2) - 4);
79+
sprintf(tmp, msg, "removed", cmd, cmd2);
80+
msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = tmp;
81+
tmp = xmalloc(strlen(msg) + strlen(cmd) + strlen("overwritten") + strlen(cmd2) - 4);
82+
sprintf(tmp, msg, "overwritten", cmd, cmd2);
83+
msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = tmp;
84+
85+
/*
86+
* Special case: ERROR_BIND_OVERLAP refers to a pair of paths, we
87+
* cannot easily display it as a list.
88+
*/
89+
msgs[ERROR_BIND_OVERLAP] = "Entry '%s' overlaps with '%s'. Cannot bind.";
90+
91+
msgs[ERROR_SPARSE_NOT_UPTODATE_FILE] =
92+
"Cannot update sparse checkout: the following entries are not up-to-date:\n%s";
93+
msgs[ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN] =
94+
"The following Working tree files would be overwritten by sparse checkout update:\n%s";
95+
msgs[ERROR_WOULD_LOSE_ORPHANED_REMOVED] =
96+
"The following Working tree files would be removed by sparse checkout update:\n%s";
97+
98+
opts->show_all_errors = 1;
99+
}
100+
53101
static void add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
54102
unsigned int set, unsigned int clear)
55103
{
@@ -77,12 +125,6 @@ static int add_rejected_path(struct unpack_trees_options *o,
77125
const char *path)
78126
{
79127
struct rejected_paths_list *newentry;
80-
int porcelain = o && (o)->msgs[e];
81-
/*
82-
* simply display the given error message if in plumbing mode
83-
*/
84-
if (!porcelain)
85-
o->show_all_errors = 0;
86128
if (!o->show_all_errors)
87129
return error(ERRORMSG(o, e), path);
88130

unpack-trees.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ enum unpack_trees_error_types {
2222
NB_UNPACK_TREES_ERROR_TYPES
2323
};
2424

25+
/*
26+
* Sets the list of user-friendly error messages to be used by the
27+
* command "cmd" (either merge or checkout), and show_all_errors to 1.
28+
*/
29+
void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
30+
const char *cmd);
31+
2532
struct rejected_paths_list {
2633
char *path;
2734
struct rejected_paths_list *next;

0 commit comments

Comments
 (0)