projects
/
git.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'jc/ident'
[git.git]
/
git-mv.perl
diff --git
a/git-mv.perl
b/git-mv.perl
index
ac19876
..
2ea852c
100755
(executable)
--- a/
git-mv.perl
+++ b/
git-mv.perl
@@
-19,15
+19,9
@@
EOT
exit(1);
}
exit(1);
}
-# Sanity checks:
-my $GIT_DIR = $ENV{'GIT_DIR'} || ".git";
-
-unless ( -d $GIT_DIR && -d $GIT_DIR . "/objects" &&
- -d $GIT_DIR . "/objects/" && -d $GIT_DIR . "/refs") {
- print "Error: git repository not found.";
- exit(1);
-}
-
+my $GIT_DIR = `git rev-parse --git-dir`;
+exit 1 if $?; # rev-parse would have given "not a git dir" message.
+chomp($GIT_DIR);
our ($opt_n, $opt_f, $opt_h, $opt_k, $opt_v);
getopts("hnfkv") || usage;
our ($opt_n, $opt_f, $opt_h, $opt_k, $opt_v);
getopts("hnfkv") || usage;
@@
-68,7
+62,7
@@
my $safesrc;
my (%overwritten, %srcForDst);
$/ = "\0";
my (%overwritten, %srcForDst);
$/ = "\0";
-open(F,
"-|","git-ls-files","-z"
)
+open(F,
'git-ls-files -z |'
)
or die "Failed to open pipe from git-ls-files: " . $!;
@allfiles = map { chomp; $_; } <F>;
or die "Failed to open pipe from git-ls-files: " . $!;
@allfiles = map { chomp; $_; } <F>;
@@
-81,6
+75,15
@@
while(scalar @srcArgs > 0) {
$dst = shift @dstArgs;
$bad = "";
$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";
}
if ($opt_v) {
print "Checking rename of '$src' to '$dst'\n";
}
@@
-108,7
+111,7
@@
while(scalar @srcArgs > 0) {
}
}
}
}
- if (($bad eq "") && ($
src eq $dstDir
)) {
+ if (($bad eq "") && ($
dst =~ /^$safesrc\//
)) {
$bad = "can not move directory '$src' into itself";
}
$bad = "can not move directory '$src' into itself";
}
@@
-151,6
+154,11
@@
while(scalar @srcs > 0) {
if (!$opt_n) {
if (!rename($src,$dst)) {
$bad = "renaming '$src' failed: $!";
if (!$opt_n) {
if (!rename($src,$dst)) {
$bad = "renaming '$src' failed: $!";
+ if ($opt_k) {
+ print "Warning: skipped: $bad\n";
+ $bad = "";
+ next;
+ }
last;
}
}
last;
}
}