git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: "Torsten Bögershausen" <tboegi@web.de>
To: Mark Amery <markrobertamery@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Bug: Changing folder case with `git mv` crashes on case-insensitive file system
Date: Tue, 4 May 2021 17:19:54 +0200	[thread overview]
Message-ID: <20210504151954.aczbvml4rh7t2svc@tb-raspi4> (raw)
In-Reply-To: <CAD8jeghpOQoibk0xM0QgLsOwLNw9GdM=4rhYuzV-NSkw8LinMQ@mail.gmail.com>

On Mon, May 03, 2021 at 06:25:43PM +0100, Mark Amery wrote:
> Attempting to change the case of a folder's name using a command like
> `git mv foo FOO` crashes on case-insensitive file systems, like the
> default APFS used on Apple Macs.
>
> Here are simple steps to repro this:
>
>     $ mkdir testrepo && cd testrepo && git init
>     Initialized empty Git repository in /Users/markamery/testrepo/.git/
>     $ mkdir foo && touch foo/bar && git add foo && git commit -m bla
>     [master (root-commit) a7e9f5f] bla
>     1 file changed, 0 insertions(+), 0 deletions(-)
>     create mode 100644 foo/bar
>     $ git mv foo FOO
>     fatal: renaming 'foo' failed: Invalid argument
>     $ echo $?
>     128
>     $ git status
>     On branch master
>     nothing to commit, working tree clean
>
> If I create a case-sensitive APFS volume using Disk Utility and try
> the commands above on that volume, `git mv foo FOO` works correctly:
> it emits no output, exits with a 0 status code, and stages a change
> renaming `foo/bar` to `FOO/bar`. However, on my main case-insensitive
> volume, `git mv` behaves as shown above: it exits with code 128,
> prints an "Invalid argument" error message, and does not stage any
> changes.
>
> The command still fails in the same way if you use `git mv --force`
> instead of just `git mv`.
>
> Note that previously, `git mv` could not change the case of *file*
> names on case-insensitive file systems, until that was fixed in commit
> https://github.com/git/git/commit/baa37bff9a845471754d3f47957d58a6ccc30058.
> I'm guessing there's a different code path that needs fixing for
> changing the case of *folders*.
>
> As far as I can tell, this error has never been reported to the Git
> mailing list, but it seems to be encountered frequently;
> https://stackoverflow.com/questions/3011625/git-mv-and-only-change-case-of-directory
> mentions this bug and has 86000 views.
>
> In case it's relevant, here's my system info as output by `git bugreport`:
>
>     [System Info]
>     git version:
>     git version 2.31.1
>     cpu: x86_64
>     no commit associated with this build
>     sizeof-long: 8
>     sizeof-size_t: 8
>     shell-path: /bin/sh
>     uname: Darwin 18.7.0 Darwin Kernel Version 18.7.0: Mon Apr 27
> 20:09:39 PDT 2020; root:xnu-4903.278.35~1/RELEASE_X86_64 x86_64
>     compiler info: clang: 11.0.0 (clang-1100.0.33.17)
>     libc info: no libc information available
>     $SHELL (typically, interactive shell): /bin/bash


Thanks for reporting - that's always good.

To my undestanding we try to rename
foo/ into FOO/.
But because FOO/ already "exists" as directory,
Git tries to move foo/ into FOO/foo, which fails.

And no, the problem is probably not restricted to MacOs,
Windows and all case-insenstive file systems should show
the same, but I haven't tested yet, so it's more a suspicion.

The following diff allows to move foo/ into FOO/
If someone wants to make a patch out if, that would be good.



diff --git a/builtin/mv.c b/builtin/mv.c
index 3fccdcb6452..fbf184bcfa9 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -163,8 +163,10 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 		destination = internal_prefix_pathspec(dest_path[0], argv, argc, DUP_BASENAME);
 	else if (!lstat(dest_path[0], &st) &&
 			S_ISDIR(st.st_mode)) {
-		dest_path[0] = add_slash(dest_path[0]);
-		destination = internal_prefix_pathspec(dest_path[0], argv, argc, DUP_BASENAME);
+		if (!ignore_case || strcasecmp(source[0], dest_path[0])) {
+			dest_path[0] = add_slash(dest_path[0]);
+			destination = internal_prefix_pathspec(dest_path[0], argv, argc, DUP_BASENAME);
+		}
 	} else {
 		if (argc != 1)
 			die(_("destination '%s' is not a directory"), dest_path[0]);
@@ -187,9 +189,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 				(dst[length] == 0 || dst[length] == '/')) {
 			bad = _("can not move directory into itself");
 		} else if ((src_is_dir = S_ISDIR(st.st_mode))
-				&& lstat(dst, &st) == 0)
-			bad = _("cannot move directory over file");
-		else if (src_is_dir) {
+			   && lstat(dst, &st) == 0) {
+			if (!ignore_case || strcasecmp(src, dst)){
+				bad = _("cannot move directory over file");
+			}
+		}
+		if (!bad && src_is_dir) {
 			int first = cache_name_pos(src, length), last;

 			if (first >= 0)
@@ -277,7 +282,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 		if (mode != INDEX && rename(src, dst) < 0) {
 			if (ignore_errors)
 				continue;
-			die_errno(_("renaming '%s' failed"), src);
+			die_errno(_("renaming '%s' into '%s' failed"), src, dst);
 		}
 		if (submodule_gitfile[i]) {
 			if (!update_path_in_gitmodules(src, dst))

  parent reply	other threads:[~2021-05-04 15:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-03 17:25 Mark Amery
2021-05-03 22:58 ` brian m. carlson
2021-05-04  3:46   ` Junio C Hamano
2021-05-04 11:20     ` brian m. carlson
2021-05-05 13:51       ` Johannes Schindelin
2021-05-06  0:38         ` Junio C Hamano
2021-05-04 15:19 ` Torsten Bögershausen [this message]
2021-05-05  0:23   ` Junio C Hamano
2021-05-05  2:12     ` brian m. carlson
2021-05-06  4:34     ` Torsten Bögershausen
2021-05-06  9:12       ` Mark Amery
2021-05-06 13:11         ` Bagas Sanjaya
2021-05-06 14:53         ` Torsten Bögershausen
2021-05-06 21:03         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210504151954.aczbvml4rh7t2svc@tb-raspi4 \
    --to=tboegi@web.de \
    --cc=git@vger.kernel.org \
    --cc=markrobertamery@gmail.com \
    --subject='Re: Bug: Changing folder case with `git mv` crashes on case-insensitive file system' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.version-control.git
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.version-control.git
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git