{"thread":{"id":"3505","subject":"[PATCH] git-mv: fixes for path handling","startedAt":"2006-03-01T18:09:23Z","lastAt":"2006-03-01T18:09:23Z","messageCount":1,"participants":["Josef Weidendorfer"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"16967","messageId":"200603011909.23357.Josef.Weidendorfer@gmx.de","threadId":"3505","inReplyTo":null,"subject":"[PATCH] git-mv: fixes for path handling","fromName":"Josef Weidendorfer","fromEmail":"josef.weidendorfer@gmx.de","sentAt":"2006-03-01T18:09:23Z","receivedAt":"2006-03-01T18:09:23Z","isPatch":true,"sender":{"key":"josef.weidendorfer@gmx.de","avatar":null},"body":"Moving a directory ending in a slash was not working as the\ndestination was not calculated correctly.\nE.g. in the git repo,\n\n git-mv t/ Documentation\n\ngave the error\n\n Error: destination 'Documentation' already exists\n\nTo get rid of this problem, strip trailing slashes from all arguments.\nThe comment in cg-mv made me curious about this issue; Pasky, thanks!\nAs result, the workaround in cg-mv is not needed any more.\n\nAlso, another bug was shown by cg-mv. When moving files outside of\na subdirectory, it typically calls git-mv with something like\n\n git-mv Documentation/git.txt Documentation/../git-mv.txt\n\nwhich triggers the following error from git-update-index:\n\n Ignoring path Documentation/../git-mv.txt\n\nThe result is a moved file, removed from git revisioning, but not\nadded again. To fix this, the paths have to be normalized not have \"..\"\nin the middle. This was already done in git-mv, but only for\na better visual appearance :(\n\nSigned-off-by: Josef Weidendorfer <Josef.Weidendorfer@gmx.de>\n\n---\n\n git-mv.perl |   24 +++++++++++++-----------\n 1 files changed, 13 insertions(+), 11 deletions(-)\n\n15d94ce0807c1d99d10f6c3ddd32963b1ac0fece\ndiff --git a/git-mv.perl b/git-mv.perl\nindex 8cd95c4..9b43dcc 100755\n--- a/git-mv.perl\n+++ b/git-mv.perl\n@@ -31,11 +31,12 @@ chomp($GIT_DIR);\n my (@srcArgs, @dstArgs, @srcs, @dsts);\n my ($src, $dst, $base, $dstDir);\n \n+# remove any trailing slash in arguments\n+for (@ARGV) { s/\\/*$//; }\n+\n my $argCount = scalar @ARGV;\n if (-d $ARGV[$argCount-1]) {\n \t$dstDir = $ARGV[$argCount-1];\n-\t# remove any trailing slash\n-\t$dstDir =~ s/\\/$//;\n \t@srcArgs = @ARGV[0..$argCount-2];\n \t\n \tforeach $src (@srcArgs) {\n@@ -61,6 +62,16 @@ else {\n     $dstDir = \"\";\n }\n \n+# normalize paths, needed to compare against versioned files and update-index\n+# also, this is nicer to end-users by doing \".//a/./b/.//./c\" ==> \"a/b/c\"\n+for (@srcArgs, @dstArgs) {\n+    s|^\\./||;\n+    s|/\\./|/| while (m|/\\./|);\n+    s|//+|/|g;\n+    # Also \"a/b/../c\" ==> \"a/c\"\n+    1 while (s,(^|/)[^/]+/\\.\\./,$1,);\n+}\n+\n my (@allfiles,@srcfiles,@dstfiles);\n my $safesrc;\n my (%overwritten, %srcForDst);\n@@ -79,15 +90,6 @@ while(scalar @srcArgs > 0) {\n     $dst = shift @dstArgs;\n     $bad = \"\";\n \n-    for ($src, $dst) {\n-\t# Be nicer to end-users by doing \".//a/./b/.//./c\" ==> \"a/b/c\"\n-\ts|^\\./||;\n-\ts|/\\./|/| while (m|/\\./|);\n-\ts|//+|/|g;\n-\t# Also \"a/b/../c\" ==> \"a/c\"\n-\t1 while (s,(^|/)[^/]+/\\.\\./,$1,);\n-    }\n-\n     if ($opt_v) {\n \tprint \"Checking rename of '$src' to '$dst'\\n\";\n     }\n-- \n1.2.0.g719b\n"}]}