diff options
author | Josef Weidendorfer <Josef.Weidendorfer@gmx.de> | 2005-11-23 12:04:23 +0100 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2005-11-23 16:51:26 -0800 |
commit | 073dab137a746a44606e8e11629e05ff8343346f (patch) | |
tree | f3470b1639c966e33e95499a7c264b4400aeb5a2 /git-mv.perl | |
parent | fbf8ac212caa74fc506434da83f8e9630b09ed12 (diff) | |
download | git-073dab137a746a44606e8e11629e05ff8343346f.tar.gz git-073dab137a746a44606e8e11629e05ff8343346f.tar.xz |
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: Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'git-mv.perl')
-rwxr-xr-x | git-mv.perl | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/git-mv.perl b/git-mv.perl index a21d87eea..bf54c3841 100755 --- a/git-mv.perl +++ b/git-mv.perl @@ -103,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'"; + } } } @@ -118,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"; } @@ -166,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 { |