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

Re: [PATCH] post-update hook: update working copy

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 2, 2007, 01:02 UTC
Message-ID
<7vd4ut7948.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<1193964304-10847-1-git-send-email-sam.vilain@catalyst.net.nz>
Sam Vilain <sam.vilain@catalyst.net.nz> writes:
> Now that git-stash is available, it is not so unsafe to push to a
> non-bare repository, but care needs to be taken to preserve any dirty
> working copy or index state.  This hook script does that, using
> git-stash.

Honestly, I am reluctant to do things that _encourages_ pushing into a live tree.

 - Who guarantees that the reflog is enabled for the HEAD?
 - Who guarantees that a human user is not actively editing the
   work tree files without saving?  You would not see "dirty
   state", the editor would notice "the file was modified since
   you started editing it" and tell so to the user, but the user
   cannot recover from the situation without knowing to do the
   three-way merge between HEAD@{1}, HEAD and the index _anyway_.
Show 12 quoted lines
> +update_wc() {
> +	ref=$1
> +	echo "Push to checked out branch $ref" >&2
> +	if (cd $GIT_WORK_TREE; git-diff-files -q --exit-code >/dev/null)
> +	then
> +		wc_dirty=0
> +	else
> +		echo "W:unstaged changes found in working copy" >&2
> +		wc_dirty=1
> +		desc="working copy"
> +	fi
> +	if git diff-index HEAD@{1} >/dev/null
Are you missing "--cached" here?
Show 8 quoted lines
> +	if [ "$wc_dirty" -ne 0 -o "$index_dirty" -ne 0 ]
> +	then
> +		new=$(git rev-parse HEAD)
> +		git-update-ref --no-deref HEAD HEAD@{1}
> +		echo "W:stashing dirty $desc - see git-stash(1)" >&2
> +		(cd $GIT_WORK_TREE
> +		git stash save "dirty $desc before update to $new")
> +		git-symbolic-ref HEAD "$ref"

This part feels somewhat dangerous. What happens if we are interrupted in the middle of these commands?

Show 8 quoted lines
> +	fi
> +
> +	# eye candy - show the WC updates :)
> +	echo "Updating working copy" >&2
> +	(cd $GIT_WORK_TREE
> +	git-diff-index -R --name-status HEAD >&2
> +	git-reset --hard HEAD)
> +}

And I would have expected you would unstash the dirty state here. Are there any reason not to?

Previous: Sam VilainNext: Sam Vilain
Message 2 of 6 in “post-update hook: update working copy”
  1. post-update hook: update working copySam Vilain, Nov 2, 2007
  2. Junio C HamanoNov 2, 2007
  3. Sam VilainNov 2, 2007
  4. Junio C HamanoNov 2, 2007
  5. Andreas EricssonNov 2, 2007
  6. Steven GrimmNov 2, 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.