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

Re: [QUESTION] Tracking HEAD changes?

From
Jeff King <peff@peff.net>
Date
Feb 23, 2021, 20:42 UTC
Message-ID
<YDVo0kGYODP0JjqT@coredump.intra.peff.net>
In-Reply-To
<YDROhhrM5qJti1ir@coredump.intra.peff.net>
On Mon, Feb 22, 2021 at 07:38:30PM -0500, Jeff King wrote:
Show 11 quoted lines
> On Mon, Feb 22, 2021 at 11:12:11AM +0200, Yaron Wittenstein wrote:
> 
> > Is there any possible way to track changes to HEAD using hooks?
> > 
> > Being able to listen using hooks to events such as pre-head-checkout
> > and post-head-checkout would be the best option (from my perspective).
> > 
> > To my knowledge, the only possible way to do that today is by adding a
> > file watch over the refs directory.
> 
> No, I don't think there is currently a better way.

Actually, I completely forgot about Patrick's recent ref-transaction hook. See the "reference-transaction" section of githooks(7). They do more than you'd need, but you should be able to write a hook that just looks for updates to HEAD, or updates to the ref that HEAD is pointing at.

The code was introduced in 6754159767 (refs: implement reference transaction hook, 2020-06-19), so you'll need Git v2.28.0 or later.

-Peff
Previous: Jeff KingNext: Yaron Wittenstein
Message 3 of 15 in “[QUESTION] Tracking HEAD changes?”
  1. Yaron WittensteinFeb 22, 2021
  2. Jeff KingFeb 23, 2021
  3. Jeff KingFeb 23, 2021
  4. Yaron WittensteinFeb 24, 2021
  5. Jeff KingFeb 24, 2021
  6. Patrick SteinhardtFeb 25, 2021
  7. Yaron WittensteinFeb 25, 2021
  8. Patrick SteinhardtFeb 25, 2021
  9. Junio C HamanoFeb 25, 2021
  10. Patrick SteinhardtFeb 25, 2021
  11. Yaron WittensteinFeb 25, 2021
  12. Jeff KingFeb 26, 2021
  13. Yaron WittensteinFeb 26, 2021
  14. Jeff KingMar 1, 2021
  15. Yaron WittensteinMar 1, 2021

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.