git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Sam Vilain <sam.vilain@catalyst.net.nz>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] post-update hook: update working copy
Date: Thu, 01 Nov 2007 18:02:15 -0700	[thread overview]
Message-ID: <7vd4ut7948.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <1193964304-10847-1-git-send-email-sam.vilain@catalyst.net.nz> (Sam Vilain's message of "Fri, 2 Nov 2007 13:45:04 +1300")

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_.

> +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?

> +	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?

> +	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?

  reply	other threads:[~2007-11-02  1:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-02  0:45 [PATCH] post-update hook: update working copy Sam Vilain
2007-11-02  1:02 ` Junio C Hamano [this message]
2007-11-02  3:36   ` Sam Vilain
2007-11-02  8:49     ` Junio C Hamano
2007-11-02 10:34   ` Andreas Ericsson
2007-11-02 17:28     ` Steven Grimm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vd4ut7948.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=sam.vilain@catalyst.net.nz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).