merge-recursive: adjust to loosened "working file clobbered" check
The three-way merge by git-read-tree does not complain about presense of the file in the working tree that is involved in a merge when the merge result needs to be determined by the caller. Adjust merge-recursive so that it makes sure that an untracked file is not touched when the merge decides the path should not be included in the final result. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Oct 27, 2006 at 14:08 UTC
65ac6e9c3f47807cb603af07a6a9e1a43bc119ae
1 file changed
+20
-21
merge-recursive.c
+20
-21
@@ -469,10 +469,10 @@ static int remove_path(const char *name)
469
return ret;
470
}
471
472
-static int remove_file(int clean, const char *path)
472
+static int remove_file(int clean, const char *path, int no_wd)
473
{
474
int update_cache = index_only || clean;
475
- int update_working_directory = !index_only;
475
+ int update_working_directory = !index_only && !no_wd;
476
477
if (update_cache) {
478
if (!cache_dirty)
@@ -481,8 +481,7 @@ static int remove_file(int clean, const char *path)
481
if (remove_file_from_cache(path))
482
return -1;
483
}
484
- if (update_working_directory)
485
- {
484
+ if (update_working_directory) {
485
unlink(path);
486
if (errno != ENOENT || errno != EISDIR)
487
return -1;
@@ -725,13 +724,13 @@ static void conflict_rename_rename(struct rename *ren1,
724
dst_name1 = del[delp++] = unique_path(ren1_dst, branch1);
725
output("%s is a directory in %s adding as %s instead",
726
ren1_dst, branch2, dst_name1);
728
- remove_file(0, ren1_dst);
727
+ remove_file(0, ren1_dst, 0);
728
}
729
if (path_list_has_path(¤t_directory_set, ren2_dst)) {
730
dst_name2 = del[delp++] = unique_path(ren2_dst, branch2);
731
output("%s is a directory in %s adding as %s instead",
732
ren2_dst, branch1, dst_name2);
734
- remove_file(0, ren2_dst);
733
+ remove_file(0, ren2_dst, 0);
734
}
735
update_stages(dst_name1, NULL, ren1->pair->two, NULL, 1);
736
update_stages(dst_name2, NULL, NULL, ren2->pair->two, 1);
@@ -744,7 +743,7 @@ static void conflict_rename_dir(struct rename *ren1,
743
{
744
char *new_path = unique_path(ren1->pair->two->path, branch1);
745
output("Renaming %s to %s instead", ren1->pair->one->path, new_path);
747
- remove_file(0, ren1->pair->two->path);
746
+ remove_file(0, ren1->pair->two->path, 0);
747
update_file(0, ren1->pair->two->sha1, ren1->pair->two->mode, new_path);
748
free(new_path);
749
}
@@ -759,7 +758,7 @@ static void conflict_rename_rename_2(struct rename *ren1,
758
output("Renaming %s to %s and %s to %s instead",
759
ren1->pair->one->path, new_path1,
760
ren2->pair->one->path, new_path2);
762
- remove_file(0, ren1->pair->two->path);
761
+ remove_file(0, ren1->pair->two->path, 0);
762
update_file(0, ren1->pair->two->sha1, ren1->pair->two->mode, new_path1);
763
update_file(0, ren2->pair->two->sha1, ren2->pair->two->mode, new_path2);
764
free(new_path2);
@@ -857,7 +856,7 @@ static int process_renames(struct path_list *a_renames,
856
conflict_rename_rename(ren1, branch1, ren2, branch2);
857
} else {
858
struct merge_file_info mfi;
860
- remove_file(1, ren1_src);
859
+ remove_file(1, ren1_src, 1);
860
mfi = merge_file(ren1->pair->one,
861
ren1->pair->two,
862
ren2->pair->two,
@@ -890,7 +889,7 @@ static int process_renames(struct path_list *a_renames,
889
struct diff_filespec src_other, dst_other;
890
int try_merge, stage = a_renames == renames1 ? 3: 2;
891
893
- remove_file(1, ren1_src);
892
+ remove_file(1, ren1_src, 1);
893
894
hashcpy(src_other.sha1, ren1->src_entry->stages[stage].sha);
895
src_other.mode = ren1->src_entry->stages[stage].mode;
@@ -1008,7 +1007,8 @@ static int process_entry(const char *path, struct stage_data *entry,
1007
* unchanged in the other */
1008
if (a_sha)
1009
output("Removing %s", path);
1011
- remove_file(1, path);
1010
+ /* do not touch working file if it did not exist */
1011
+ remove_file(1, path, !a_sha);
1012
} else {
1013
/* Deleted in one and changed in the other */
1014
clean_merge = 0;
@@ -1055,7 +1055,7 @@ static int process_entry(const char *path, struct stage_data *entry,
1055
output("CONFLICT (%s): There is a directory with name %s in %s. "
1056
"Adding %s as %s",
1057
conf, path, other_branch, path, new_path);
1058
- remove_file(0, path);
1058
+ remove_file(0, path, 0);
1059
update_file(0, sha, mode, new_path);
1060
} else {
1061
output("Adding %s", path);
@@ -1083,7 +1083,7 @@ static int process_entry(const char *path, struct stage_data *entry,
1083
output("CONFLICT (add/add): File %s added non-identically "
1084
"in both branches. Adding as %s and %s instead.",
1085
path, new_path1, new_path2);
1086
- remove_file(0, path);
1086
+ remove_file(0, path, 0);
1087
update_file(0, a_sha, a_mode, new_path1);
1088
update_file(0, b_sha, b_mode, new_path2);
1089
}
@@ -1205,14 +1205,13 @@ static struct commit_list *reverse_commit_list(struct commit_list *list)
1205
* Merge the commits h1 and h2, return the resulting virtual
1206
* commit object and a flag indicating the cleaness of the merge.
1207
*/
1208
-static
1209
-int merge(struct commit *h1,
1210
- struct commit *h2,
1211
- const char *branch1,
1212
- const char *branch2,
1213
- int call_depth /* =0 */,
1214
- struct commit *ancestor /* =None */,
1215
- struct commit **result)
1208
+static int merge(struct commit *h1,
1209
+ struct commit *h2,
1210
+ const char *branch1,
1211
+ const char *branch2,
1212
+ int call_depth /* =0 */,
1213
+ struct commit *ancestor /* =None */,
1214
+ struct commit **result)
1215
{
1216
struct commit_list *ca = NULL, *iter;
1217
struct commit *merged_common_ancestors;