From: Sam Vilain <sam.vilain@catalyst.net.nz>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Sam Vilain <sam.vilain@catalyst.net.nz>
Subject: [PATCH] contrib/hooks: add post-update hook for updating working copy
Date: Sat, 30 Jun 2007 20:56:20 +1200 [thread overview]
Message-ID: <11831937823588-git-send-email-sam.vilain@catalyst.net.nz> (raw)
In-Reply-To: <11831937822950-git-send-email-sam.vilain@catalyst.net.nz>
Many users want 'git push' to work like 'git pull'; that is, after the
transfer of the new objects, the working copy is updated, too. This
hook tries to be paranoid and never lose any information, as well as
being able to be safely just chmod +x'ed without destroying anything
it shouldn't.
Also allude to this potential feature on the man page for git-push.
Signed-off-by: Sam Vilain <sam.vilain@catalyst.net.nz>
---
Documentation/git-push.txt | 4 ++-
templates/hooks--post-update | 78 +++++++++++++++++++++++++++++++++++++++--
2 files changed, 77 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
index 665f6dc..9f5fbc7 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -20,7 +20,9 @@ necessary to complete the given refs.
You can make interesting things happen to a repository
every time you push into it, by setting up 'hooks' there. See
-documentation for gitlink:git-receive-pack[1].
+documentation for gitlink:git-receive-pack[1]. One commonly
+requested feature, updating the working copy of the target
+repository, must be enabled in this way.
OPTIONS
diff --git a/templates/hooks--post-update b/templates/hooks--post-update
index bcba893..b5d490c 100644
--- a/templates/hooks--post-update
+++ b/templates/hooks--post-update
@@ -1,8 +1,78 @@
#!/bin/sh
#
-# An example hook script to prepare a packed repository for use over
-# dumb transports.
+# This hook does two things:
#
-# To enable this hook, make this file executable by "chmod +x post-update".
+# 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.
+
+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-rev-parse commit $commit^{tree}`
+ 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
-exec git-update-server-info
+ 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
--
1.5.2.1.1131.g3b90
next prev parent reply other threads:[~2007-06-30 8:57 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-30 8:56 a bunch of outstanding updates Sam Vilain
2007-06-30 8:56 ` [PATCH] repack: improve documentation on -a option Sam Vilain
2007-06-30 8:56 ` [PATCH] git-svn: use git-log rather than rev-list | xargs cat-file Sam Vilain
2007-06-30 8:56 ` [PATCH] git-svn: cache max revision in rev_db databases Sam Vilain
2007-06-30 8:56 ` [PATCH] GIT-VERSION-GEN: don't convert - delimiter to .'s Sam Vilain
2007-06-30 8:56 ` [PATCH] git-remote: document -n Sam Vilain
2007-06-30 8:56 ` [PATCH] git-remote: allow 'git-remote fetch' as a synonym for 'git fetch' Sam Vilain
2007-06-30 8:56 ` [PATCH] git-merge-ff: fast-forward only merge Sam Vilain
2007-06-30 8:56 ` [PATCH] git-mergetool: add support for ediff Sam Vilain
2007-06-30 8:56 ` Sam Vilain [this message]
2007-06-30 8:56 ` [PATCH] git-repack: generational repacking (and example hook script) Sam Vilain
2007-07-03 3:36 ` Nicolas Pitre
2007-07-03 4:58 ` Sam Vilain
2007-07-03 14:45 ` Nicolas Pitre
2007-07-03 14:55 ` Shawn O. Pearce
2007-07-04 0:05 ` Sam Vilain
2007-07-04 1:01 ` Johannes Schindelin
2007-07-04 6:16 ` Sam Vilain
2007-07-04 7:02 ` Alex Riesen
2007-07-04 15:42 ` Nicolas Pitre
2007-06-30 17:19 ` [PATCH] contrib/hooks: add post-update hook for updating working copy Junio C Hamano
2007-07-01 22:30 ` Sam Vilain
2007-07-02 1:10 ` Junio C Hamano
2007-06-30 17:19 ` [PATCH] git-mergetool: add support for ediff Junio C Hamano
2007-07-01 22:33 ` Sam Vilain
2007-06-30 14:28 ` [PATCH] git-merge-ff: fast-forward only merge Johannes Schindelin
2007-06-30 18:32 ` Matthias Lederhofer
2007-06-30 17:19 ` [PATCH] git-remote: allow 'git-remote fetch' as a synonym for 'git fetch' Junio C Hamano
2007-06-30 11:12 ` [PATCH] git-remote: document -n Frank Lichtenheld
2007-06-30 17:19 ` [PATCH] GIT-VERSION-GEN: don't convert - delimiter to .'s Junio C Hamano
2007-07-11 10:49 ` Jakub Narebski
2007-07-01 3:50 ` [PATCH] git-svn: cache max revision in rev_db databases Junio C Hamano
2007-07-01 5:31 ` Eric Wong
2007-07-01 6:49 ` Junio C Hamano
2007-06-30 11:15 ` [PATCH] repack: improve documentation on -a option Frank Lichtenheld
2007-06-30 17:19 ` Junio C Hamano
2007-06-30 11:05 ` a bunch of outstanding updates Frank Lichtenheld
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=11831937823588-git-send-email-sam.vilain@catalyst.net.nz \
--to=sam.vilain@catalyst.net.nz \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).