Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions git-secrets
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ prepare_commit_msg_hook* prepare-commit-msg hook (internal only)"
load_patterns() {
git config --get-all secrets.patterns
# Execute each provider and use their output to build up patterns
git config --get-all secrets.providers | while read -r cmd; do
git config --get-all --type path secrets.providers | while read -r cmd; do
# Only split words on '\n\t ' and strip "\r" from the output to account
# for carriage returns being added on Windows systems. Note that this
# trimming is done before the test to ensure that the string is not empty.
Expand Down Expand Up @@ -339,9 +339,17 @@ case "${COMMAND}" in
--scan-history) scan_with_fn_or_die "scan_history" "$@" ;;
--list)
if [ ${GLOBAL} -eq 1 ]; then
git config --global --get-regex secrets.*
RESULT=1
git config --global --get-regex --type path "^secrets\.providers$" && RESULT=0
git config --global --get-regex "^secrets\.patterns$" && RESULT=0
git config --global --get-regex "^secrets\.allowed$" && RESULT=0
[ $RESULT -eq 0 ]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old regex was overly broad and should have been at least ^secrets\..* to begin with.
--type path should only be applied to providers, so they have to be broken out here. That means explicitly enumerating the settings keys. Because the tests (and plausible real world use cases) expect --list's exit code to reflect whether any settings were found I had to accumulate a result along the way, and this was the most concise way that I was comfortable with.

else
git config --get-regex secrets.*
RESULT=1
git config --get-regex --type path "^secrets\.providers$" && RESULT=0
git config --get-regex "^secrets\.patterns$" && RESULT=0
git config --get-regex "^secrets\.allowed$" && RESULT=0
[ $RESULT -eq 0 ]
fi
;;
--install)
Expand Down
8 changes: 8 additions & 0 deletions test/git-secrets.bats
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ load test_helper
[ $status -eq 0 ]
}

@test "Expands ~ in providers" {
repo_run git-secrets --add-provider -- '~/test'
[ $status -eq 0 ]
repo_run git-secrets --list
[ $status -eq 0 ]
echo "$output" | grep -F "${HOME}/test"
}

@test "--recursive cannot be used with SCAN_*" {
repo_run git-secrets --scan -r --cached
[ $status -eq 1 ]
Expand Down