hooks: work around worktree wierdness
Girocco has recently started "tolerating" linked working trees
(and perhaps even non-bare repositories) just a bit better.
Unfortunately that means the situation gets inflicted on the
hook scripts as well.
While the receive scripts are generally not expected to have
to deal with the current working directory being a worktree
rather than an actual Git repository directory, linked working
trees introduce bizarre wierdness.
One _can_ clone a linked working tree and then push back into
it. Ugh. The receive hook scripts get all kinds of wierd
things when this happens. Of particular concern, the current
working directory will _not_ be the directory containing the
`config` file!
Address this travesty by resetting the current working directory
and GIT_DIR variable when the ugly situation rears its head so
that the hook scripts work like they are designed to.
And just in case, also make sure the current directory has not
been left pointing at some worktree somewhere.
Signed-off-by: Kyle J. McKay <mackyle@gmail.com>