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

Re: Add "git-update-ref" to update the HEAD (or other) ref

From
Linus Torvalds <torvalds@osdl.org>
Date
Sep 25, 2005, 19:05 UTC
Message-ID
<Pine.LNX.4.58.0509251153090.3308@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.58.0509251134480.3308@g5.osdl.org>
On Sun, 25 Sep 2005, Linus Torvalds wrote:
>
> This is a careful version of the script stuff that currently just
> blindly writes HEAD with a new value.

Btw, in case it wasn't clear from the patch, this only introduced mechanism, it didn't actually use it in any script.

But the point of the exercise is to move towards using git-update-ref in places like git-fetch.sh, which currently are doing some of it by hand (and not handling symlinks etc).

So you should be able to do something like
	..
	old=$(git-rev-parse --verify "$refname^0") >& /dev/null
	if [ "$old" ]; then
		mb=$(git-merge-base $new $old)
		if [ "$mb" != "$old" ]; then
			echo "$new is not a fast-forward of $old"
			[ "$force" ] || exit 1
			old=
		fi
	fi
	git-update-ref "$refname" $new $old

and the actual update phase will re-verify that "old" is still valid (if it exists at all).

Doing it by hand works, of course, but for example, if we have two symlinks pointing to the same ref, the current locking in git-fetch.sh is broken - it may lock the _symlink_, but since the other one _also_ points to the same thing, there's no locking of the _target_.

git-update-ref should do things like that right. Famous last words ;)
			Linus
Previous: Linus TorvaldsNext: Junio C Hamano
Message 2 of 19 in “Add "git-update-ref" to update the HEAD (or other) ref”
  1. Linus TorvaldsSep 25, 2005
  2. Linus TorvaldsSep 25, 2005
  3. Junio C HamanoSep 25, 2005
  4. Use git-update-ref in scripts.Junio C Hamano, Sep 28, 2005
  5. Linus TorvaldsSep 28, 2005
  6. Junio C HamanoSep 28, 2005
  7. Linus TorvaldsSep 28, 2005
  8. Junio C HamanoSep 28, 2005
  9. Linus TorvaldsSep 28, 2005
  10. Junio C HamanoSep 28, 2005
  11. Linus TorvaldsSep 29, 2005
  12. Junio C HamanoSep 28, 2005
  13. Junio C HamanoSep 28, 2005
  14. Fredrik KuivinenSep 28, 2005
  15. Linus TorvaldsSep 29, 2005
  16. Junio C HamanoSep 25, 2005
  17. Linus TorvaldsSep 26, 2005
  18. Junio C HamanoSep 26, 2005
  19. Linus TorvaldsSep 26, 2005

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.