Subject: Re: pulling the root commit overwrites untracked files without warning (1.7.2.3)

From: Clemens Buchacher <[email-masked]>
Date: Sun, 14 Nov 2010 22:34:53 +0100

Hi,

On Thu, Oct 21, 2010 at 04:18:19PM +0300, Gert Palok wrote:
> 
> On 1.7.2.3, pulling the root commit overwrites untracked files
>
> Minimal working example:                                                        
> $ git init wc1                                                                  
> $ cd wc1                                                                        
> $ echo a > a                                                                    
> $ git add a                                                                     
> $ git commit -m "added a"                                                       
> $ mkdir ../wc2                                                                  
> $ cd ../wc2                                                                     
> $ echo b > a                                                                    
> $ git init                                                                      
> $ git remote add origin ../wc1                                                  
> $ git pull origin master                                                        
> $ # expected: error: Untracked working tree file 'a' would be                   
> overwritten by merge.  Aborting                                                 
> $ # actual: no error                                                            
> $ cat a                                                                         
> $ # expected: b                                                                 
> $ # actual: a

I finally got a chance to look at this. Contrary to my initial
suspicion, it's not a problem with the merge algorithm at all. It
doesn't even do a merge.

Instead, git merge finds that it has no valid HEAD and therefore
does a hard reset, which obviously overwrites any files already
there.

Patch to follow.

Clemens