From 843b18a8659343c7ce6ce4bb931ba22f20aa6450 Mon Sep 17 00:00:00 2001 From: "Clarence \"Sparr\" Risher" Date: Fri, 16 Jun 2023 17:00:49 +0000 Subject: [PATCH] Add -- to add_config grep. Fix error check. Add test. Signed-off-by: Clarence "Sparr" Risher --- git-secrets | 16 ++++++++++++---- test/git-secrets.bats | 5 +++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/git-secrets b/git-secrets index 8df3809..6601f9b 100755 --- a/git-secrets +++ b/git-secrets @@ -223,11 +223,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 } diff --git a/test/git-secrets.bats b/test/git-secrets.bats index b7a5b1c..6853eb3 100644 --- a/test/git-secrets.bats +++ b/test/git-secrets.bats @@ -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