diff options
author | Petr Baudis <pasky@suse.cz> | 2008-07-21 02:25:56 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-07-27 15:05:19 -0700 |
commit | 81dc2307d0ad87a4da2e753a9d1b5586d6456eed (patch) | |
tree | 1768cbb9f900c8bbb2be9f08d76bb3e88a703ca0 /t | |
parent | f6c52fe4e871d1d07cb7d86692ccf8cc4de54579 (diff) | |
download | git-81dc2307d0ad87a4da2e753a9d1b5586d6456eed.tar.gz git-81dc2307d0ad87a4da2e753a9d1b5586d6456eed.tar.xz |
git-mv: Keep moved index entries inact
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.
Also the code used to refuse renaming overwriting symlink with a regular
file and vice versa; there is no need for that.
A few new tests have been added to the testsuite to reflect this change.
Signed-off-by: Petr Baudis <pasky@suse.cz>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rwxr-xr-x | t/t7001-mv.sh | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 336cfaa1c..b0fa40782 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -156,4 +156,56 @@ test_expect_success 'absolute pathname outside should fail' '( )' +test_expect_success 'git mv should not change sha1 of moved cache entry' ' + + rm -fr .git && + git init && + echo 1 >dirty && + git add dirty && + entry="$(git ls-files --stage dirty | cut -f 1)" + git mv dirty dirty2 && + [ "$entry" = "$(git ls-files --stage dirty2 | cut -f 1)" ] && + echo 2 >dirty2 && + git mv dirty2 dirty && + [ "$entry" = "$(git ls-files --stage dirty | cut -f 1)" ] + +' + +rm -f dirty dirty2 + +test_expect_success 'git mv should overwrite symlink to a file' ' + + rm -fr .git && + git init && + echo 1 >moved && + ln -s moved symlink && + git add moved symlink && + test_must_fail git mv moved symlink && + git mv -f moved symlink && + ! test -e moved && + test -f symlink && + test "$(cat symlink)" = 1 && + git diff-files --quiet + +' + +rm -f moved symlink + +test_expect_success 'git mv should overwrite file with a symlink' ' + + rm -fr .git && + git init && + echo 1 >moved && + ln -s moved symlink && + git add moved symlink && + test_must_fail git mv symlink moved && + git mv -f symlink moved && + ! test -e symlink && + test -h moved && + git diff-files --quiet + +' + +rm -f moved symlink + test_done |