Skip to content

Commit 843b18a

Browse files
committed
Add -- to add_config grep. Fix error check. Add test.
Signed-off-by: Clarence "Sparr" Risher <[email protected]>
1 parent 0ab55f8 commit 843b18a

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

git-secrets

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,19 @@ add_config() {
223223
value=$(sed 's/[\.|$(){}?+*^]/\\&/g' <<< "${value}")
224224
fi
225225
if [ ${GLOBAL} -eq 1 ]; then
226-
git config --global --get-all $key | grep -Fq "${value}" && return 1
227-
git config --global --add "${key}" "${value}"
226+
git config --global --get-all $key | grep -Fq -- "${value}"
227+
case $? in
228+
0) return 1 ;; # value already exists
229+
2) return 1 ;; # grep error
230+
*) git config --global --add "${key}" "${value}" ;;
231+
esac
228232
else
229-
git config --get-all $key | grep -Fq "${value}" && return 1
230-
git config --add "${key}" "${value}"
233+
git config --get-all $key | grep -Fq -- "${value}"
234+
case $? in
235+
0) return 1 ;; # value already exists
236+
2) return 1 ;; # grep error
237+
*) git config --add "${key}" "${value}" ;;
238+
esac
231239
fi
232240
}
233241

test/git-secrets.bats

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ load test_helper
238238
echo "$output" | grep -F 'secrets.allowed testing\+abc'
239239
}
240240

241+
@test "Adds secrets beginning with --" {
242+
repo_run git-secrets --add --literal --global -- '--TEST'
243+
[ $status -eq 0 ]
244+
}
245+
241246
@test "Empty lines must be ignored in .gitallowed files" {
242247
setup_bad_repo
243248
echo '' >> $TEST_REPO/.gitallowed

0 commit comments

Comments
 (0)