Is there any reliable way to check if Git literal pathspecs are enabled in a shell script?
This option can be set either by assigning a boolean value to the variable GIT_LITERAL_PATHSPECS or by passing a flag --literal-pathspecs to git, which also seems to set this variable.
However, parsing the variable seems pretty hard. This is what the documentation says about it:
The environment variables marked as "Boolean" take their values the same way as Boolean valued configuration variables, i.e., "true", "yes", "on" and positive numbers are taken as "yes", while "false", "no", "off", and "0" are taken as "no".
This seems to be enough information to implement it but I'm afraid that the documentation may be outdated or incomplete. There may be more valid keywords like "yeah" and "nah" (or they may be added in the future).
I tried to write a script that checks those values, but I don't know how reliable it would be:
if printf '%s' "$GIT_LITERAL_PATHSPECS" | grep -Eqxi 'true|yes|on' || [ "$GIT_LITERAL_PATHSPECS" -ge 1 ] 2>/dev/null
then
echo 'literal pathspecs are ON'
else
echo 'literal pathspecs are OFF'
fi
Even if it is reliable, I would prefer for some simpler method that won't require me to reimplement the whole boolean parser.
Is there some Git built-in method to check either this specific value, or at least to parse a boolean environment variable?
--literal-pathspecswill setGIT_LITERAL_PATHSPECSto1.