Skip to content

Commit 75b3bd9

Browse files
committed
Add '--fmtprg-stderr' option
1 parent 63c322d commit 75b3bd9

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ options:
3434
--staged a synonym of --cached
3535
--color always show colors
3636
--no-color turn off colored diff
37+
--fmtprg-stderr show stderr from formatter programs
3738
--warn-risky-stderr redirects warning about potential unsolicited changes in suggestions to stderr;
3839
option not recommended as the warning blocks dangerous 'git apply'
3940
```

completion.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ __git_fmt_diff_options="
33
--staged
44
--color
55
--no-color
6+
--fmtprg-stderr
67
--config
78
--warn-risky-stderr
89
"

git-fmt-diff

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ gf_debug=0
1313
gf_no_term=
1414
gf_use_color=
1515
gf_warn_risky_stderr=
16+
g_fmtprg_devnull="2> /dev/null"
1617

1718
g_rm_list="$(mktemp)"
1819

@@ -48,12 +49,13 @@ cleanup () (
4849
)
4950

5051
debug () (
51-
[ "$2" != "--" ] && [ "$gf_debug" -eq 0 ] && return
52-
>&2 printf "[debug] %s:%d # " "$(basename "$0")" "$1"
53-
shift 1
54-
>&2 echo "$@"
52+
[ "$3" != "--" ] && [ "$gf_debug" -eq 0 ] && return
53+
prg="$(basename "$0")"
54+
func="$1" && shift 1
55+
lineno="$1" && shift 1
56+
>&2 printf "[debug] %s @ %s:%d # %s\n" "$prg" "$func" "$lineno" "$*"
5557
)
56-
alias debug='debug "$LINENO"'
58+
alias debug='debug "$FUNCNAME" "$LINENO"'
5759

5860
pat_list_to_case () (
5961
sed 's/\s*,\s*/|/g'
@@ -393,12 +395,14 @@ process_file () (
393395
return
394396
fi
395397

396-
sh -c "$formatter" < "$b_raw" > "$b_fmt" 2> /dev/null
398+
# shellcheck disable=SC2086
399+
sh -c "$formatter" < "$b_raw" > "$b_fmt" $g_fmtprg_devnull
397400
rm_list__push "$b_fmt"
398401

399402
git diff -s "$b_raw" "$b_fmt" && return
400403

401-
sh -c "$formatter" < "$a_raw" > "$a_fmt" 2> /dev/null
404+
# shellcheck disable=SC2086
405+
sh -c "$formatter" < "$a_raw" > "$a_fmt" $g_fmtprg_devnull
402406
rm_list__push "$a_fmt"
403407

404408
chng_fmt="$(git_changes_formatted \
@@ -484,6 +488,7 @@ options:
484488
--staged a synonym of --cached
485489
--color always show colors
486490
--no-color turn off colored diff
491+
--fmtprg-stderr show stderr from formatter programs
487492
--warn-risky-stderr redirects warning about potential unsolicited changes in suggestions to stderr;
488493
option not recommended as the warning blocks dangerous 'git apply'
489494
EOU
@@ -511,6 +516,9 @@ while :; do
511516
--no-color)
512517
gf_use_color=0
513518
;;
519+
--fmtprg-stderr)
520+
g_fmtprg_devnull=""
521+
;;
514522
--warn-risky-stderr)
515523
gf_warn_risky_stderr=1
516524
;;

0 commit comments

Comments
 (0)