merge-recursive: add/add really is modify/modify with an empty base
Unify the handling for cases C (add/add) and D (modify/modify). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Dec 13, 2006 at 04:05 UTC
f953831e030d3ece7346bdb5c4fde4fde43c925e
2 files changed
+26
-30
merge-recursive.c
+15
-29
@@ -610,6 +610,12 @@ static void fill_mm(const unsigned char *sha1, mmfile_t *mm)
610
unsigned long size;
611
char type[20];
612
613
+ if (!hashcmp(sha1, null_sha1)) {
614
+ mm->ptr = xstrdup("");
615
+ mm->size = 0;
616
+ return;
617
+ }
618
+
619
mm->ptr = read_sha1_file(sha1, type, &size);
620
if (!mm->ptr || strcmp(type, blob_type))
621
die("unable to read blob object %s", sha1_to_hex(sha1));
@@ -1045,38 +1051,17 @@ static int process_entry(const char *path, struct stage_data *entry,
1051
output("Adding %s", path);
1052
update_file(1, sha, mode, path);
1053
}
1048
- } else if (!o_sha && a_sha && b_sha) {
1049
- /* Case C: Added in both (check for same permissions). */
1050
- if (sha_eq(a_sha, b_sha)) {
1051
- if (a_mode != b_mode) {
1052
- clean_merge = 0;
1053
- output("CONFLICT: File %s added identically in both branches, "
1054
- "but permissions conflict %06o->%06o",
1055
- path, a_mode, b_mode);
1056
- output("CONFLICT: adding with permission: %06o", a_mode);
1057
- update_file(0, a_sha, a_mode, path);
1058
- } else {
1059
- /* This case is handled by git-read-tree */
1060
- assert(0 && "This case must be handled by git-read-tree");
1061
- }
1062
- } else {
1063
- const char *new_path1, *new_path2;
1064
- clean_merge = 0;
1065
- new_path1 = unique_path(path, branch1);
1066
- new_path2 = unique_path(path, branch2);
1067
- output("CONFLICT (add/add): File %s added non-identically "
1068
- "in both branches. Adding as %s and %s instead.",
1069
- path, new_path1, new_path2);
1070
- remove_file(0, path, 0);
1071
- update_file(0, a_sha, a_mode, new_path1);
1072
- update_file(0, b_sha, b_mode, new_path2);
1073
- }
1074
-
1075
- } else if (o_sha && a_sha && b_sha) {
1054
+ } else if (a_sha && b_sha) {
1055
+ /* Case C: Added in both (check for same permissions) and */
1056
/* case D: Modified in both, but differently. */
1057
+ const char *reason = "content";
1058
struct merge_file_info mfi;
1059
struct diff_filespec o, a, b;
1060
1061
+ if (!o_sha) {
1062
+ reason = "add/add";
1063
+ o_sha = (unsigned char *)null_sha1;
1064
+ }
1065
output("Auto-merging %s", path);
1066
o.path = a.path = b.path = (char *)path;
1067
hashcpy(o.sha1, o_sha);
@@ -1093,7 +1078,8 @@ static int process_entry(const char *path, struct stage_data *entry,
1078
update_file(1, mfi.sha, mfi.mode, path);
1079
else {
1080
clean_merge = 0;
1096
- output("CONFLICT (content): Merge conflict in %s", path);
1081
+ output("CONFLICT (%s): Merge conflict in %s",
1082
+ reason, path);
1083
1084
if (index_only)
1085
update_file(0, mfi.sha, mfi.mode, path);
t/t6024-recursive-merge.sh
+11
-1
@@ -58,9 +58,19 @@ GIT_AUTHOR_DATE="2006-12-12 23:00:08" git commit -m F
58
59
test_expect_failure "combined merge conflicts" "git merge -m final G"
60
61
+cat > expect << EOF
62
+<<<<<<< HEAD/a1
63
+F
64
+=======
65
+G
66
+>>>>>>> 26f86b677eb03d4d956dbe108b29cb77061c1e73/a1
67
+EOF
68
+
69
+test_expect_success "result contains a conflict" "diff -u expect a1"
70
+
71
git ls-files --stage > out
72
cat > expect << EOF
63
-100644 f70f10e4db19068f79bc43844b49f3eece45c4e8 1 a1
73
+100644 f16f906ab60483c100d1241dfc39868de9ec9fcb 1 a1
74
100644 cf84443e49e1b366fac938711ddf4be2d4d1d9e9 2 a1
75
100644 fd7923529855d0b274795ae3349c5e0438333979 3 a1
76
EOF