@matheusbsbs / matheus-bagliano / commits / 9e7c73de0b
Fork 0

git-mv: fixes for path handling

Moving a directory ending in a slash was not working as the destination was not calculated correctly. E.g. in the git repo, git-mv t/ Documentation gave the error Error: destination 'Documentation' already exists To get rid of this problem, strip trailing slashes from all arguments. The comment in cg-mv made me curious about this issue; Pasky, thanks! As result, the workaround in cg-mv is not needed any more. Also, another bug was shown by cg-mv. When moving files outside of a subdirectory, it typically calls git-mv with something like git-mv Documentation/git.txt Documentation/../git-mv.txt which triggers the following error from git-update-index: Ignoring path Documentation/../git-mv.txt The result is a moved file, removed from git revisioning, but not added again. To fix this, the paths have to be normalized not have ".." in the middle. This was already done in git-mv, but only for a better visual appearance :( Signed-off-by: Josef Weidendorfer <Josef.Weidendorfer@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Josef Weidendorfer committed Mar 1, 2006 at 19:09 UTC 9e7c73de0bcd410d12f897b19419dd35accd961e
1 file changed +14 -12
git-mv.perl
+14 -12
@@ -31,13 +31,14 @@ chomp($GIT_DIR);
31 my (@srcArgs, @dstArgs, @srcs, @dsts);
32 my ($src, $dst, $base, $dstDir);
33
34 +# remove any trailing slash in arguments
35 +for (@ARGV) { s/\/*$//; }
36 +
37 my $argCount = scalar @ARGV;
38 if (-d $ARGV[$argCount-1]) {
39 $dstDir = $ARGV[$argCount-1];
37 - # remove any trailing slash
38 - $dstDir =~ s/\/$//;
40 @srcArgs = @ARGV[0..$argCount-2];
40 -
41 +
42 foreach $src (@srcArgs) {
43 $base = $src;
44 $base =~ s/^.*\///;
@@ -61,6 +62,16 @@ else {
62 $dstDir = "";
63 }
64
65 +# normalize paths, needed to compare against versioned files and update-index
66 +# also, this is nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c"
67 +for (@srcArgs, @dstArgs) {
68 + s|^\./||;
69 + s|/\./|/| while (m|/\./|);
70 + s|//+|/|g;
71 + # Also "a/b/../c" ==> "a/c"
72 + 1 while (s,(^|/)[^/]+/\.\./,$1,);
73 +}
74 +
75 my (@allfiles,@srcfiles,@dstfiles);
76 my $safesrc;
77 my (%overwritten, %srcForDst);
@@ -79,15 +90,6 @@ while(scalar @srcArgs > 0) {
90 $dst = shift @dstArgs;
91 $bad = "";
92
82 - for ($src, $dst) {
83 - # Be nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c"
84 - s|^\./||;
85 - s|/\./|/| while (m|/\./|);
86 - s|//+|/|g;
87 - # Also "a/b/../c" ==> "a/c"
88 - 1 while (s,(^|/)[^/]+/\.\./,$1,);
89 - }
90 -
93 if ($opt_v) {
94 print "Checking rename of '$src' to '$dst'\n";
95 }