Skip to content

Commit baa37bf

Browse files
dturner-twgitster
authored andcommitted
mv: allow renaming to fix case on case insensitive filesystems
"git mv hello.txt Hello.txt" on a case insensitive filesystem always triggers "destination already exists" error, because these two names refer to the same path from the filesystem's point of view, and requires the user to give "--force" when correcting the case of the path recorded in the index and in the next commit. Detect this case and allow it without requiring "--force". Signed-off-by: David Turner <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ae352c7 commit baa37bf

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

builtin/mv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
202202
}
203203
} else if (cache_name_pos(src, length) < 0)
204204
bad = _("not under version control");
205-
else if (lstat(dst, &st) == 0) {
205+
else if (lstat(dst, &st) == 0 &&
206+
(!ignore_case || strcasecmp(src, dst))) {
206207
bad = _("destination exists");
207208
if (force) {
208209
/*

t/t6039-merge-ignorecase.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test_expect_success 'merge with case-changing rename on both sides' '
3535
git reset --hard baseline &&
3636
git branch -D with-camel &&
3737
git checkout -b with-camel &&
38-
git mv --force TestCase testcase &&
38+
git mv TestCase testcase &&
3939
git commit -m "recase on branch" &&
4040
>foo &&
4141
git add foo &&

0 commit comments

Comments
 (0)