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

Re: post-update script to update wc - suggestions welcome

From
Sam Vilain <sam@vilain.net>
Date
Jun 20, 2007, 22:28 UTC
Message-ID
<4679AA11.5050407@vilain.net>
In-Reply-To
<7vtzt2s5jl.fsf@assigned-by-dhcp.pobox.com>
Junio C Hamano wrote:
Show 6 quoted lines
> I am afraid I am not following your logic.
> 
> I missed that "if git-diff-files"; it is not checking (you would
> have to ask for --exit-code or something --- traditionally we
> never used git-diff-xxxx exit code to indicate if there is any
> changes).

Oh, I expected a diff command to return an error code if differences were found, like diff does.

Show 6 quoted lines
> Suppose we update that "if" to see if diff-files says "no change
> in the working tree wrt the index".  But then, I think what you
> have at the end, "git reset --hard HEAD", where the HEAD is an
> arbitrary commit that does not necessarily have to do anything
> with what the index is based on, would remove what is known to
> the index but not in HEAD.

Good point. Yes a semi-staged commit would lose information. So we also need to check that the index matches the previous value of what the current branch points to.

How about this. We call write-tree and get a tree ID. If we can find that tree in any of the commits reachable by the reflog or the history of the current branch then we can be happy that no local changes have been staged. That will imply that if you want a non-bare repository to update automatically and use push -f, you need reflog.

>  Which was my point about the
> "diff-index piped to perl".  I do not think that one is
> necessary.

Sure, I only did that because I didn't think reset --hard would remove files which were previously in the index but not in the version being reset to.

> Actually, more importantly, why is it justified to remove a file
> that is unchanged since the index, if the updated HEAD does not
> have it?  That is losing information, isn't it?

Well, not if you can confirm that the index matches some previous version of the branch.

> Or are you assuming that this is used only for a worktree where
> there is NO actual development happens, but just kept up to date
> to whatever commit comes at HEAD?

I was aiming for something safe that people can just chmod +x to get symmetric push/pull semantics.

Sam.
Previous: Junio C Hamano
Message 6 of 6 in “post-update script to update wc - suggestions welcome”
  1. Sam VilainJun 20, 2007
  2. Sam VilainJun 20, 2007
  3. Junio C HamanoJun 20, 2007
  4. Sam VilainJun 20, 2007
  5. Junio C HamanoJun 20, 2007
  6. Sam VilainJun 20, 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.