git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* post-update script to update wc - version 2
@ 2007-06-27  2:05 Sam Vilain
  2007-06-27  2:06 ` Sam Vilain
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Sam Vilain @ 2007-06-27  2:05 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-06-27 23:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-27  2:05 post-update script to update wc - version 2 Sam Vilain
2007-06-27  2:06 ` Sam Vilain
2007-06-27  9:21   ` Alex Riesen
2007-06-27 10:09     ` Junio C Hamano
2007-06-27 12:43       ` Alex Riesen
2007-06-27 22:45     ` Sam Vilain
2007-06-27  7:54 ` Steven Grimm
2007-06-27 23:53   ` Sam Vilain
2007-06-27 10:36 ` Johannes Schindelin

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