X-Git-Url: https://git.octo.it/?p=git.git;a=blobdiff_plain;f=git-mv.perl;h=75aa8feeb6201c54e55bfaca0cc178c53891e776;hp=f3e859ae48af05d0b982a159c2197bab7e5da996;hb=HEAD;hpb=9e7c73de0bcd410d12f897b19419dd35accd961e diff --git a/git-mv.perl b/git-mv.perl index f3e859ae..75aa8fee 100755 --- a/git-mv.perl +++ b/git-mv.perl @@ -62,9 +62,17 @@ else { $dstDir = ""; } +my $subdir_prefix = `git rev-parse --show-prefix`; +chomp($subdir_prefix); + +# run in git base directory, so that git-ls-files lists all revisioned files +chdir "$GIT_DIR/.."; + # normalize paths, needed to compare against versioned files and update-index # also, this is nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c" for (@srcArgs, @dstArgs) { + # prepend git prefix as we run from base directory + $_ = $subdir_prefix.$_; s|^\./||; s|/\./|/| while (m|/\./|); s|//+|/|g; @@ -90,6 +98,15 @@ while(scalar @srcArgs > 0) { $dst = shift @dstArgs; $bad = ""; + for ($src, $dst) { + # Be nicer to end-users by doing ".//a/./b/.//./c" ==> "a/b/c" + s|^\./||; + s|/\./|/| while (m|/\./|); + s|//+|/|g; + # Also "a/b/../c" ==> "a/c" + 1 while (s,(^|/)[^/]+/\.\./,$1,); + } + if ($opt_v) { print "Checking rename of '$src' to '$dst'\n"; }