Skip to content

Commit a301973

Browse files
trastgitster
authored andcommitted
add -p: print errors in separate color
Print interaction error messages in color.interactive.error, which defaults to the value of color.interactive.help. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ca6ac7f commit a301973

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

Documentation/config.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,8 @@ color.interactive::
556556

557557
color.interactive.<slot>::
558558
Use customized color for 'git-add --interactive'
559-
output. `<slot>` may be `prompt`, `header`, or `help`, for
560-
three distinct types of normal output from interactive
559+
output. `<slot>` may be `prompt`, `header`, `help` or `error`, for
560+
four distinct types of normal output from interactive
561561
programs. The values of these variables may be specified as
562562
in color.branch.<slot>.
563563

git-add--interactive.perl

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
$repo->get_color('color.interactive.header', 'bold'),
1313
$repo->get_color('color.interactive.help', 'red bold'),
1414
) : ();
15+
my $error_color = ();
16+
if ($menu_use_color) {
17+
my $help_color_spec = $repo->config('color.interactive.help');
18+
$error_color = $repo->get_color('color.interactive.error',
19+
$help_color_spec);
20+
}
1521

1622
my $diff_use_color = $repo->get_colorbool('color.diff');
1723
my ($fraginfo_color) =
@@ -333,6 +339,10 @@ sub highlight_prefix {
333339
return "$prompt_color$prefix$normal_color$remainder";
334340
}
335341

342+
sub error_msg {
343+
print STDERR colored $error_color, @_;
344+
}
345+
336346
sub list_and_choose {
337347
my ($opts, @stuff) = @_;
338348
my (@chosen, @return);
@@ -428,12 +438,12 @@ sub list_and_choose {
428438
else {
429439
$bottom = $top = find_unique($choice, @stuff);
430440
if (!defined $bottom) {
431-
print "Huh ($choice)?\n";
441+
error_msg "Huh ($choice)?\n";
432442
next TOPLOOP;
433443
}
434444
}
435445
if ($opts->{SINGLETON} && $bottom != $top) {
436-
print "Huh ($choice)?\n";
446+
error_msg "Huh ($choice)?\n";
437447
next TOPLOOP;
438448
}
439449
for ($i = $bottom-1; $i <= $top-1; $i++) {
@@ -1029,11 +1039,11 @@ sub patch_update_file {
10291039
chomp $response;
10301040
}
10311041
if ($response !~ /^\s*\d+\s*$/) {
1032-
print STDERR "Invalid number: '$response'\n";
1042+
error_msg "Invalid number: '$response'\n";
10331043
} elsif (0 < $response && $response <= $num) {
10341044
$ix = $response - 1;
10351045
} else {
1036-
print STDERR "Sorry, only $num hunks available.\n";
1046+
error_msg "Sorry, only $num hunks available.\n";
10371047
}
10381048
next;
10391049
}
@@ -1062,7 +1072,7 @@ sub patch_update_file {
10621072
if ($@) {
10631073
my ($err,$exp) = ($@, $1);
10641074
$err =~ s/ at .*git-add--interactive line \d+, <STDIN> line \d+.*$//;
1065-
print STDERR "Malformed search regexp $exp: $err\n";
1075+
error_msg "Malformed search regexp $exp: $err\n";
10661076
next;
10671077
}
10681078
my $iy = $ix;
@@ -1072,7 +1082,7 @@ sub patch_update_file {
10721082
$iy++;
10731083
$iy = 0 if ($iy >= $num);
10741084
if ($ix == $iy) {
1075-
print STDERR "No hunk matches the given pattern\n";
1085+
error_msg "No hunk matches the given pattern\n";
10761086
last;
10771087
}
10781088
}
@@ -1084,7 +1094,7 @@ sub patch_update_file {
10841094
$ix--;
10851095
}
10861096
else {
1087-
print STDERR "No previous hunk\n";
1097+
error_msg "No previous hunk\n";
10881098
}
10891099
next;
10901100
}
@@ -1093,7 +1103,7 @@ sub patch_update_file {
10931103
$ix++;
10941104
}
10951105
else {
1096-
print STDERR "No next hunk\n";
1106+
error_msg "No next hunk\n";
10971107
}
10981108
next;
10991109
}
@@ -1106,13 +1116,13 @@ sub patch_update_file {
11061116
}
11071117
}
11081118
else {
1109-
print STDERR "No previous hunk\n";
1119+
error_msg "No previous hunk\n";
11101120
}
11111121
next;
11121122
}
11131123
elsif ($line =~ /^j/) {
11141124
if ($other !~ /j/) {
1115-
print STDERR "No next hunk\n";
1125+
error_msg "No next hunk\n";
11161126
next;
11171127
}
11181128
}

0 commit comments

Comments
 (0)