Thread (6 messages) flat view 6 messages, 3 authors, 2016-06-15

Re: Bogus error: Untracked working tree file '....' would be overwritten by merge. Aborting

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:50:03
Subsystem: the rest · Maintainer: Linus Torvalds

On Tue, Nov 16, 2010 at 11:26:19AM +0100, demerphq wrote:
The error in the subject line is generated if one has a git repo
checked out to a commit that adds a new file and one does something
like:

git reset HEAD^

and then a merge operation that involves going forward onto or past HEAD.

Why is this error generated when the file is *exactly* the same as the
file that would overwrite it?

Obviously it makes sense to throw this error when data would be lost,
but when they are identical what is the point?
Something like this may help. Completely untested but could be a
starting point. See [1] for a more generic case, where users just want
git it ignore updating worktree and go ahead.
-- 
Duy

[1] http://thread.gmane.org/gmane.comp.version-control.git/160568/focus=160725

-- 8< --
diff --git a/unpack-trees.c b/unpack-trees.c
index 803445a..f9451fc 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -980,6 +980,12 @@ static int same(struct cache_entry *a, struct cache_entry *b)
 }
 
 
+static int identical_content(struct cache_entry *ce, struct stat *st)
+{
+	unsigned char sha1[20];
+	return !index_path(sha1, ce->name, st, 0) && !hashcmp(sha1, ce->sha1);
+}
+
 /*
  * When a CE gets turned into an unmerged entry, we
  * want it to be up-to-date
@@ -1006,6 +1012,10 @@ static int verify_uptodate_1(struct cache_entry *ce,
 		 */
 		if (S_ISGITLINK(ce->ce_mode))
 			return 0;
+
+		if (identical_content(ce, &st))
+			return 0;
+
 		errno = 0;
 	}
 	if (errno == ENOENT)
@@ -1195,6 +1205,8 @@ static int verify_absent_1(struct cache_entry *ce,
 				return 0;
 		}
 
+		if (identical_content(ce, &st))
+			return 0;
 		return o->gently ? -1 :
 			add_rejected_path(o, error_type, ce->name);
 	}
-- 8< --
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help