Skip to content

Commit f7b1254

Browse files
eliottthomas1ccojocar
authored andcommitted
Add --quiet flag to remove error message from output
1 parent 808c3a2 commit f7b1254

4 files changed

Lines changed: 40 additions & 27 deletions

File tree

README.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Synopsis
1313

1414
::
1515

16-
git secrets --scan [-r|--recursive] [--cached] [--no-index] [--untracked] [<files>...]
16+
git secrets --scan [-r|--recursive] [-q|--quiet] [--cached] [--no-index] [--untracked] [<files>...]
1717
git secrets --scan-history
1818
git secrets --install [-f|--force] [<target-directory>]
1919
git secrets --list [--global]
@@ -265,6 +265,9 @@ Options for ``--scan``
265265
``-r`` cannot be used alongside ``--cached``, ``--no-index``, or
266266
``--untracked``.
267267

268+
``-q, --quiet``
269+
Shows results but removes error message from output.
270+
268271
``--cached``
269272
Searches blobs registered in the index file.
270273

git-secrets

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# permissions and limitations under the License.
1414

1515
NONGIT_OK=1 OPTIONS_SPEC="\
16-
git secrets --scan [-r|--recursive] [--cached] [--no-index] [--untracked] [<files>...]
16+
git secrets --scan [-r|--recursive] [--cached] [-q|--quiet] [--no-index] [--untracked] [<files>...]
1717
git secrets --scan-history
1818
git secrets --install [-f|--force] [<target-directory>]
1919
git secrets --list [--global]
@@ -33,6 +33,7 @@ aws-provider Secret provider that outputs credentials found in an ini file
3333
register-aws Adds common AWS patterns to the git config and scans for ~/.aws/credentials
3434
r,recursive --scan scans directories recursively
3535
cached --scan scans searches blobs registered in the index file
36+
q,quiet --scan shows results but removes error message from output
3637
no-index --scan searches files in the current directory that is not managed by Git
3738
untracked In addition to searching in the tracked files in the working tree, --scan also in untracked files
3839
f,force --install overwrites hooks if the hook already exists
@@ -153,16 +154,18 @@ process_output() {
153154
scan_with_fn_or_die() {
154155
local fn="$1"; shift
155156
$fn "$@" && exit 0
156-
echo >&2
157-
echo "[ERROR] Matched one or more prohibited patterns" >&2
158-
echo >&2
159-
echo "Possible mitigations:" >&2
160-
echo "- Mark false positives as allowed using: git config --add secrets.allowed ..." >&2
161-
echo "- Mark false positives as allowed by adding regular expressions to .gitallowed at repository's root directory" >&2
162-
echo "- List your configured patterns: git config --get-all secrets.patterns" >&2
163-
echo "- List your configured allowed patterns: git config --get-all secrets.allowed" >&2
164-
echo "- List your configured allowed patterns in .gitallowed at repository's root directory" >&2
165-
echo "- Use --no-verify if this is a one-time false positive" >&2
157+
if [ ${QUIET} -ne 1 ]; then
158+
echo >&2
159+
echo "[ERROR] Matched one or more prohibited patterns" >&2
160+
echo >&2
161+
echo "Possible mitigations:" >&2
162+
echo "- Mark false positives as allowed using: git config --add secrets.allowed ..." >&2
163+
echo "- Mark false positives as allowed by adding regular expressions to .gitallowed at repository's root directory" >&2
164+
echo "- List your configured patterns: git config --get-all secrets.patterns" >&2
165+
echo "- List your configured allowed patterns: git config --get-all secrets.allowed" >&2
166+
echo "- List your configured allowed patterns in .gitallowed at repository's root directory" >&2
167+
echo "- Use --no-verify if this is a one-time false positive" >&2
168+
fi
166169
exit 1
167170
}
168171

@@ -294,7 +297,7 @@ assert_option_for_command() {
294297
fi
295298
}
296299

297-
declare COMMAND="$1" FORCE=0 RECURSIVE=0 LITERAL=0 GLOBAL=0 ALLOWED=0
300+
declare COMMAND="$1" FORCE=0 RECURSIVE=0 QUIET=0 LITERAL=0 GLOBAL=0 ALLOWED=0
298301
declare SCAN_CACHED=0 SCAN_NO_INDEX=0 SCAN_UNTRACKED=0
299302

300303
# Shift off the command name
@@ -309,6 +312,10 @@ while [ "$#" -ne 0 ]; do
309312
assert_option_for_command "--scan" "-r|--recursive"
310313
RECURSIVE=1
311314
;;
315+
-q)
316+
assert_option_for_command "--scan" "-q|--quiet"
317+
QUIET=1
318+
;;
312319
-a)
313320
assert_option_for_command "--add" "-a|--allowed"
314321
ALLOWED=1

git-secrets.1

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
8989
.sp
9090
.nf
9191
.ft C
92-
git secrets \-\-scan [\-r|\-\-recursive] [\-\-cached] [\-\-no\-index] [\-\-untracked] [<files>...]
92+
git secrets \-\-scan [\-r|\-\-recursive] [\-q|\-\-quiet] [\-\-cached] [\-\-no\-index] [\-\-untracked] [<files>...]
9393
git secrets \-\-scan\-history
9494
git secrets \-\-install [\-f|\-\-force] [<target\-directory>]
9595
git secrets \-\-list [\-\-global]
@@ -113,19 +113,6 @@ rejected.
113113
\fBgit\-secrets\fP must be placed somewhere in your PATH so that it is picked up
114114
by \fBgit\fP when running \fBgit secrets\fP\&.
115115
.SS *nix (Linux/macOS)
116-
.IP "System Message: WARNING/2 (README.rst:, line 43)"
117-
Title underline too short.
118-
.INDENT 0.0
119-
.INDENT 3.5
120-
.sp
121-
.nf
122-
.ft C
123-
\e*nix (Linux/macOS)
124-
~~~~~~~~~~~~~~~~~
125-
.ft P
126-
.fi
127-
.UNINDENT
128-
.UNINDENT
129116
.sp
130117
You can use the \fBinstall\fP target of the provided Makefile to install \fBgit secrets\fP and the man page.
131118
You can customize the install path using the PREFIX and MANPREFIX variables.
@@ -429,6 +416,9 @@ ignored.
429416
\fB\-r\fP cannot be used alongside \fB\-\-cached\fP, \fB\-\-no\-index\fP, or
430417
\fB\-\-untracked\fP\&.
431418
.TP
419+
.B \fB\-q, \-\-quiet\fP
420+
Shows results but removes error message from output.
421+
.TP
432422
.B \fB\-\-cached\fP
433423
Searches blobs registered in the index file.
434424
.TP

test/git-secrets.bats

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,14 @@ load test_helper
311311
[ $status -eq 0 ]
312312
}
313313

314+
@test "-q removes error message from output" {
315+
setup_bad_repo
316+
repo_run git-secrets --scan
317+
echo "$output" | grep "ERROR"
318+
repo_run git-secrets --scan -q
319+
[[ ! $output =~ "ERROR" ]]
320+
}
321+
314322
@test "--recursive cannot be used with SCAN_*" {
315323
repo_run git-secrets --scan -r --cached
316324
[ $status -eq 1 ]
@@ -398,3 +406,8 @@ load test_helper
398406
repo_run git-secrets --list
399407
[ $status -eq 0 ]
400408
}
409+
410+
@test "-q can only be used with --scan" {
411+
repo_run git-secrets --list -q
412+
[ $status -eq 1 ]
413+
}

0 commit comments

Comments
 (0)