Skip to content

Commit

Permalink
Add -- to add_config grep. Fix error check. Add test.
Browse files Browse the repository at this point in the history
Signed-off-by: Clarence "Sparr" Risher <[email protected]>
  • Loading branch information
sparr committed Jun 16, 2023
1 parent 99d01d5 commit e9caadb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
16 changes: 12 additions & 4 deletions git-secrets
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,19 @@ add_config() {
value=$(sed 's/[\.|$(){}?+*^]/\\&/g' <<< "${value}")
fi
if [ ${GLOBAL} -eq 1 ]; then
git config --global --get-all $key | grep -Fq "${value}" && return 1
git config --global --add "${key}" "${value}"
git config --global --get-all $key | grep -Fq -- "${value}"
case $? in
0) return 1 ;; # value already exists
2) return 1 ;; # grep error
*) git config --global --add "${key}" "${value}" ;;
esac
else
git config --get-all $key | grep -Fq "${value}" && return 1
git config --add "${key}" "${value}"
git config --get-all $key | grep -Fq -- "${value}"
case $? in
0) return 1 ;; # value already exists
2) return 1 ;; # grep error
*) git config --add "${key}" "${value}" ;;
esac
fi
}

Expand Down
5 changes: 5 additions & 0 deletions test/git-secrets.bats
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ load test_helper
echo "$output" | grep -F 'secrets.allowed testing\+abc'
}

@test "Adds secrets beginning with --" {
repo_run git-secrets --add --literal --global -- '--TEST'
[ $status -eq 0 ]
}

@test "Empty lines must be ignored in .gitallowed files" {
setup_bad_repo
echo '' >> $TEST_REPO/.gitallowed
Expand Down

0 comments on commit e9caadb

Please sign in to comment.