X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=git-mv.perl;h=bf54c38413c02553bd314d24bfdadc4cdb23ccce;hb=ee72aeaf009417156a3599b0eb69da3f7023ca07;hp=17e35b0ac088f83bbcd6d104c77925cd69ded2bb;hpb=05ff5649a4fd90c3c80f507165bbaf07dc0dbe8e;p=git.git diff --git a/git-mv.perl b/git-mv.perl index 17e35b0a..bf54c384 100755 --- a/git-mv.perl +++ b/git-mv.perl @@ -54,6 +54,8 @@ my ($src, $dst, $base, $dstDir); my $argCount = scalar @ARGV; if (-d $ARGV[$argCount-1]) { $dstDir = $ARGV[$argCount-1]; + # remove any trailing slash + $dstDir =~ s/\/$//; @srcArgs = @ARGV[0..$argCount-2]; foreach $src (@srcArgs) { @@ -101,13 +103,22 @@ while(scalar @srcArgs > 0) { $bad = "bad source '$src'"; } + $safesrc = quotemeta($src); + @srcfiles = grep /^$safesrc(\/|$)/, @allfiles; + $overwritten{$dst} = 0; if (($bad eq "") && -e $dst) { $bad = "destination '$dst' already exists"; - if (-f $dst && $opt_f) { - print "Warning: $bad; will overwrite!\n"; - $bad = ""; - $overwritten{$dst} = 1; + if ($opt_f) { + # only files can overwrite each other: check both source and destination + if (-f $dst && (scalar @srcfiles == 1)) { + print "Warning: $bad; will overwrite!\n"; + $bad = ""; + $overwritten{$dst} = 1; + } + else { + $bad = "Can not overwrite '$src' with '$dst'"; + } } } @@ -116,8 +127,6 @@ while(scalar @srcArgs > 0) { } if ($bad eq "") { - $safesrc = quotemeta($src); - @srcfiles = grep /^$safesrc(\/|$)/, @allfiles; if (scalar @srcfiles == 0) { $bad = "'$src' not under version control"; } @@ -164,10 +173,12 @@ while(scalar @srcs > 0) { push @deletedfiles, @srcfiles; if (scalar @srcfiles == 1) { + # $dst can be a directory with 1 file inside if ($overwritten{$dst} ==1) { - push @changedfiles, $dst; + push @changedfiles, $dstfiles[0]; + } else { - push @addedfiles, $dst; + push @addedfiles, $dstfiles[0]; } } else {