提交 073dab13 编写于 作者: J Josef Weidendorfer 提交者: Junio C Hamano

Fix git-mv for moving directories with 1 file

This is fixed by putting the file into @changedfiles/@addedfiles,
and not the directory this file is in.

Additionally, this fixes the behavior for attempting to overwrite
a file with a directory, and gives a message for all cases where
overwriting is not possible (file->dir,dir->file,dir->dir).

Thanks for Alexander Litvinov for noting this problem.
Signed-off-by: NJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Signed-off-by: NJunio C Hamano <junkio@cox.net>
上级 fbf8ac21
......@@ -103,13 +103,22 @@ ()
$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'";
}
}
}
......@@ -118,8 +127,6 @@ ()
}
if ($bad eq "") {
$safesrc = quotemeta($src);
@srcfiles = grep /^$safesrc(\/|$)/, @allfiles;
if (scalar @srcfiles == 0) {
$bad = "'$src' not under version control";
}
......@@ -166,10 +173,12 @@ ()
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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册