@matheusbsbs / matheus-bagliano / commits / 073dab137a
Fork 0

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>

Josef Weidendorfer committed Nov 23, 2005 at 12:04 UTC 073dab137a746a44606e8e11629e05ff8343346f
1 file changed +17 -8
git-mv.perl
+17 -8
@@ -103,13 +103,22 @@ while(scalar @srcArgs > 0) {
103 $bad = "bad source '$src'";
104 }
105
106 + $safesrc = quotemeta($src);
107 + @srcfiles = grep /^$safesrc(\/|$)/, @allfiles;
108 +
109 $overwritten{$dst} = 0;
110 if (($bad eq "") && -e $dst) {
111 $bad = "destination '$dst' already exists";
109 - if (-f $dst && $opt_f) {
110 - print "Warning: $bad; will overwrite!\n";
111 - $bad = "";
112 - $overwritten{$dst} = 1;
112 + if ($opt_f) {
113 + # only files can overwrite each other: check both source and destination
114 + if (-f $dst && (scalar @srcfiles == 1)) {
115 + print "Warning: $bad; will overwrite!\n";
116 + $bad = "";
117 + $overwritten{$dst} = 1;
118 + }
119 + else {
120 + $bad = "Can not overwrite '$src' with '$dst'";
121 + }
122 }
123 }
124
@@ -118,8 +127,6 @@ while(scalar @srcArgs > 0) {
127 }
128
129 if ($bad eq "") {
121 - $safesrc = quotemeta($src);
122 - @srcfiles = grep /^$safesrc(\/|$)/, @allfiles;
130 if (scalar @srcfiles == 0) {
131 $bad = "'$src' not under version control";
132 }
@@ -166,10 +173,12 @@ while(scalar @srcs > 0) {
173
174 push @deletedfiles, @srcfiles;
175 if (scalar @srcfiles == 1) {
176 + # $dst can be a directory with 1 file inside
177 if ($overwritten{$dst} ==1) {
170 - push @changedfiles, $dst;
178 + push @changedfiles, $dstfiles[0];
179 +
180 } else {
172 - push @addedfiles, $dst;
181 + push @addedfiles, $dstfiles[0];
182 }
183 }
184 else {