Skip to content

Commit

Permalink
git-mv: keep git index consistent with file system on failed rename
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Josef Weidendorfer authored and Junio C Hamano committed Nov 27, 2005
1 parent 3ae64df commit f6bc189
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions git-mv.perl
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,17 @@ ()

# Final pass: rename/move
my (@deletedfiles,@addedfiles,@changedfiles);
$bad = "";
while(scalar @srcs > 0) {
$src = shift @srcs;
$dst = shift @dsts;

if ($opt_n || $opt_v) { print "Renaming $src to $dst\n"; }
if (!$opt_n) {
rename($src,$dst)
or die "rename failed: $!";
if (!rename($src,$dst)) {
$bad = "renaming '$src' failed: $!";
last;
}
}

$safesrc = quotemeta($src);
Expand Down Expand Up @@ -209,3 +212,8 @@ ()
close(H);
}
}

if ($bad ne "") {
print "Error: $bad\n";
exit(1);
}

0 comments on commit f6bc189

Please sign in to comment.