git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Nov 16, 2010, 11:24 UTC
Message-ID
<20101116112406.GA18259@do>
In-Reply-To
<AANLkTinv7XsXNR2MMbaGAUo2=WgL6SEWkuzwGU_7YVn0@mail.gmail.com>
On Tue, Nov 16, 2010 at 11:26:19AM +0100, demerphq wrote:
Show 13 quoted lines
> 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< --
Previous: demerphqNext: Nguyen Thai Ngoc Duy
Message 3 of 8 in “Bogus error: Untracked working tree file '....' would be overwritten by merge. Aborting”
  1. demerphqNov 16, 2010
  2. demerphqNov 16, 2010
  3. Nguyen Thai Ngoc DuyNov 16, 2010
  4. Nguyen Thai Ngoc DuyNov 16, 2010
  5. demerphqNov 17, 2010
  6. Ævar Arnfjörð BjarmasonNov 17, 2010
  7. Matthieu MoyNov 17, 2010
  8. Nguyen Thai Ngoc DuyNov 17, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.