Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gracefully handle git secrets not being installed #212

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lukaso
Copy link

@lukaso lukaso commented Jul 19, 2022

Issue #, if available:

Description of changes:

For whatever reason, sometimes the env does not have access to git secrets (for example in vscode this seems to happen frequently). This change allows it to fail gracefully instead of blocking all commits.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

lukaso added 2 commits July 20, 2022 00:00
For whatever reason, sometimes the env does not have access to git secrets (for example in `vscode` this seems to happen frequently). This change allows it to fail gracefully instead of blocking all commits.
Comment on lines +206 to +212
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}"
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants