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

Re: "fatal: Untracked working tree file 'so-and-so' would be overwritten by merge"

From
Linus Torvalds <torvalds@osdl.org>
Date
Oct 9, 2006, 16:03 UTC
Message-ID
<Pine.LNX.4.64.0610090858120.3952@g5.osdl.org>
In-Reply-To
<7vodsmdq0m.fsf@assigned-by-dhcp.cox.net>
On Sun, 8 Oct 2006, Junio C Hamano wrote:
Show 6 quoted lines
> 
> Note note note.  The above patch alone leaves merge risky to
> remove an untracked working tree files, and needs to be
> compensated by corresponding checks to the git-merge-xxx
> strategies.  The original code was overcautious, but was
> protecting valid cases too.

I think the difference _should_ be that we only remove the local file if it was removed _remotely_.

In that case, it was there in the original tree, and removing it is correct.

> diff --git a/git-merge-one-file.sh b/git-merge-one-file.sh index 
> fba4b0c..25aedb7 100755 --- a/git-merge-one-file.sh +++ 
> b/git-merge-one-file.sh @@ -23,6 +23,9 @@ #
>  "$1.." | "$1.$1" | "$1$1.")

So I actually think that we should NOT consider these three cases to be the same.

There are really two distinct cases:
 - "$1.." and "$1.$1"
	The file had already been removed locally, AND WE SHOULD NOT TOUCH 
	IT.
 - "$1$1.":
	The file was removed remotely, and we SHOULD remove it locally.
In fact, we already have that as a "special case":
Show 8 quoted lines
>  	if [ "$2" ]; then
>  		echo "Removing $4"
> +	elif test -f "$4"
> +		echo "ERROR: untracked $4 is removed by the merge."
> +		exit 1
>  	fi
>  	if test -f "$4"; then
>  		rm -f -- "$4" &&
That
	if [ "$2" ]; then
		echo "Removing $4"

is _exactly_ that case: it is the "$1$1." case, and we already treat it differently, but we actually treat it differently the wrong way: we only print out the message for that case, but the actual "touch working tree" code should _also_ be affected.

If the local index doesn't change, we should not print out the "Removing 'so-and-so'" message, but we should also not even _touch_ that file, because it was already "gone" as far as the local tree was concerned.

Agreed?
		Linus
Previous: Luben TuikovNext: Junio C Hamano
Message 10 of 12 in “"fatal: Untracked working tree file 'so-and-so' would be overwritten by merge"”
  1. Linus TorvaldsOct 9, 2006
  2. Junio C HamanoOct 9, 2006
  3. Junio C HamanoOct 9, 2006
  4. merge: loosen overcautious "working file will be lost" check.Junio C Hamano, Oct 9, 2006
  5. Luben TuikovOct 9, 2006
  6. Junio C HamanoOct 9, 2006
  7. Luben TuikovOct 10, 2006
  8. Junio C HamanoOct 10, 2006
  9. Luben TuikovOct 10, 2006
  10. Linus TorvaldsOct 9, 2006
  11. Junio C HamanoOct 9, 2006
  12. Junio C HamanoOct 10, 2006

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.