Skip to content
Open
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
8 changes: 7 additions & 1 deletion git-secrets
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,13 @@ install_hook() {
[ -f "${dest}" ] && [ "${FORCE}" -ne 1 ] \
&& die "${dest} already exists. Use -f to force"
echo "#!/usr/bin/env bash" > "${dest}"
echo "git secrets --${cmd} -- \"\$@\"" >> "${dest}"
echo "err=\"\$(git secrets --${cmd} -- \"\$@\" 2>&1 > /dev/null)\"" >> "${dest}"
echo "if [[ \"\$err\" == *\"git: 'secrets' is not a git command\"* ]]; then" >> "${dest}"
echo " exit 0" >> "${dest}"
echo "elif [[ ! -z \"\$err\" ]]; then" >> "${dest}"
echo " >&2 echo \"\$err\"" >> "${dest}"
echo " exit 1" >> "${dest}"
echo "fi" >> "${dest}"
Comment on lines +206 to +212
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
echo "err=\"\$(git secrets --${cmd} -- \"\$@\" 2>&1 > /dev/null)\"" >> "${dest}"
echo "if [[ \"\$err\" == *\"git: 'secrets' is not a git command\"* ]]; then" >> "${dest}"
echo " exit 0" >> "${dest}"
echo "elif [[ ! -z \"\$err\" ]]; then" >> "${dest}"
echo " >&2 echo \"\$err\"" >> "${dest}"
echo " exit 1" >> "${dest}"
echo "fi" >> "${dest}"
cat <<-EOF > "${dest}"
err="\$(git secrets --${cmd} -- "\$@" 2>&1 > /dev/null)"
if [[ "\$err" == *"git: 'secrets' is not a git command"* ]]; then
exit 0
elif [[ ! -z "\$err" ]]; then
>&2 echo "\$err"
exit 1
fi
EOF

I think this will be easier to read, but it needs to be tested.
Also, due to github limitations, this suggestion doesn't replace the first echo on line 205 but should.

chmod +x "${dest}"
say "$(tput setaf 2)✓$(tput sgr 0) Installed ${hook} hook to ${dest}"
}
Expand Down