{"thread":{"id":"10021","subject":"[PATCH] Documentation for post-checkout and post-merge hooks","startedAt":"2007-09-25T22:49:21Z","lastAt":"2007-09-26T17:16:50Z","messageCount":6,"participants":["Josh England","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"54058","messageId":"1190760563-32453-1-git-send-email-jjengla@sandia.gov","threadId":"10021","inReplyTo":null,"subject":"[PATCH] post-checkout hooks and related tests","fromName":"Josh England","fromEmail":"jjengla@sandia.gov","sentAt":"2007-09-25T22:49:21Z","receivedAt":"2007-09-25T22:49:21Z","isPatch":true,"sender":{"key":"jjengla@sandia.gov","avatar":null},"body":"Signed-off-by: Josh England <jjengla@sandia.gov>\n---\n git-checkout.sh               |   12 +++++++\n t/t5403-post-checkout-hook.sh |   70 +++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 82 insertions(+), 0 deletions(-)\n create mode 100755 t/t5403-post-checkout-hook.sh\n\ndiff --git a/git-checkout.sh b/git-checkout.sh\nindex 17f4392..78355eb 100755\n--- a/git-checkout.sh\n+++ b/git-checkout.sh\n@@ -137,6 +137,13 @@ Did you intend to checkout '$@' which can not be resolved as commit?\"\n \tgit ls-files --error-unmatch -- \"$@\" >/dev/null || exit\n \tgit ls-files -- \"$@\" |\n \tgit checkout-index -f -u --stdin\n+\n+        # Run a post-checkout hook -- the HEAD does not change so the\n+\t# current HEAD is passed in for both args\n+\tif test -x \"$GIT_DIR\"/hooks/post-checkout; then\n+\t    \"$GIT_DIR\"/hooks/post-checkout $old $old\n+\tfi\n+\n \texit $?\n else\n \t# Make sure we did not fall back on $arg^{tree} codepath\n@@ -284,3 +291,8 @@ if [ \"$?\" -eq 0 ]; then\n else\n \texit 1\n fi\n+\n+# Run a post-checkout hook\n+if test -x \"$GIT_DIR\"/hooks/post-checkout; then\n+        \"$GIT_DIR\"/hooks/post-checkout $old $new\n+fi\ndiff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh\nnew file mode 100755\nindex 0000000..663f8d7\n--- /dev/null\n+++ b/t/t5403-post-checkout-hook.sh\n@@ -0,0 +1,70 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2006 Josh England\n+#\n+\n+test_description='Test the post-checkout hook.'\n+. ./test-lib.sh\n+\n+test_expect_success setup '\n+\techo Data for commit0. >a &&\n+\techo Data for commit0. >b &&\n+\tgit update-index --add a &&\n+\tgit update-index --add b &&\n+\ttree0=$(git write-tree) &&\n+\tcommit0=$(echo setup | git commit-tree $tree0) &&\n+        git update-ref refs/heads/master $commit0 &&\n+\tgit-clone ./. clone1 &&\n+\tgit-clone ./. clone2 &&\n+        GIT_DIR=clone2/.git git branch -a new2 &&\n+       \techo Data for commit1. >clone2/b &&\n+\tGIT_DIR=clone2/.git git add clone2/b &&\n+\tGIT_DIR=clone2/.git git commit -m new2\n+'\n+\n+for clone in 1 2; do \n+    cat >clone${clone}/.git/hooks/post-checkout <<'EOF'\n+#!/bin/sh\n+echo $@ > $GIT_DIR/post-checkout.args\n+EOF\n+    chmod u+x clone${clone}/.git/hooks/post-checkout\n+done\n+\n+test_expect_success 'post-checkout runs as expected ' '\n+        GIT_DIR=clone1/.git git checkout master &&\n+ \ttest -e clone1/.git/post-checkout.args\n+'\n+\n+test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' '\n+         old=$(awk \"{print \\$1}\" clone1/.git/post-checkout.args) &&\n+         new=$(awk \"{print \\$2}\" clone1/.git/post-checkout.args) &&\n+         test $old = $new\n+'\n+\n+test_expect_success 'post-checkout runs as expected ' '\n+        GIT_DIR=clone1/.git git checkout master &&\n+ \ttest -e clone1/.git/post-checkout.args\n+'\n+\n+test_expect_success 'post-checkout args are correct with git checkout -b ' '\n+        GIT_DIR=clone1/.git git checkout -b new1 &&\n+        old=$(awk \"{print \\$1}\" clone1/.git/post-checkout.args) &&\n+        new=$(awk \"{print \\$2}\" clone1/.git/post-checkout.args) &&\n+        test $old = $new\n+'\n+\n+test_expect_success 'post-checkout receives the right args with HEAD changed ' '\n+        GIT_DIR=clone2/.git git checkout new2 &&\n+        old=$(awk \"{print \\$1}\" clone2/.git/post-checkout.args) &&\n+        new=$(awk \"{print \\$2}\" clone2/.git/post-checkout.args) &&\n+        test $old != $new\n+'\n+\n+test_expect_success 'post-checkout receives the right args when not switching branches ' '\n+        GIT_DIR=clone2/.git git checkout master b &&\n+        old=$(awk \"{print \\$1}\" clone2/.git/post-checkout.args) &&\n+        new=$(awk \"{print \\$2}\" clone2/.git/post-checkout.args) &&\n+        test $old == $new\n+'\n+\n+test_done\n-- \n1.5.3.2.89.g296e\n"},{"id":"54057","messageId":"1190760563-32453-2-git-send-email-jjengla@sandia.gov","threadId":"10021","inReplyTo":"1190760563-32453-1-git-send-email-jjengla@sandia.gov","subject":"[PATCH] post-merge hook and related tests","fromName":"Josh England","fromEmail":"jjengla@sandia.gov","sentAt":"2007-09-25T22:49:22Z","receivedAt":"2007-09-25T22:49:22Z","isPatch":true,"sender":{"key":"jjengla@sandia.gov","avatar":null},"body":"Signed-off-by: Josh England <jjengla@sandia.gov>\n---\n git-merge.sh               |   13 ++++++++++\n t/t5402-post-merge-hook.sh |   56 ++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 69 insertions(+), 0 deletions(-)\n create mode 100644 t/t5402-post-merge-hook.sh\n\ndiff --git a/git-merge.sh b/git-merge.sh\nindex 3a01db0..66e48b3 100755\n--- a/git-merge.sh\n+++ b/git-merge.sh\n@@ -97,6 +97,19 @@ finish () {\n \t\tfi\n \t\t;;\n \tesac\n+\n+\t# Run a post-merge hook\n+        if test -x \"$GIT_DIR\"/hooks/post-merge\n+        then\n+\t    case \"$squash\" in\n+\t    t)\n+                \"$GIT_DIR\"/hooks/post-merge 1\n+\t\t;;\n+\t    '')\n+                \"$GIT_DIR\"/hooks/post-merge 0\n+\t\t;;\n+\t    esac\n+        fi\n }\n \n merge_name () {\ndiff --git a/t/t5402-post-merge-hook.sh b/t/t5402-post-merge-hook.sh\nnew file mode 100644\nindex 0000000..2a7a097\n--- /dev/null\n+++ b/t/t5402-post-merge-hook.sh\n@@ -0,0 +1,56 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2006 Josh England\n+#\n+\n+test_description='Test the post-merge hook.'\n+. ./test-lib.sh\n+\n+test_expect_success setup '\n+\techo Data for commit0. >a &&\n+\tgit update-index --add a &&\n+\ttree0=$(git write-tree) &&\n+\tcommit0=$(echo setup | git commit-tree $tree0) &&\n+\techo Changed data for commit1. >a &&\n+\tgit update-index a &&\n+\ttree1=$(git write-tree) &&\n+\tcommit1=$(echo modify | git commit-tree $tree1 -p $commit0) &&\n+        git update-ref refs/heads/master $commit0 &&     \n+\tgit-clone ./. clone1 &&\n+\tGIT_DIR=clone1/.git git update-index --add a &&\n+\tgit-clone ./. clone2 &&\n+\tGIT_DIR=clone2/.git git update-index --add a\n+'\n+\n+for clone in 1 2; do \n+    cat >clone${clone}/.git/hooks/post-merge <<'EOF'\n+#!/bin/sh\n+echo $@ >> $GIT_DIR/post-merge.args\n+EOF\n+    chmod u+x clone${clone}/.git/hooks/post-merge\n+done\n+\n+test_expect_failure 'post-merge does not run for up-to-date ' '\n+        GIT_DIR=clone1/.git git merge $commit0 &&\n+ \ttest -e clone1/.git/post-merge.args\n+'\n+\n+test_expect_success 'post-merge runs as expected ' '\n+        GIT_DIR=clone1/.git git merge $commit1 &&\n+ \ttest -e clone1/.git/post-merge.args\n+'\n+\n+test_expect_success 'post-merge from normal merge receives the right argument ' '\n+        grep 0 clone1/.git/post-merge.args\n+'\n+\n+test_expect_success 'post-merge from squash merge runs as expected ' '\n+        GIT_DIR=clone2/.git git merge --squash $commit1 &&\n+ \ttest -e clone2/.git/post-merge.args\n+'\n+\n+test_expect_success 'post-merge from squash merge receives the right argument ' '\n+        grep 1 clone2/.git/post-merge.args\n+'\n+\n+test_done\n-- \n1.5.3.2.89.g296e\n"},{"id":"54056","messageId":"1190760563-32453-3-git-send-email-jjengla@sandia.gov","threadId":"10021","inReplyTo":"1190760563-32453-2-git-send-email-jjengla@sandia.gov","subject":"[PATCH] Documentation for post-checkout and post-merge hooks","fromName":"Josh England","fromEmail":"jjengla@sandia.gov","sentAt":"2007-09-25T22:49:23Z","receivedAt":"2007-09-25T22:49:23Z","isPatch":true,"sender":{"key":"jjengla@sandia.gov","avatar":null},"body":"Signed-off-by: Josh England <jjengla@sandia.gov>\n---\n Documentation/hooks.txt |   25 +++++++++++++++++++++++++\n 1 files changed, 25 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/hooks.txt b/Documentation/hooks.txt\nindex c39edc5..37a3e5a 100644\n--- a/Documentation/hooks.txt\n+++ b/Documentation/hooks.txt\n@@ -87,6 +87,31 @@ parameter, and is invoked after a commit is made.\n This hook is meant primarily for notification, and cannot affect\n the outcome of `git-commit`.\n \n+post-checkout\n+-----------\n+\n+This hook is invoked when a `git-checkout` is run after having updated the\n+worktree.  The hook is given two parameters: the ref of the previous HEAD and\n+the ref of the new HEAD, which may or may not have changed.  This hook cannot\n+affect the outcome of `git-checkout`.\n+\n+This hook can be used to perform repository validity checks, auto-display\n+differences from the previous HEAD if different, or set working dir metadata\n+properties.\n+\n+post-merge\n+-----------\n+\n+This hook is invoked by `git-merge`, which happens when a `git pull`\n+is done on a local repository.  The hook takes a single parameter, a status\n+flag specifying whether or not the merge being done was a squash merge.\n+This hook cannot affect the outcome of `git-merge`.\n+\n+This hook can be used in conjunction with a corresponding pre-commit hook to\n+save and restore any form of metadata associated with the working tree\n+(eg: permissions/ownership, ACLS, etc).  See contrib/hooks/setgitperms.pl\n+for an example of how to do this.\n+\n [[pre-receive]]\n pre-receive\n -----------\n-- \n1.5.3.2.89.g296e\n"},{"id":"54062","messageId":"7vve9y2v39.fsf@gitster.siamese.dyndns.org","threadId":"10021","inReplyTo":"1190760563-32453-1-git-send-email-jjengla@sandia.gov","subject":"Re: [PATCH] post-checkout hooks and related tests","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-09-25T23:17:46Z","receivedAt":"2007-09-25T23:17:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Josh England\" <jjengla@sandia.gov> writes:\n\n> diff --git a/git-checkout.sh b/git-checkout.sh\n> index 17f4392..78355eb 100755\n> --- a/git-checkout.sh\n> +++ b/git-checkout.sh\n> @@ -137,6 +137,13 @@ Did you intend to checkout '$@' which can not be resolved as commit?\"\n>  \tgit ls-files --error-unmatch -- \"$@\" >/dev/null || exit\n>  \tgit ls-files -- \"$@\" |\n>  \tgit checkout-index -f -u --stdin\n> +\n> +        # Run a post-checkout hook -- the HEAD does not change so the\n> +\t# current HEAD is passed in for both args\n> +\tif test -x \"$GIT_DIR\"/hooks/post-checkout; then\n\nIt is usually a good idea to view your patch in your MUA before\nsending them out.\n\nYou will spot HT vs SP indentation inconsistencies right away.\n\nHEAD did not change but don't you want to differenciate if the\ncheckout was from the index or from the HEAD?  If not why not?\n"},{"id":"54063","messageId":"7vr6km2uwi.fsf@gitster.siamese.dyndns.org","threadId":"10021","inReplyTo":"1190760563-32453-2-git-send-email-jjengla@sandia.gov","subject":"Re: [PATCH] post-merge hook and related tests","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-09-25T23:21:49Z","receivedAt":"2007-09-25T23:21:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Josh England\" <jjengla@sandia.gov> writes:\n\n> Signed-off-by: Josh England <jjengla@sandia.gov>\n> ---\n>  git-merge.sh               |   13 ++++++++++\n>  t/t5402-post-merge-hook.sh |   56 ++++++++++++++++++++++++++++++++++++++++++++\n>  2 files changed, 69 insertions(+), 0 deletions(-)\n>  create mode 100644 t/t5402-post-merge-hook.sh\n\nI think this is part of the 'master' for at least a few days, so\nis a half of the Documentation patch.\n"},{"id":"54106","messageId":"1190827010.6078.123.camel@beauty","threadId":"10021","inReplyTo":"7vve9y2v39.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] post-checkout hooks and related tests","fromName":"Josh England","fromEmail":"jjengla@sandia.gov","sentAt":"2007-09-26T17:16:50Z","receivedAt":"2007-09-26T17:16:50Z","isPatch":true,"sender":{"key":"jjengla@sandia.gov","avatar":null},"body":"On Tue, 2007-09-25 at 16:17 -0700, Junio C Hamano wrote:\n> \"Josh England\" <jjengla@sandia.gov> writes:\n> \n> > diff --git a/git-checkout.sh b/git-checkout.sh\n> > index 17f4392..78355eb 100755\n> > --- a/git-checkout.sh\n> > +++ b/git-checkout.sh\n> > @@ -137,6 +137,13 @@ Did you intend to checkout '$@' which can not be resolved as commit?\"\n> >  \tgit ls-files --error-unmatch -- \"$@\" >/dev/null || exit\n> >  \tgit ls-files -- \"$@\" |\n> >  \tgit checkout-index -f -u --stdin\n> > +\n> > +        # Run a post-checkout hook -- the HEAD does not change so the\n> > +\t# current HEAD is passed in for both args\n> > +\tif test -x \"$GIT_DIR\"/hooks/post-checkout; then\n> \n> It is usually a good idea to view your patch in your MUA before\n> sending them out.\n>\n> You will spot HT vs SP indentation inconsistencies right away.\n\nDang.  It looked ok in emacs.  :(\n\n> HEAD did not change but don't you want to differenciate if the\n> checkout was from the index or from the HEAD?  If not why not?\n\nHmmmm.  It wouldn't hurt to add another arg though I guess in case\nsomeone might use it.  I'm just trying to figure out how to word this\nnicely in the Documentation.\n\n-JE\n"}]}