The code like
grep $short_refname "$GIT_DIR/locked"
if [ $? -eq 0 ] ; then
is fragile - it is prone to break on future refactoring.
Also, it contains TWO other issues.
Much cleaner is to directly write what you intend the code to do:
if grep -F "$short_refname" "$GIT_DIR/locked"; then