public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Sam Vilain <sam@vilain•net>
To: git@vger•kernel.org
Subject: Re: post-update script to update wc - suggestions welcome
Date: Wed, 20 Jun 2007 19:03:22 +1200	[thread overview]
Message-ID: <4678D13A.7090904@vilain.net> (raw)
In-Reply-To: <E1I0tZY-0001Uz-00@www.watts.utsl.gen.nz>

Sam Vilain wrote:
> #!/bin/sh
> #
> # An example hook script to prepare a packed repository for use over
> # dumb transports.
> #
> # To enable this hook, make this file executable by "chmod +x post-update".
> 
> git-update-server-info
> 
> ref=$1

In particular, if anyone can think of a clever and reliable way to
detect whether the repository is bare or not (perhaps the presence of
$GIT_DIR/index ?), then this could conceivably become the default
example hook script, by making the below bit conditional on whether this
looks like a non-bare repository.

Sam.

> active=`git-symbolic-ref HEAD`
> if [ "$ref" = "$active" ]
> then
>   echo "Pushing to checked out branch - updating working copy" >&2
>   export GIT_DIR=`cd $GIT_DIR; pwd`
>   cd ..
>   success=
>   if git-diff-files
>   then
>     git-diff-index -z -R --name-status HEAD | perl -n0 -le \
> 	'if ($z^=1) {
> 		$status=$_;
> 	 }
> 	 else {
>         	$filename=$_;
> 		printf STDERR "$status\t$filename\n";
> 		if($status eq "D"){
> 			unlink($filename)
> 				or die("unlink($filename) failed; $!")
> 		}
>          }' &&
>     git-reset --hard HEAD && success=1
>   fi
>   if [ -z "$success" ]
>   then
>     (
>     echo "Non-bare repository checkout is not clean - not updating it"
>     echo "However I AM going to update the index.  Any in-progress commit"
>     echo "happening in that checkout will be thrown away, but on the bright"
>     echo "side this is probably the least confusing thing for us to do and"
>     echo "at least we're not throwing any files somebody has changed away"
>     git-reset --mixed HEAD
>     echo 
>     echo "This is the new status of the upstream working copy:"
>     git-status
>     ) >&2
>   fi
> fi
> -
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger•kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2007-06-20  7:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-20  6:21 post-update script to update wc - suggestions welcome Sam Vilain
2007-06-20  7:03 ` Sam Vilain [this message]
2007-06-20  8:52 ` Junio C Hamano
2007-06-20 20:14   ` Sam Vilain
2007-06-20 21:02     ` Junio C Hamano
2007-06-20 22:28       ` Sam Vilain

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=4678D13A.7090904@vilain.net \
    --to=sam@vilain$(echo .)net \
    --cc=git@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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