Skip to content

gracefully handle git secrets not being installed#212

Open
lukaso wants to merge 2 commits intoawslabs:masterfrom
lukaso:fail-gracefully-when-not-installed
Open

gracefully handle git secrets not being installed#212
lukaso wants to merge 2 commits intoawslabs:masterfrom
lukaso:fail-gracefully-when-not-installed

Conversation

@lukaso
Copy link
Copy Markdown

@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 thread git-secrets
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
Copy Markdown
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