[PATCH] git-mv: fix git mv bug with case insensitive fs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Fix git mv to not assert when src is already in the index under a
different casing, core.caseInsensitive=true, and the file system
is case insensitive.

Since 9b906af657 the check that git mv does to ensure the src is in the
cache respects caseInsensitive. As a result git mv allows a move from a
file that has a different case in the index than it does on disk. 
After the rename on disk, git mv fails to find the file in the cache
in order to rename it in the index, and asserts.
Assertion failed: pos >= 0, file builtin/mv.c, line 295

This is the simplest possible fix, suggested by @tboegi. It does leave
the file renamed on disk, but that is easy to reverse after the error.

Another option would be to change the aforementioned check to always
be case sensitive, but I am not sure whether there is a scenario where
it is useful to be insensitive.

Signed-off-by: Dan Moseley <danmose@xxxxxxxxxxxxx>
---
Originally reported in https://github.com/git-for-windows/git/issues/2920
but this is not specific to Windows.

 builtin/mv.c  | 6 ++++--
 t/t7001-mv.sh | 8 ++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/builtin/mv.c b/builtin/mv.c index 7dac714af9..e1fd8a5e00 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -292,8 +292,10 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
                        continue;

                pos = cache_name_pos(src, strlen(src));
-               assert(pos >= 0);
-               rename_cache_entry_at(pos, dst);
+               if (pos >= 0)
+                       rename_cache_entry_at(pos, dst);
+               else if (!ignore_errors)
+                       die(_("bad source: source=%s, destination=%s"), 
+ src, dst);
        }

        if (gitmodules_modified)
diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 63d5f41a12..5c7fee9bd8 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -152,6 +152,14 @@ test_expect_success \
     'move into "."' \
     'git mv path1/path2/ .'

+test_expect_success \
+    'fail to move file already in index under different cased name' \
+    'echo 1 > foo &&
+     git add foo &&
+     git commit -m add_file -- foo &&
+     git mv foo FOO &&
+     test_expect_code 128 git mv foo BAR'
+
 test_expect_success "Michael Cassar's test case" '
        rm -fr .git papers partA &&
        git init &&
--
2.25.1





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux