threads / discuss / 9928

Problem with merge when renaming

Subject: Problem with merge when renaming

## tl;dr

7 messages between Sep 18, 2007 and Sep 19, 2007.

replies: 6people: 4as markdown or json

David Euresti· Sep 18, 2007, 20:34 UTC · lore
Hi,

I think I found a problem when you move a file into a directory of the same name. Here's what I did.

In a repository I created a directory with a file in it. Commit it. Then I move the file into a tmp name, make a directory with that name, and move it into the directory. git-mv dir/foo dir/foo.bin mkdir dir/foo git-mv dir/foo.bin dir/foo/foo.bin

Then in another branch I make a completely unrelated change. I create a file in another directory.

If I try to merge in the changes from the other branch or if the other branch tries to merge in these changes I get this error:

dir/foo/foo.bin: unmerged (257cc5642cb1a054f08cc83f2d943e56fd3ebe99) fatal: git-write-tree: error building trees Merge with strategy recursive failed.

This is the script I've been using #!/bin/bash #

# Make sure it's all clean rm -rf git-repo

mkdir git-repo pushd git-repo git-init mkdir dir git-add dir pushd dir echo foo > foo git-add foo popd git-commit -a -m "one" popd

# Developer A moves file into dir of same name pushd git-repo git-checkout -b branch-a git-mv dir/foo dir/foo.bin mkdir dir/foo git-mv dir/foo.bin dir/foo/foo.bin git-commit -a -m "File renamed" git-checkout master popd

# Developer B makes completely unrelated changes. pushd git-repo git-checkout -b branch-b echo baz > foo.txt echo bar > bar.txt git-add bar.txt git-add foo.txt git-commit -a -m "unrelated changes" git-checkout master popd

# Developer A wants to merge changes from B pushd git-repo #git-merge branch-a echo #git-merge branch-b #popd

Alex Riesen· Sep 18, 2007, 22:12 UTC · re: David Euresti · lore

[PATCH] Extend t6020 with another test for d/f interactions

A test for a merge when one of the trees has a file moved into a directory with the same name (not just file replaced by a directory).

The problem noticed and reported by David Euresti
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
 t/t6020-merge-df.sh |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
David Euresti, Tue, Sep 18, 2007 22:34:53 +0200:
Show 6 quoted lines
> If I try to merge in the changes from the other branch or if the other
> branch tries to merge in these changes I get this error:
> 
> dir/foo/foo.bin: unmerged (257cc5642cb1a054f08cc83f2d943e56fd3ebe99)
> fatal: git-write-tree: error building trees
> Merge with strategy recursive failed.

I extended the d/f merge test with the case. Have no idea how to fix it yet though.

diff --git a/t/t6020-merge-df.sh b/t/t6020-merge-df.sh
index a19d49d..c081d3f 100755
--- a/t/t6020-merge-df.sh
+++ b/t/t6020-merge-df.sh
@@ -10,6 +10,7 @@ test_expect_success 'prepare repository' \
 'echo "Hello" > init &&
 git add init &&
 git commit -m "Initial commit" &&
+git branch init &&
 git branch B &&
 mkdir dir &&
 echo "foo" > dir/foo &&
@@ -22,4 +23,20 @@ git commit -m "File: dir"'
 
 test_expect_code 1 'Merge with d/f conflicts' 'git merge "merge msg" B master'
 
+test_expect_success 'file moved into a dir of same name' '
+    git reset --hard &&
+    git checkout -b d1 init &&
+    mkdir dir &&
+    mv init dir/init &&
+    mv dir init &&
+    git add . &&
+    git commit -a -m"init moved into init/init" &&
+    git checkout -b d2 init &&
+    echo file >file &&
+    git add file &&
+    git commit -m"unrelated change" &&
+    git checkout d1 &&
+    git merge d2
+'
+
 test_done
-- 
1.5.3.1.173.g9a67
Junio C Hamano· Sep 18, 2007, 22:28 UTC · re: David Euresti · lore

Re: Problem with merge when renaming

"David Euresti" <evelio@gmail.com> writes:
> I think I found a problem when you move a file into a directory of the
> same name.  Here's what I did.
Two questions.
 (1) git --version?
 (2) if you do "git merge -s resolve" instead of just "git
     merge", do you see a difference?
David Euresti· Sep 18, 2007, 22:42 UTC · re: Junio C Hamano · lore

Re: Problem with merge when renaming

1) git version 1.5.2.5 and 1.5.3.1.139.g9346b

2) $ git-merge -s resolve branch-a $ git-merge -s resolve branch-b Trying really trivial in-index merge... fatal: Merge requires file-level merging Nope. Trying simple merge. Simple merge failed, trying Automatic merge. fatal: merge program failed Automatic merge failed; fix conflicts and then commit the result.

$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: bar.txt # new file: foo.txt # # Changed but not updated: # (use "git add <file>..." to update what will be committed) # # unmerged: dir/foo # unmerged: dir/foo/foo.bin # modified: dir/foo/foo.bin #

But if I do it in the other order I get this:
$ git-merge -s resolve branch-b
$ git-merge -s resolve branch-a
Trying really trivial in-index merge...
fatal: Merge requires file-level merging
Nope.
Trying simple merge.
Simple merge failed, trying Automatic merge.
Removing dir/foo
Adding dir/foo/foo.bin
ERROR: untracked dir/foo/foo.bin is overwritten by the merge.
fatal: merge program failed
Automatic merge failed; fix conflicts and then commit the result.

deuresti@deuresti-lnx /tmp/scm-rename-test/git-repo $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # deleted: dir/foo # # Changed but not updated: # (use "git add <file>..." to update what will be committed) # # unmerged: dir/foo/foo.bin #

Thanks, David On 9/18/07, Junio C Hamano <gitster@pobox.com> wrote:

Show 12 quoted lines
> "David Euresti" <evelio@gmail.com> writes:
>
> > I think I found a problem when you move a file into a directory of the
> > same name.  Here's what I did.
>
> Two questions.
>
>  (1) git --version?
>
>  (2) if you do "git merge -s resolve" instead of just "git
>      merge", do you see a difference?
>
Alex Riesen· Sep 18, 2007, 22:44 UTC · re: Junio C Hamano · lore

Re: Problem with merge when renaming

Junio C Hamano, Wed, Sep 19, 2007 00:28:39 +0200:
Show 8 quoted lines
> "David Euresti" <evelio@gmail.com> writes:
> 
> > I think I found a problem when you move a file into a directory of the
> > same name.  Here's what I did.
> 
> Two questions.
> 
>  (1) git --version?
it happens with very recent git (as of today)
>  (2) if you do "git merge -s resolve" instead of just "git
>      merge", do you see a difference?
yes: it has more error output.

Trying really trivial in-index merge... warning: Merge requires file-level merging Nope, a really trivial in-index merge not possible Trying simple merge. Simple merge failed, trying Automatic merge. error: init: is a directory - add individual files instead fatal: Unable to process path init fatal: merge program failed Automatic merge failed; fix conflicts and then commit the result.

Junio C Hamano· Sep 18, 2007, 23:27 UTC · re: Alex Riesen · lore

Re: Problem with merge when renaming

Alex Riesen <raa.lkml@gmail.com> writes:
Show 26 quoted lines
> Junio C Hamano, Wed, Sep 19, 2007 00:28:39 +0200:
>> "David Euresti" <evelio@gmail.com> writes:
>> 
>> > I think I found a problem when you move a file into a directory of the
>> > same name.  Here's what I did.
>> 
>> Two questions.
>> 
>>  (1) git --version?
>
> it happens with very recent git (as of today)
>
>>  (2) if you do "git merge -s resolve" instead of just "git
>>      merge", do you see a difference?
>
> yes: it has more error output.
>
> Trying really trivial in-index merge...
> warning: Merge requires file-level merging
> Nope, a really trivial in-index merge not possible
> Trying simple merge.
> Simple merge failed, trying Automatic merge.
> error: init: is a directory - add individual files instead
> fatal: Unable to process path init
> fatal: merge program failed
> Automatic merge failed; fix conflicts and then commit the result.
Isn't this the same as the known issue here?
	<http://permalink.gmane.org/gmane.comp.version-control.git/53402>
Alex Riesen· Sep 19, 2007, 21:11 UTC · re: Junio C Hamano · lore

Re: Problem with merge when renaming

Junio C Hamano, Wed, Sep 19, 2007 01:27:01 +0200:
Show 21 quoted lines
> > it happens with very recent git (as of today)
> >
> >>  (2) if you do "git merge -s resolve" instead of just "git
> >>      merge", do you see a difference?
> >
> > yes: it has more error output.
> >
> > Trying really trivial in-index merge...
> > warning: Merge requires file-level merging
> > Nope, a really trivial in-index merge not possible
> > Trying simple merge.
> > Simple merge failed, trying Automatic merge.
> > error: init: is a directory - add individual files instead
> > fatal: Unable to process path init
> > fatal: merge program failed
> > Automatic merge failed; fix conflicts and then commit the result.
> 
> Isn't this the same as the known issue here?
> 
> 	<http://permalink.gmane.org/gmane.comp.version-control.git/53402>
> 
Yes, looks similar:
    .../git/t$ ./t3031-df-3way.sh -d -v -i
    ...
    Created commit 992a330: side moves and makes changes
     6 files changed, 155 insertions(+), 153 deletions(-)
     create mode 100644 D
     create mode 100644 D.A
     delete mode 100644 D/A
     delete mode 100644 D/B
     delete mode 100644 D/C
     create mode 100644 D0C
    *   ok 1: setup
    * expecting success: 
	    git read-tree -m initial side master
    fatal: Entry 'D/A' would be overwritten by merge. Cannot merge.
    * FAIL 2: threeway
		    git read-tree -m initial side master
    .../git/t$

← back to recent threads