git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] githooks: discuss Git operations in foreign repositories

From
Jeff King <peff@peff.net>
Date
Jan 11, 2023, 19:01 UTC
Message-ID
<Y78Hgj4jKga7vNo7@coredump.intra.peff.net>
In-Reply-To
<pull.1457.v2.git.1673293508399.gitgitgadget@gmail.com>
On Mon, Jan 09, 2023 at 07:45:08PM +0000, Eric Sunshine via GitGitGadget wrote:
Show 15 quoted lines
> Recommended best-practice[1,2,3,4,5,6] for avoiding this problem is for
> the hook to ensure that Git variables are unset before invoking Git
> commands in foreign repositories or other worktrees:
> 
>     unset $(git rev-parse --local-env-vars)
> 
> However, this advice is not documented anywhere. Rectify this
> shortcoming by mentioning it in githooks.txt documentation.
> 
> [1]: https://lore.kernel.org/git/YFuHd1MMlJAvtdzb@coredump.intra.peff.net/
> [2]: https://lore.kernel.org/git/20200228190218.GC1408759@coredump.intra.peff.net/
> [3]: https://lore.kernel.org/git/20190516221702.GA11784@sigill.intra.peff.net/
> [4]: https://lore.kernel.org/git/20190422162127.GC9680@sigill.intra.peff.net/
> [5]: https://lore.kernel.org/git/20180716183942.GB22298@sigill.intra.peff.net/
> [6]: https://lore.kernel.org/git/20150203163235.GA9325@peff.net/
Boy, I'm like a broken record.

The patch here looks good to me. The problem is wider than just hooks, but it seems like that's going to be a common place for people to get caught by it. So certainly this is going in the right direction.

The other place I've run into it is writing a script meant to be run as an external command. E.g., running this:

  git --git-dir=/some/path my-external-command

means that "my-external-command" is going to have $GIT_DIR set. If it wants to operate on another repository it needs to take care to clear that from the environment.

-Peff
Previous: Preston Tunnell Wilson
Message 11 of 11 in “githooks: discuss Git operations in foreign repositories”
  1. githooks: discuss Git operations in foreign repositoriesEric Sunshine via GitGitGadget, Jan 8, 2023
  2. Preston Tunnell WilsonJan 8, 2023
  3. Eric SunshineJan 8, 2023
  4. Preston Tunnell WilsonJan 9, 2023
  5. Eric SunshineJan 9, 2023
  6. Junio C HamanoJan 9, 2023
  7. Eric SunshineJan 9, 2023
  8. Junio C HamanoJan 9, 2023
  9. githooks: discuss Git operations in foreign repositoriesEric Sunshine via GitGitGadget, Jan 9, 2023
  10. Preston Tunnell WilsonJan 9, 2023
  11. Jeff KingJan 11, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.