@@ -17,6 +17,7 @@ use warnings FATAL => 'all';
17
17
my $remove_file_add_header = 1;
18
18
my $remove_file_delete_header = 1;
19
19
my $clean_permission_changes = 1;
20
+ my $patch_mode = 0;
20
21
my $manually_color_lines = 0; # Usually git/hg colorizes the lines, but for raw patches we use this
21
22
my $change_hunk_indicators = git_config_boolean(" diff-so-fancy.changeHunkIndicators" ," true" );
22
23
my $strip_leading_indicators = git_config_boolean(" diff-so-fancy.stripLeadingSymbols" ," true" );
@@ -51,6 +52,13 @@ if ($args->{color_on}) {
51
52
$color_forced = 1;
52
53
}
53
54
55
+ # `git add --patch` requries our output to match the number of lines from the
56
+ # input. So, when patch mode is active, we print out empty lines to pad our
57
+ # output to match any lines we've consumed.
58
+ if ($args -> {patch }) {
59
+ $patch_mode = 1;
60
+ }
61
+
54
62
# We only process ARGV if we don't have STDIN
55
63
if (!$has_stdin ) {
56
64
if ($args -> {v } || $args -> {version }) {
@@ -178,6 +186,10 @@ sub do_dsf_stuff {
178
186
179
187
$last_file_seen =~ s | ^\w /|| ; # Remove a/ (and handle diff.mnemonicPrefix).
180
188
$in_hunk = 0;
189
+ if ($patch_mode ) {
190
+ # we are consuming one line, and the debt must be paid
191
+ print " \n " ;
192
+ }
181
193
# #######################################
182
194
# Find the first file: --- a/README.md #
183
195
# #######################################
@@ -281,6 +293,9 @@ sub do_dsf_stuff {
281
293
} elsif ($remove_file_delete_header && $line =~ / ^${ansi_color_regex} deleted file mode/ ) {
282
294
# Don't print the line (i.e. remove it from the output);
283
295
$last_file_mode = " delete" ;
296
+ if ($patch_mode ) {
297
+ print " \n " ;
298
+ }
284
299
# ###############################
285
300
# Look for binary file changes #
286
301
# ###############################
@@ -301,6 +316,10 @@ sub do_dsf_stuff {
301
316
}
302
317
303
318
my ($new_mode ) = $next =~ m / new mode (\d +)/ ;
319
+
320
+ if ($patch_mode ) {
321
+ print " \n " ;
322
+ }
304
323
print " $last_file_seen changed file mode from $old_mode to $new_mode \n " ;
305
324
306
325
# ##############
0 commit comments