merge-recursive: handle D/F conflict case more carefully.
When a path D that originally was blob in the ancestor was modified on our branch while it was removed on the other branch, we keep stages 1 and 2, and leave our version in the working tree. If the other branch created a path D/F, however, that path can cleanly be resolved in the index (after all, the ancestor nor we do not have it and only the other side added), but it cannot be checked out. The issue is the same when the other branch had D and we had renamed it to D/F, or the ancestor had D/F instead of D (so there are four combinations). Do not stop the merge, but leave both D and D/F paths in the index so that the user can clear things up. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Apr 7, 2007 at 06:41 UTC
4d50895a390658bf1b9a9385dbc0b9f90b48c803
1 file changed
+26
-3
merge-recursive.c
+26
-3
@@ -596,9 +596,31 @@ static void update_file_flags(const unsigned char *sha,
596
597
if (S_ISREG(mode) || (!has_symlinks && S_ISLNK(mode))) {
598
int fd;
599
- if (mkdir_p(path, 0777))
600
- die("failed to create path %s: %s", path, strerror(errno));
601
- unlink(path);
599
+ int status;
600
+ const char *msg = "failed to create path '%s'%s";
601
+
602
+ status = mkdir_p(path, 0777);
603
+ if (status) {
604
+ if (status == -3) {
605
+ /* something else exists */
606
+ error(msg, path, ": perhaps a D/F conflict?");
607
+ update_wd = 0;
608
+ goto update_index;
609
+ }
610
+ die(msg, path, "");
611
+ }
612
+ if (unlink(path)) {
613
+ if (errno == EISDIR) {
614
+ /* something else exists */
615
+ error(msg, path, ": perhaps a D/F conflict?");
616
+ update_wd = 0;
617
+ goto update_index;
618
+ }
619
+ if (errno != ENOENT)
620
+ die("failed to unlink %s "
621
+ "in preparation to update: %s",
622
+ path, strerror(errno));
623
+ }
624
if (mode & 0100)
625
mode = 0777;
626
else
@@ -620,6 +642,7 @@ static void update_file_flags(const unsigned char *sha,
642
die("do not know what to do with %06o %s '%s'",
643
mode, sha1_to_hex(sha), path);
644
}
645
+ update_index:
646
if (update_cache)
647
add_cacheinfo(mode, sha, path, 0, update_wd, ADD_CACHE_OK_TO_ADD);
648
}