# post-update script to update wc - version 2

9 messages from 2007-06-27 to 2007-06-27. Participants: Sam Vilain, Steven Grimm, Alex Riesen, Junio C Hamano, Johannes Schindelin.
Thread: https://gitlist.dev/t/8743

## Sam Vilain, 2007-06-27 02:05

Subject: post-update script to update wc - version 2
Message-ID: <E1I3MuE-0005eO-00@www.watts.utsl.gen.nz>
URL: https://gitlist.dev/e/E1I3MuE-0005eO-00%40www.watts.utsl.gen.nz

```
#!/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

export GIT_DIR=`cd $GIT_DIR; pwd`
[ `expr "$GIT_DIR" : '.*/\.git'` = 0 ] && exit 0

tree_in_revlog() {
    ref=$1
    tree=$2
    found=$(
    tail logs/$ref | while read commit rubbish
    do
        this_tree=`git-cat-file commit $commit | awk '/^tree/ { print $2; exit }'`
	if [ "$this_tree" = "$tree" ]
        then
	    echo $commit
        fi
    done
    )
    [ -n "$found" ] && true
}

for ref
do
active=`git-symbolic-ref HEAD`
if [ "$ref" = "$active" ]
then
  echo "Pushing to checked out branch - updating working copy" >&2
  success=
  if ! (cd ..; git-diff-files) | grep -q .
  then
    # save the current index just in case
    current_tree=`git-write-tree`
    if tree_in_revlog $ref $current_tree
    then
      cd ..
      if git-diff-index -R --name-status HEAD >&2 &&
         git-diff-index -z --name-only --diff-filter=A HEAD | xargs -0r rm &&
         git-reset --hard HEAD
      then
         success=1
      else
        echo "E:unexpected error during update" >&2
      fi
    else
      echo "E:uncommitted, staged changes found" >&2
    fi
  else
    echo "E:unstaged changes found" >&2
  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 half-staged commit"
    echo "in that checkout will be thrown away, but on the bright side"
    echo "this is probably the least confusing thing for us to do and at"
    echo "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
done

```

## Sam Vilain, 2007-06-27 02:06

Subject: Re: post-update script to update wc - version 2
Message-ID: <4681C640.6060408@vilain.net>
URL: https://gitlist.dev/e/4681C640.6060408%40vilain.net
In-Reply-To: <E1I3MuE-0005eO-00@www.watts.utsl.gen.nz>

```
Sam Vilain wrote:
>         this_tree=`git-cat-file commit $commit | awk '/^tree/ { print $2; exit }'`

Of course on newer git, `git-rev-parse $commit:` will do that.

Sam.

```

## Steven Grimm, 2007-06-27 07:54

Subject: Re: post-update script to update wc - version 2
Message-ID: <468217B4.3030708@midwinter.com>
URL: https://gitlist.dev/e/468217B4.3030708%40midwinter.com
In-Reply-To: <E1I3MuE-0005eO-00@www.watts.utsl.gen.nz>

```
Sam Vilain wrote:
> # An example hook script to prepare a packed repository for use over
> # dumb transports.
>   
Maybe this comment isn't quite accurate any more?

-Steve

```

## Alex Riesen, 2007-06-27 09:21

Subject: Re: post-update script to update wc - version 2
Message-ID: <81b0412b0706270221y40bac0a7gf6b73eda9f1e4bb0@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0706270221y40bac0a7gf6b73eda9f1e4bb0%40mail.gmail.com
In-Reply-To: <4681C640.6060408@vilain.net>

```
On 6/27/07, Sam Vilain <sam@vilain.net> wrote:
> Sam Vilain wrote:
> >         this_tree=`git-cat-file commit $commit | awk '/^tree/ { print $2; exit }'`
>
> Of course on newer git, `git-rev-parse $commit:` will do that.
>

Are you sure? Maybe you mean git-rev-parse "$commit"^{tree}?

```

## Junio C Hamano, 2007-06-27 10:09

Subject: Re: post-update script to update wc - version 2
Message-ID: <7vved9pv2h.fsf@assigned-by-dhcp.pobox.com>
URL: https://gitlist.dev/e/7vved9pv2h.fsf%40assigned-by-dhcp.pobox.com
In-Reply-To: <81b0412b0706270221y40bac0a7gf6b73eda9f1e4bb0@mail.gmail.com>

```
"Alex Riesen" <raa.lkml@gmail.com> writes:

> On 6/27/07, Sam Vilain <sam@vilain.net> wrote:
>> Sam Vilain wrote:
>> >         this_tree=`git-cat-file commit $commit | awk '/^tree/ { print $2; exit }'`
>>
>> Of course on newer git, `git-rev-parse $commit:` will do that.
>
> Are you sure? Maybe you mean git-rev-parse "$commit"^{tree}?

I had the same "Huh?"  moment as you had, but what Sam said is
correct.  He is being too clever to confuse us ;-).

When "$commit" is a tree-ish,

	$commit:$path

is the name of the tree or blob object at that $path, and as 
very strange special case, an empty $path is the whole tree.

It's been this way since early this year (before v1.5.0-rc1),
thanks to Jeff King.

```

## Johannes Schindelin, 2007-06-27 10:36

Subject: Re: post-update script to update wc - version 2
Message-ID: <Pine.LNX.4.64.0706271136150.4438@racer.site>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0706271136150.4438%40racer.site
In-Reply-To: <E1I3MuE-0005eO-00@www.watts.utsl.gen.nz>

```
Hi,

On Wed, 27 Jun 2007, Sam Vilain wrote:

> # An example hook script to prepare a packed repository for use over
> # dumb transports.

???

Ciao,
Dscho

```

## Alex Riesen, 2007-06-27 12:43

Subject: Re: post-update script to update wc - version 2
Message-ID: <81b0412b0706270543s7dd37e3ds1acfe671f647617@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0706270543s7dd37e3ds1acfe671f647617%40mail.gmail.com
In-Reply-To: <7vved9pv2h.fsf@assigned-by-dhcp.pobox.com>

```
On 6/27/07, Junio C Hamano <gitster@pobox.com> wrote:
> "Alex Riesen" <raa.lkml@gmail.com> writes:
> > On 6/27/07, Sam Vilain <sam@vilain.net> wrote:
> >> Sam Vilain wrote:
> >> >         this_tree=`git-cat-file commit $commit | awk '/^tree/ { print $2; exit }'`
> >>
> >> Of course on newer git, `git-rev-parse $commit:` will do that.
> >
> > Are you sure? Maybe you mean git-rev-parse "$commit"^{tree}?
>
> I had the same "Huh?"  moment as you had, but what Sam said is
> correct.  He is being too clever to confuse us ;-).
>
> When "$commit" is a tree-ish,
>
>         $commit:$path
>
> is the name of the tree or blob object at that $path, and as
> very strange special case, an empty $path is the whole tree.

I didn't even see the colon. That's GMail, they obviously have
no idea what font should be used for the mail of a technical user.

```

## Sam Vilain, 2007-06-27 22:45

Subject: Re: post-update script to update wc - version 2
Message-ID: <4682E8A0.8050205@vilain.net>
URL: https://gitlist.dev/e/4682E8A0.8050205%40vilain.net
In-Reply-To: <81b0412b0706270221y40bac0a7gf6b73eda9f1e4bb0@mail.gmail.com>

```
Alex Riesen wrote:
> On 6/27/07, Sam Vilain <sam@vilain.net> wrote:
>> Sam Vilain wrote:
>>>         this_tree=`git-cat-file commit $commit | awk '/^tree/ { print $2; exit }'`
>> Of course on newer git, `git-rev-parse $commit:` will do that.
> Are you sure? Maybe you mean git-rev-parse "$commit"^{tree}?

Ah, I missed that on the git-rev-parse man page.  Much better!

Sam.

```

## Sam Vilain, 2007-06-27 23:53

Subject: Re: post-update script to update wc - version 2
Message-ID: <4682F883.4030609@vilain.net>
URL: https://gitlist.dev/e/4682F883.4030609%40vilain.net
In-Reply-To: <468217B4.3030708@midwinter.com>

```
Steven Grimm wrote:
> Sam Vilain wrote:
>> # An example hook script to prepare a packed repository for use over
>> # dumb transports.
>>   
> Maybe this comment isn't quite accurate any more?

Ok that should read something like

# This hook does two things:
#
#  1. update the "info" files that allow the list of references to be
#     queries over dumb transports such as http
#
#  2. if this repository looks like it is a non-bare repository, and
#     the checked-out branch is pushed to, then update the working copy.
#     This makes "push" and "pull" symmetric operations as in darcs and
#     bzr.

Sam.

```
