|
15 | 15 | #include "hex.h" |
16 | 16 | #include "hook.h" |
17 | 17 | #include "merge-ll.h" |
| 18 | +#include "merge.h" |
18 | 19 | #include "lockfile.h" |
19 | 20 | #include "mem-pool.h" |
20 | 21 | #include "merge-ort-wrappers.h" |
@@ -263,6 +264,7 @@ static int checkout_merged(int pos, const struct checkout *state, |
263 | 264 | struct cache_entry *ce = the_repository->index->cache[pos]; |
264 | 265 | const char *path = ce->name; |
265 | 266 | mmfile_t ancestor, ours, theirs; |
| 267 | + char *base_label, *ours_label, *theirs_label; |
266 | 268 | enum ll_merge_result merge_status; |
267 | 269 | int status; |
268 | 270 | struct object_id oid; |
@@ -293,10 +295,19 @@ static int checkout_merged(int pos, const struct checkout *state, |
293 | 295 |
|
294 | 296 | git_config_get_bool("merge.renormalize", &renormalize); |
295 | 297 | ll_opts.renormalize = renormalize; |
| 298 | + if (read_merge_labels(the_repository, &base_label, &ours_label, |
| 299 | + &theirs_label)) { |
| 300 | + base_label = xstrdup("base"); |
| 301 | + ours_label = xstrdup("ours"); |
| 302 | + theirs_label = xstrdup("theirs"); |
| 303 | + } |
296 | 304 | ll_opts.conflict_style = conflict_style; |
297 | | - merge_status = ll_merge(&result_buf, path, &ancestor, "base", |
298 | | - &ours, "ours", &theirs, "theirs", |
| 305 | + merge_status = ll_merge(&result_buf, path, &ancestor, base_label, |
| 306 | + &ours, ours_label, &theirs, theirs_label, |
299 | 307 | state->istate, &ll_opts); |
| 308 | + free(base_label); |
| 309 | + free(ours_label); |
| 310 | + free(theirs_label); |
300 | 311 | free(ancestor.ptr); |
301 | 312 | free(ours.ptr); |
302 | 313 | free(theirs.ptr); |
@@ -692,6 +703,7 @@ static void describe_detached_head(const char *msg, struct commit *commit) |
692 | 703 | } |
693 | 704 |
|
694 | 705 | #define ERROR_FLAG_WRITEOUT (1u << 0) |
| 706 | +#define ERROR_FLAG_CONFLICTS (1u << 1) |
695 | 707 |
|
696 | 708 | static int reset_tree(struct tree *tree, const struct checkout_opts *o, |
697 | 709 | int worktree, unsigned int *error_flags, |
@@ -916,6 +928,8 @@ static int merge_working_tree(const struct checkout_opts *opts, |
916 | 928 | old_tree); |
917 | 929 | if (ret < 0) |
918 | 930 | exit(128); |
| 931 | + if (!ret) |
| 932 | + *error_flags |= ERROR_FLAG_CONFLICTS; |
919 | 933 | ret = reset_tree(new_tree, |
920 | 934 | opts, 0, |
921 | 935 | error_flags, new_branch_info); |
@@ -951,10 +965,13 @@ static void report_tracking(struct branch_info *new_branch_info) |
951 | 965 |
|
952 | 966 | static void update_refs_for_switch(const struct checkout_opts *opts, |
953 | 967 | struct branch_info *old_branch_info, |
954 | | - struct branch_info *new_branch_info) |
| 968 | + struct branch_info *new_branch_info, |
| 969 | + int merge_conflicts) |
955 | 970 | { |
956 | 971 | struct strbuf msg = STRBUF_INIT; |
957 | 972 | const char *old_desc, *reflog_msg; |
| 973 | + unsigned flags = 0; |
| 974 | + |
958 | 975 | if (opts->new_branch) { |
959 | 976 | if (opts->new_orphan_branch) { |
960 | 977 | enum log_refs_config log_all_ref_updates = |
@@ -1046,7 +1063,11 @@ static void update_refs_for_switch(const struct checkout_opts *opts, |
1046 | 1063 | old_branch_info->path); |
1047 | 1064 | } |
1048 | 1065 | } |
1049 | | - remove_branch_state(the_repository, !opts->quiet); |
| 1066 | + if (!opts->quiet) |
| 1067 | + flags |= REMOVE_BRANCH_STATE_VERBOSE; |
| 1068 | + if (merge_conflicts) |
| 1069 | + flags |= REMOVE_BRANCH_STATE_PRESERVE_CONFLICT_LABELS; |
| 1070 | + remove_branch_state(the_repository, flags); |
1050 | 1071 | strbuf_release(&msg); |
1051 | 1072 | if (!opts->quiet && |
1052 | 1073 | !opts->force_detach && |
@@ -1218,12 +1239,13 @@ static int switch_branches(const struct checkout_opts *opts, |
1218 | 1239 | if (!opts->quiet && !old_branch_info.path && old_branch_info.commit && new_branch_info->commit != old_branch_info.commit) |
1219 | 1240 | orphaned_commit_warning(old_branch_info.commit, new_branch_info->commit); |
1220 | 1241 |
|
1221 | | - update_refs_for_switch(opts, &old_branch_info, new_branch_info); |
| 1242 | + update_refs_for_switch(opts, &old_branch_info, new_branch_info, |
| 1243 | + !!(error_flags & ERROR_FLAG_CONFLICTS)); |
1222 | 1244 |
|
1223 | 1245 | ret = post_checkout_hook(old_branch_info.commit, new_branch_info->commit, 1); |
1224 | 1246 | branch_info_release(&old_branch_info); |
1225 | 1247 |
|
1226 | | - return ret || error_flags; |
| 1248 | + return ret || !!(error_flags & ~ERROR_FLAG_CONFLICTS); |
1227 | 1249 | } |
1228 | 1250 |
|
1229 | 1251 | static int git_checkout_config(const char *var, const char *value, |
|
0 commit comments