@matheusbsbs / matheus-bagliano / commits / f6bc189a45
Fork 0

git-mv: keep git index consistent with file system on failed rename

When doing multiple renames, and a rename in the middle fails, git-mv did not store the successful renames in the git index; this is fixed by delaying the error message on a failed rename to after the git updating. Signed-off-by: Josef Weidendorfer <Josef.Weidendorfer@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Josef Weidendorfer committed Nov 27, 2005 at 22:04 UTC f6bc189a457b2575587f26e27f1eabdd615b2d78
1 file changed +10 -2
git-mv.perl
+10 -2
@@ -142,14 +142,17 @@ while(scalar @srcArgs > 0) {
142
143 # Final pass: rename/move
144 my (@deletedfiles,@addedfiles,@changedfiles);
145 +$bad = "";
146 while(scalar @srcs > 0) {
147 $src = shift @srcs;
148 $dst = shift @dsts;
149
150 if ($opt_n || $opt_v) { print "Renaming $src to $dst\n"; }
151 if (!$opt_n) {
151 - rename($src,$dst)
152 - or die "rename failed: $!";
152 + if (!rename($src,$dst)) {
153 + $bad = "renaming '$src' failed: $!";
154 + last;
155 + }
156 }
157
158 $safesrc = quotemeta($src);
@@ -209,3 +212,8 @@ else {
212 close(H);
213 }
214 }
215 +
216 +if ($bad ne "") {
217 + print "Error: $bad\n";
218 + exit(1);
219 +}