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

Re: [PATCH] Fix rebase with file move when diff.renames = copies

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jul 22, 2010, 07:51 UTC
Message-ID
<20100722075133.GA9292@burratino>
In-Reply-To
<1279742303-29817-1-git-send-email-ddkilzer@kilzer.net>
David D. Kilzer wrote:
Show 7 quoted lines
> With diff.renames = copies, a rebase with a file move will fail with
> the following error:
>
>     fatal: mode change for <file>, which is not in current HEAD
>     Repository lacks necessary blobs to fall back on 3-way merge.
>     Cannot fall back to three-way merge.
>     Patch failed at 0001.
I would think that the following works fine:
	git init test-repo &&
	cd test-repo &&
	echo hello >greeting.txt &&
	git add greeting.txt &&
	git commit -m base &&
	git checkout -b move &&
	git mv greeting.txt moved.txt &&
	git commit -m move &&
	git checkout master &&
	echo hi >greeting.txt &&
	git add greeting.txt &&
	git commit -m change &&
	git checkout move &&
	echo '[diff] renames = copies' >>.git/config &&
	git rebase master
What am I doing wrong?

On the other hand I find Junio’s explanation[1] compelling already on its own.

 The end user configuration for "diff" should not affect the
 result produced by the higher level command that is related to
 "diff" only because internally it is implemented in terms of
 it.

In cases where a patch copies a file that was then removed on the mainline, my intuition says ‘rebase’ without some extra flag should accept the change without complaint. Of course, this intuition is totally warped --- I tend to think of rebase as diff + apply.

Patch does not apply to master or maint, due to conflict with v1.7.1-rc0~37^2~5 (rebase: support automatic notes copying, 2010-03-12). One sneaky way to avoid this kind of thing would be to insert new tests at some logical point in the middle of a test script.

Test nitpicks:
Show 7 quoted lines
> +++ b/t/t3400-rebase.sh
> @@ -155,4 +155,21 @@ test_expect_success 'Rebase a commit that sprinkles CRs in' '
>  	git diff --exit-code file-with-cr:CR HEAD:CR
>  '
>  
> +test_expect_success 'rebase a single file move with diff.renames = copies' '
> +     git config diff.renames copies &&
Use
	test_when_finished "git config --unset diff.renames" &&
to shelter future tests from the effect of this one.
Show 5 quoted lines
> +     git checkout master &&
> +     echo 1 > Y &&
> +     git add Y &&
> +     test_tick &&
> +     git commit -m "prepare file move" &&
commit: new file Y.
Show 7 quoted lines
> +     git checkout -b filemove HEAD^ &&
> +     echo 1 > Y &&
> +     git add Y &&
> +     mkdir D &&
> +     git mv A D/A &&
> +     test_tick &&
> +     git commit -m filemove &&
commit: new file Y, rename A to D/A.
> +     GIT_TRACE=1 git rebase master

This wants to notice that Y was already added so the top patch can be simplified to include only a rename.

Can you explain why this test will fail without your patch?

Thanks, Jonathan

[1] http://thread.gmane.org/gmane.comp.version-control.git/100583/focus=100606
Previous: David D. KilzerNext: David D. Kilzer
Message 10 of 22 in “3-way merge with file move fails when diff.renames = copies”
  1. 3-way merge with file move fails when diff.renames = copiesDavid D. Kilzer, Nov 10, 2008
  2. Johannes SchindelinNov 10, 2008
  3. Fix 3-way merge with file move when diff.renames = copiesDavid D. Kilzer, Nov 10, 2008
  4. Junio C HamanoNov 10, 2008
  5. David D. KilzerNov 11, 2008
  6. Junio C HamanoNov 11, 2008
  7. Fix rebase with file move when diff.renames = copiesDavid D. Kilzer, Jul 21, 2010
  8. Junio C HamanoJul 21, 2010
  9. David D. KilzerJul 22, 2010
  10. Jonathan NiederJul 22, 2010
  11. David D. KilzerJul 22, 2010
  12. 0/5 Fix rebase with file move when diff.renames = copiesJonathan Nieder, Jul 23, 2010
  13. 1/5 t4150 (am): style tweaksJonathan Nieder, Jul 23, 2010
  14. 2/5 t4150 (am): futureproof against failing testsJonathan Nieder, Jul 23, 2010
  15. 3/5 Teach "apply --index-info" to handle rename patchesJonathan Nieder, Jul 23, 2010
  16. 4/5 t3400 (rebase): whitespace cleanupJonathan Nieder, Jul 23, 2010
  17. 5/5 rebase: protect against diff.renames configurationJonathan Nieder, Jul 23, 2010
  18. Sverre RabbelierJul 23, 2010
  19. Junio C HamanoJul 23, 2010
  20. Sverre RabbelierJul 23, 2010
  21. David D. KilzerJul 23, 2010
  22. Jonathan NiederJul 24, 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.