robfig / glock

MIT License
230 stars 27 forks source link

`glock sync` from inside git-hook can fail due to git env vars #30

Closed dt closed 7 years ago

dt commented 8 years ago

When glock is being called from a git hook, the env vars GIT_DIR and GIT_WORK_TREE are set. However, if glock tries to go get a new dependency (which in turn tries to call git clone), those vars will cause go get to fail with a message that looks like this:

> go get -v -d github.com/mattn/go-isatty
github.com/mattn/go-isatty (download)
# cd .; git clone https://github.com/mattn/go-isatty /Users/david/code/go/src/github.com/mattn/go-isatty
fatal: working tree '.' already exists.
package github.com/mattn/go-isatty: exit status 128
exit status 1

As a workaround, unsetting the vars when calling glock avoids the issue: env -u GIT_DIR -u GIT_WORK_TREE glock ...

EDIT: env -u isn't standard apparently. unset in a subshell works though: (unset GIT_WORK_TREE; glock...).

That said, running glock via git hook seems like it might be a common enough use-case that sanitizing those internally when calling go get makes sense.

dt commented 8 years ago

Looks like GIT_DIR can usually be left set, since it is usually just .git, but that might be an absolute path in some cases which could be messy.

Apparently git stopped paying attention to GIT_WORK_TREE after 2.7.1 so maybe this isn't an issue for more recent versions of git.

robfig commented 8 years ago

Sorry for the delay -- at work I'm using git 2.2.1 and fetches from the git hook have been working for me.. I wonder what the difference is.

robfig commented 7 years ago

(Not sure what action to take here, and the hook has been reliably working for us at work, so closing for now)