archimport: remove files from the index before adding/updating
This fixes a bug when importing where a directory gets removed/renamed but is immediately replaced by a file of the same name in the same changeset. This fix only applies to the accurate (default) strategy the moment. This patch should also fix the fast strategy if/when it is updated to handle the cases that would've triggered this bug. This bug was originally found in git-svn, but I remembered I did the same thing with archimport as well. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
Eric Wong committed
Feb 18, 2006 at 03:49 UTC
3ff903bfb9e34a02f681f1c95ef7aa3ce4d54d2a
1 file changed
+13
-15
git-archimport.perl
+13
-15
@@ -346,12 +346,10 @@ sub process_patchset_accurate {
346
}
347
348
# update the index with all the changes we got
349
+ system('git-diff-files --name-only -z | '.
350
+ 'git-update-index --remove -z --stdin') == 0 or die "$! $?\n";
351
system('git-ls-files --others -z | '.
352
'git-update-index --add -z --stdin') == 0 or die "$! $?\n";
351
- system('git-ls-files --deleted -z | '.
352
- 'git-update-index --remove -z --stdin') == 0 or die "$! $?\n";
353
- system('git-ls-files -z | '.
354
- 'git-update-index -z --stdin') == 0 or die "$! $?\n";
353
return 1;
354
}
355
@@ -416,22 +414,14 @@ sub process_patchset_fast {
414
# imports don't give us good info
415
# on added files. Shame on them
416
if ($ps->{type} eq 'i' || $ps->{type} eq 't') {
419
- system('git-ls-files --others -z | '.
420
- 'git-update-index --add -z --stdin') == 0 or die "$! $?\n";
417
system('git-ls-files --deleted -z | '.
418
'git-update-index --remove -z --stdin') == 0 or die "$! $?\n";
419
+ system('git-ls-files --others -z | '.
420
+ 'git-update-index --add -z --stdin') == 0 or die "$! $?\n";
421
}
422
423
# TODO: handle removed_directories and renamed_directories:
426
-
427
- if (my $add = $ps->{new_files}) {
428
- while (@$add) {
429
- my @slice = splice(@$add, 0, 100);
430
- system('git-update-index','--add','--',@slice) == 0 or
431
- die "Error in git-update-index --add: $! $?\n";
432
- }
433
- }
434
-
424
+
425
if (my $del = $ps->{removed_files}) {
426
unlink @$del;
427
while (@$del) {
@@ -462,6 +452,14 @@ sub process_patchset_fast {
452
}
453
}
454
455
+ if (my $add = $ps->{new_files}) {
456
+ while (@$add) {
457
+ my @slice = splice(@$add, 0, 100);
458
+ system('git-update-index','--add','--',@slice) == 0 or
459
+ die "Error in git-update-index --add: $! $?\n";
460
+ }
461
+ }
462
+
463
if (my $mod = $ps->{modified_files}) {
464
while (@$mod) {
465
my @slice = splice(@$mod, 0, 100);