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

Re: [PATCH] contrib/hooks: add post-update hook for updating working copy

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 2, 2007, 01:10 UTC
Message-ID
<7vk5tj1uh4.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<46882AF2.6020705@vilain.net>
Sam Vilain <sam@vilain.net> writes:
Show 5 quoted lines
> Basically I'm trying to figure out "does the current index have any
> uncommitted changes".  If it matches the tree from the previous (handful
> of) ref(s), then the answer is "no".  If we can't find it anywhere then
> it's probably got staged changes, and short of trying to move the
> changes forward, we should stop.

The fact that the index does not match the HEAD means that the user (possibly not the one who is pushing) is in the middle of doing something. A tree that happens to match that state exists in the recent reflog history would only mean that the same state exists _somewhere_; it does not mean it is easy for the end user to go back to it at all.

Show 5 quoted lines
>> But more importantly, why is it justified to throw away such
>> files to begin with?
>
> Because we've already previously decided that they are safely stowed in
> a previous (via time/reflog) revision of the current branch.

The user may have spent hours to come up to that state while doing something we do not have any way of knowing what, and this "heuristic" is allowing to lose that. As you say, we do not lose the tree from the repository, but we lose track of which state the user was interested in. I find that unjustified.

> Perhaps it would make sense to do this check in the "update" hook as
> well, thereby chmod +x refuses to allow a push that touches the
> currently checked out branch.

Having the check in update to prevent it makes sense, independently.

>> The longer I look at this patch, the more inclined I become to
>> say that the only part that is worth saving is the next hunk.

Actually, I think "the first sentence of the output in the next hunk" was what I meant. That is, "we are not updating it because it is dirty and you cannot get back to the original state if this was a mistake". And not updating the index nor the working tree.

How about doing something simpler, more predicatable and safer, like this...

 * If HEAD/index/working tree match, then obviously we can do an
   equivalent of "reset --hard".  There is little chance that
   this is a wrong thing to do, and even when the user did not
   want that happen, the user can easily recover with for
   example "git checkout @{1} .".  So I am not opposed to
   updating the index/working tree in this case at all.
 * Otherwise, especially when HEAD and index do not match,
   touching index nor working tree is absolutely a no-no,
   without giving the user to sort the mess out.  So either in
   "update" hook you prevent it from happening.

Later, when we have git-stash, we can do a bit better in a dirty working tree. We could make a stash of the state _before_ updating the tip of the current branch, and let the push update the tip, and do an equivalent of "reset --hard". Unstashing the state on top of the updated tip could fail, but at that point, the user has the choice of making a new branch (or use detached HEAD) at @{1} (that is, the HEAD before the push updated it) and then unstash the state on top of it to recreate the state before the push made a mess.

    
Previous: Sam VilainNext: Junio C Hamano
Message 23 of 37 in “a bunch of outstanding updates”
  1. Sam VilainJun 30, 2007
  2. repack: improve documentation on -a optionSam Vilain, Jun 30, 2007
  3. git-svn: use git-log rather than rev-list | xargs cat-fileSam Vilain, Jun 30, 2007
  4. git-svn: cache max revision in rev_db databasesSam Vilain, Jun 30, 2007
  5. GIT-VERSION-GEN: don't convert - delimiter to .'sSam Vilain, Jun 30, 2007
  6. git-remote: document -nSam Vilain, Jun 30, 2007
  7. git-remote: allow 'git-remote fetch' as a synonym for 'git fetch'Sam Vilain, Jun 30, 2007
  8. git-merge-ff: fast-forward only mergeSam Vilain, Jun 30, 2007
  9. git-mergetool: add support for ediffSam Vilain, Jun 30, 2007
  10. contrib/hooks: add post-update hook for updating working copySam Vilain, Jun 30, 2007
  11. git-repack: generational repacking (and example hook script)Sam Vilain, Jun 30, 2007
  12. Nicolas PitreJul 3, 2007
  13. Sam VilainJul 3, 2007
  14. Nicolas PitreJul 3, 2007
  15. Shawn O. PearceJul 3, 2007
  16. Sam VilainJul 4, 2007
  17. Johannes SchindelinJul 4, 2007
  18. Sam VilainJul 4, 2007
  19. Alex RiesenJul 4, 2007
  20. Nicolas PitreJul 4, 2007
  21. Junio C HamanoJun 30, 2007
  22. Sam VilainJul 1, 2007
  23. Junio C HamanoJul 2, 2007
  24. Junio C HamanoJun 30, 2007
  25. Sam VilainJul 1, 2007
  26. Johannes SchindelinJun 30, 2007
  27. Matthias LederhoferJun 30, 2007
  28. Junio C HamanoJun 30, 2007
  29. Frank LichtenheldJun 30, 2007
  30. Junio C HamanoJun 30, 2007
  31. Jakub NarebskiJul 11, 2007
  32. Junio C HamanoJul 1, 2007
  33. Eric WongJul 1, 2007
  34. Junio C HamanoJul 1, 2007
  35. Frank LichtenheldJun 30, 2007
  36. Junio C HamanoJun 30, 2007
  37. Frank LichtenheldJun 30, 2007

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.