Skip to content

Commit e9caadb

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

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
@@ -222,11 +222,19 @@ add_config() {
222222
value=$(sed 's/[\.|$(){}?+*^]/\\&/g' <<< "${value}")
223223
fi
224224
if [ ${GLOBAL} -eq 1 ]; then
225-
git config --global --get-all $key | grep -Fq "${value}" && return 1
226-
git config --global --add "${key}" "${value}"
225+
git config --global --get-all $key | grep -Fq -- "${value}"
226+
case $? in
227+
0) return 1 ;; # value already exists
228+
2) return 1 ;; # grep error
229+
*) git config --global --add "${key}" "${value}" ;;
230+
esac
227231
else
228-
git config --get-all $key | grep -Fq "${value}" && return 1
229-
git config --add "${key}" "${value}"
232+
git config --get-all $key | grep -Fq -- "${value}"
233+
case $? in
234+
0) return 1 ;; # value already exists
235+
2) return 1 ;; # grep error
236+
*) git config --add "${key}" "${value}" ;;
237+
esac
230238
fi
231239
}
232240

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)