From 8c5a8e3301f4697ab86c53f74874d6ed3765ae28 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 12 Feb 2025 19:11:14 +0000 Subject: [PATCH] Bug 39114: The auto-rebase script - Fix files removal Wrong handling of the return of the try-catch, $git->rm has an output ("rm /file/path"). This patch retrieves the status from the `git diff-tree` output Test plan: git checkout HEAD~100 (so you are before 38664) git rm mainpage.pl edit C4/Auth.pm and make some changes git commit -a --no-verify -m"Bug 12345: test" then rebase your branch Retrieve the auto_rebase.pl version from this patch and run it perl auto_rebase.pl The resulted commit should not contain mainpage.pl Signed-off-by: Matt Blenkinsop --- misc/devel/auto_rebase.pl | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/misc/devel/auto_rebase.pl b/misc/devel/auto_rebase.pl index 3dd01c4d253..c223ee5bc63 100755 --- a/misc/devel/auto_rebase.pl +++ b/misc/devel/auto_rebase.pl @@ -147,24 +147,31 @@ while ( my ( $i, $commit ) = each @commits ) { say BLUE sprintf "\tProcessing commit %s... (%s/%s)", $commit, $i + 1, scalar @commits; # Get the list of modified files in this commit - my @modified_files = $git->diff_tree( '--no-commit-id', '--name-only', '-r', $commit ); -FILE: while ( my ( $ii, $file ) = each @modified_files ) { + my @modified_files = $git->diff_tree( '--no-commit-id', '--name-status', '-r', $commit ); + while ( my ( $ii, $file_status ) = each @modified_files ) { + $file_status =~ s/ +/ /; + my ($status, $file) = split ' ', $file_status; + say BLUE sprintf "\t\tProcessing file %s... (%s/%s)", $file, $ii + 1, scalar @modified_files; # Retrieve the content of the file from this commit - my @content = try { - $git->RUN( "show", "$commit:$file" ); - } catch { - if ( $_->error =~ m{fatal: path '.*' exists on disk, but not in '$commit'} ) { - say BLUE "\t\t\tFile does not exist, removing..."; + if ( $status eq 'D' ) { + try { $git->rm($file); - } else { - say RED "Something wrong happened when retrieving the file from the branch."; + } catch { + say RED "Something wrong happened when removing the file from the branch."; exit 2; - } - }; + }; + next; + } - next unless @content; # We removed the file + my @content; + try { + @content = $git->RUN( "show", "$commit:$file" ); + } catch { + say RED "Something wrong happened when retrieving the file from the branch."; + exit 2; + }; my $parent_directory = dirname($file); unless ( -f $parent_directory ) { @@ -180,10 +187,10 @@ FILE: while ( my ( $ii, $file ) = each @modified_files ) { say RED "Cannot tidy $file: $_"; exit 2; }; - } - # Stage the changes - $git->add($_) for @modified_files; + # Stage the changes + $git->add($file); + } # Get the original commit information my ( $author, $date, $message ) = get_commit_info($commit); -- 2.34.1