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

Re: [PATCHv2] git-mv: Keep moved index entries inact

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 26, 2008, 06:46 UTC
Message-ID
<7v8wvpm9cl.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20080721002508.26773.92277.stgit@localhost>
Petr Baudis <pasky@suse.cz> writes:
Show 14 quoted lines
> The rewrite of git-mv from a shell script to a builtin was perhaps
> a little too straightforward: the git add and git rm queues were
> emulated directly, which resulted in a rather complicated code and
> caused an inconsistent behaviour when moving dirty index entries;
> git mv would update the entry based on working tree state,
> except in case of overwrites, where the new entry would still have
> sha1 of the old file.
>
> This patch introduces rename_index_entry_at() into the index toolkit,
> which will rename an entry while removing any entries the new entry
> might render duplicate. This is then used in git mv instead
> of all the file queues, resulting in a major simplification
> of the code and an inevitable change in git mv -n output format.
> ...

Thanks. I think I've managed to fix the rename_index_entry_at() in a satisfactory way, and also made builtin-mv to allow "mv -f symlink file" and "mv -f file symlink".

I do not agree with the semantics of this test seems to want, though.
Show 17 quoted lines
> +test_expect_failure 'git mv should follow symlink to a directory' '
> +
> +	rm -fr .git &&
> +	git init &&
> +	echo 1 >moved &&
> +	mkdir -p dir &&
> +	touch dir/.keep &&
> +	ln -s dir symlink &&
> +	git add moved dir/.keep symlink &&
> +	git mv moved symlink &&
> +	[ ! -e moved ] &&
> +	[ -f symlink/moved ] &&
> +	[ $(cat symlink/moved) = 1 ] &&
> +	[ "$(ls dir)" = "$(ls symlink)" ] &&
> +	git diff-files --quiet
> +
> +'

A symlink to us is just a different kind of blob, and by definition a blob is the leaf level of a tree structure that represents the working tree in the index. There won't be anything hanging below it, and when adding things to the index we should not dereference the symlink to see where it leads to.

Traditionally we have been loose about this check, and the normal "git add" and "git update-index" codepath is still forever broken, and we allow:

	$ mkdir dir
        $ >dir/file
        $ ln -s dir symlink
        $ git add symlink/file
but some codepaths that matter more (because they do larger damage
unattended, as opposed to the above command sequence that can be avoided
by user education a bit more easily), such as "git apply" and "git
read-tree", have been corrected using has_symlink_leading_path() since mid
2007.  We would need to follow through c40641b (Optimize symlink/directory
detection, 2008-05-09) and further fix "git add" and "git update-index"
codepaths to forbid the above command sequence.
So my take on the above test piece is that after:
	>moved
	mkdir dir
        >dir/file
        ln -s dir symlink
	git add moved dir symlink
This should fail, as it is an overwrite:
	git mv moved symlink

and with "-f", the command should simply remove symlink and replace it with a regular file whose contents come from the original "moved".

IOW, what a symlink points at should not matter.
Previous: Junio C HamanoNext: Petr Baudis
Message 15 of 56 in “Submodule support in git mv, git rm”
  1. Petr BaudisJul 16, 2008
  2. 1/7 git-mv: Remove dead code branchPetr Baudis, Jul 16, 2008
  3. 2/7 t7400: Add short "git submodule add" testsuitePetr Baudis, Jul 16, 2008
  4. 3/7 git submodule add: Fix naming clash handlingPetr Baudis, Jul 16, 2008
  5. 4/7 submodule.*: Introduce simple C interface for submodule lookup by pathPetr Baudis, Jul 16, 2008
  6. 5/7 git mv: Support moving submodulesPetr Baudis, Jul 16, 2008
  7. Junio C HamanoJul 17, 2008
  8. Petr BaudisJul 17, 2008
  9. git-mv: Keep moved index entries inactPetr Baudis, Jul 17, 2008
  10. git mv: Support moving submodulesPetr Baudis, Jul 17, 2008
  11. Junio C HamanoJul 19, 2008
  12. Petr BaudisJul 21, 2008
  13. [PATCHv2] git-mv: Keep moved index entries inactPetr Baudis, Jul 21, 2008
  14. Junio C HamanoJul 21, 2008
  15. Junio C HamanoJul 26, 2008
  16. Petr BaudisJul 27, 2008
  17. t/t7001-mv.sh: Propose ability to use git-mv on conflicting entriesPetr Baudis, Jul 27, 2008
  18. Junio C HamanoJul 28, 2008
  19. Junio C HamanoJul 28, 2008
  20. SZEDER GáborJul 28, 2008
  21. Johannes SchindelinJul 28, 2008
  22. Johannes SchindelinJul 28, 2008
  23. Johannes SchindelinJul 28, 2008
  24. Junio C HamanoJul 28, 2008
  25. Johannes SchindelinJul 28, 2008
  26. Johannes SchindelinJul 28, 2008
  27. Petr BaudisJul 29, 2008
  28. Junio C HamanoJul 29, 2008
  29. Junio C HamanoJul 29, 2008
  30. Not going beyond symbolic linksJunio C Hamano, Aug 4, 2008
  31. 1/2 update-index: refuse to add working tree items beyond symlinksJunio C Hamano, Aug 4, 2008
  32. 2/2 add: refuse to add working tree items beyond symlinksJunio C Hamano, Aug 4, 2008
  33. Linus TorvaldsAug 5, 2008
  34. Junio C HamanoAug 5, 2008
  35. Linus TorvaldsAug 5, 2008
  36. Johannes SchindelinAug 5, 2008
  37. Linus TorvaldsAug 5, 2008
  38. Junio C HamanoAug 5, 2008
  39. Dmitry PotapovAug 5, 2008
  40. Junio C HamanoAug 5, 2008
  41. Linus TorvaldsAug 5, 2008
  42. Junio C HamanoAug 5, 2008
  43. Johannes SchindelinAug 5, 2008
  44. Junio C HamanoAug 5, 2008
  45. david@lang.hmAug 5, 2008
  46. Junio C HamanoAug 7, 2008
  47. Junio C HamanoAug 8, 2008
  48. Linus TorvaldsAug 8, 2008
  49. Johannes SchindelinJul 21, 2008
  50. Petr BaudisJul 21, 2008
  51. Junio C HamanoJul 21, 2008
  52. 6/7 git rm: Support for removing submodulesPetr Baudis, Jul 16, 2008
  53. Johannes SchindelinJul 16, 2008
  54. Petr BaudisJul 17, 2008
  55. Johannes SchindelinJul 17, 2008
  56. 7/7 t7403: Submodule git mv, git rm testsuitePetr Baudis, Jul 16, 2008

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.