git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: dturner@twopensource.com
To: git@vger.kernel.org
Cc: gitster@pobox.com, David Turner <dturner@twitter.com>
Subject: [PATCH 2/2] ignorecase: Fix git mv on insensitive filesystems
Date: Tue,  6 May 2014 15:59:04 -0700	[thread overview]
Message-ID: <1399417144-24864-2-git-send-email-dturner@twopensource.com> (raw)
In-Reply-To: <1399417144-24864-1-git-send-email-dturner@twopensource.com>

From: David Turner <dturner@twitter.com>

Make it possible to change the case of a filename on a
case-insensitive filesystem using git mv.  Change git mv to allow
moves where the destination file exists if either the destination file
has the same inode as the source file (for Mac) or the same name
ignoring case (for Win).

Signed-off-by: David Turner <dturner@twitter.com>
---
 builtin/mv.c                | 18 ++++++++++--------
 t/t6039-merge-ignorecase.sh |  2 +-
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/builtin/mv.c b/builtin/mv.c
index 45e57f3..8cead13 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -74,7 +74,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 	};
 	const char **source, **destination, **dest_path, **submodule_gitfile;
 	enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes;
-	struct stat st;
+	struct stat src_st,dst_st;
 	struct string_list src_for_dst = STRING_LIST_INIT_NODUP;
 
 	gitmodules_config();
@@ -102,8 +102,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 	if (dest_path[0][0] == '\0')
 		/* special case: "." was normalized to "" */
 		destination = internal_copy_pathspec(dest_path[0], argv, argc, DUP_BASENAME);
-	else if (!lstat(dest_path[0], &st) &&
-			S_ISDIR(st.st_mode)) {
+	else if (!lstat(dest_path[0], &dst_st) &&
+			S_ISDIR(dst_st.st_mode)) {
 		dest_path[0] = add_slash(dest_path[0]);
 		destination = internal_copy_pathspec(dest_path[0], argv, argc, DUP_BASENAME);
 	} else {
@@ -122,13 +122,13 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 			printf(_("Checking rename of '%s' to '%s'\n"), src, dst);
 
 		length = strlen(src);
-		if (lstat(src, &st) < 0)
+		if (lstat(src, &src_st) < 0)
 			bad = _("bad source");
 		else if (!strncmp(src, dst, length) &&
 				(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)
+		} else if ((src_is_dir = S_ISDIR(src_st.st_mode))
+				&& lstat(dst, &dst_st) == 0)
 			bad = _("cannot move directory over file");
 		else if (src_is_dir) {
 			int first = cache_name_pos(src, length);
@@ -202,14 +202,16 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 			}
 		} else if (cache_name_pos(src, length) < 0)
 			bad = _("not under version control");
-		else if (lstat(dst, &st) == 0) {
+		else if (lstat(dst, &dst_st) == 0 &&
+			 (src_st.st_ino != dst_st.st_ino ||
+			  (src_st.st_ino == 0 && strcasecmp(src, dst)))) {
 			bad = _("destination exists");
 			if (force) {
 				/*
 				 * only files can overwrite each other:
 				 * check both source and destination
 				 */
-				if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
+				if (S_ISREG(dst_st.st_mode) || S_ISLNK(dst_st.st_mode)) {
 					if (verbose)
 						warning(_("overwriting '%s'"), dst);
 					bad = NULL;
diff --git a/t/t6039-merge-ignorecase.sh b/t/t6039-merge-ignorecase.sh
index ad06752..28cfb49 100755
--- a/t/t6039-merge-ignorecase.sh
+++ b/t/t6039-merge-ignorecase.sh
@@ -35,7 +35,7 @@ test_expect_success 'merge with case-changing rename on both sides' '
 	git reset --hard baseline &&
 	git branch -D with-camel &&
 	git checkout -b with-camel &&
-	git mv --force TestCase testcase &&
+	git mv TestCase testcase &&
 	git commit -m "recase on branch" &&
 	> foo &&
 	git add foo &&
-- 
2.0.0.rc0.33.g27630aa

  reply	other threads:[~2014-05-06 23:00 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-29 19:02 Bug: Case-insensitive filesystems can cause merge and checkout problems David Turner
2014-05-02  0:21 ` [PATCH] merge-recursive.c: Fix case-changing merge bug David Turner
2014-05-06 17:07   ` Junio C Hamano
2014-05-06 17:36     ` David Turner
2014-05-06 19:46       ` Junio C Hamano
2014-05-06 22:59         ` [PATCH 1/2] merge-recursive.c: Fix case-changing merge dturner
2014-05-06 22:59           ` dturner [this message]
2014-05-07  6:17             ` [PATCH 2/2] ignorecase: Fix git mv on insensitive filesystems Johannes Sixt
2014-05-07 16:42               ` David Turner
2014-05-07 17:46                 ` Junio C Hamano
2014-05-07 18:01                   ` David Turner
2014-05-08  6:37                   ` Johannes Sixt
2014-05-08  8:55                     ` Torsten Bögershausen
2014-05-08 17:23                       ` [PATCH 0/2] " dturner
2014-05-08 17:23                         ` [PATCH 1/2] merge-recursive.c: Fix case-changing merge dturner
2014-05-08 19:45                           ` Junio C Hamano
2014-05-08 17:23                         ` [PATCH 2/2] ignorecase: Fix git mv on insensitive filesystems dturner
2014-05-08 19:54                           ` Junio C Hamano
2014-05-08 20:40                             ` David Turner
2014-05-08 20:55                               ` Junio C Hamano
2014-05-08  1:22             ` brian m. carlson
2014-05-07 18:01           ` [PATCH 1/2] merge-recursive.c: Fix case-changing merge Junio C Hamano
2014-05-07 18:13             ` Jonathan Nieder
2014-05-07 20:53               ` Junio C Hamano
2014-05-08 20:48 [PATCH 2/2] ignorecase: Fix git mv on insensitive filesystems Thomas Braun

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

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

  git send-email \
    --in-reply-to=1399417144-24864-2-git-send-email-dturner@twopensource.com \
    --to=dturner@twopensource.com \
    --cc=dturner@twitter.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).