git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add a post-tag hook
@ 2009-04-17 22:15 Ammon Riley
  2009-04-17 22:19 ` Shawn O. Pearce
  0 siblings, 1 reply; 4+ messages in thread
From: Ammon Riley @ 2009-04-17 22:15 UTC (permalink / raw)
  To: git

Add a post-tag hook, to allow notifications when a tag is created.
The hook is given the name of the newly created tag.

Signed-off-by: Ammon Riley <ammon.riley@gmail.com>
---
 Documentation/git-tag.txt        |    4 ++++
 Documentation/githooks.txt       |    9 +++++++++
 builtin-tag.c                    |    2 ++
 t/t3800-tag-hook.sh              |   32 ++++++++++++++++++++++++++++++++
 templates/hooks--post-tag.sample |    8 ++++++++
 5 files changed, 55 insertions(+), 0 deletions(-)
 create mode 100755 t/t3800-tag-hook.sh
 create mode 100755 templates/hooks--post-tag.sample

diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index fa73321..3fcb3d4 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -248,6 +248,10 @@ An example follows.
 $ GIT_COMMITTER_DATE="2006-10-02 10:31" git tag -s v1.0.1
 ------------

+HOOKS
+-----
+This command can run the `post-tag` hook. See linkgit:githooks[5]
+for more information.

 Author
 ------
diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
index 1c73673..4512f18 100644
--- a/Documentation/githooks.txt
+++ b/Documentation/githooks.txt
@@ -314,6 +314,15 @@ This hook is invoked by 'git-gc --auto'. It takes
no parameter, and
 exiting with non-zero status from this script causes the 'git-gc --auto'
 to abort.

+post-tag
+--------
+
+This hook is invoked by 'git-tag'.  It takes one parameter, the name
+of the tag, and is invoked after a tag is made.
+
+This hook is meant primarily for notification, and cannot affect
+the outcome of 'git-tag'.
+
 GIT
 ---
 Part of the linkgit:git[1] suite
diff --git a/builtin-tag.c b/builtin-tag.c
index 01e7374..e4509ba 100644
--- a/builtin-tag.c
+++ b/builtin-tag.c
@@ -482,6 +482,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
 	if (write_ref_sha1(lock, object, NULL) < 0)
 		die("%s: cannot update the ref", ref);

+	run_hook(NULL, "post-tag", tag, NULL);
+
 	strbuf_release(&buf);
 	return 0;
 }
diff --git a/t/t3800-tag-hook.sh b/t/t3800-tag-hook.sh
new file mode 100755
index 0000000..68c5877
--- /dev/null
+++ b/t/t3800-tag-hook.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+test_description='git tag with its hook
+
+This test creates a post-tag hook and tests it.'
+
+. ./test-lib.sh
+
+TAG_FILE="$(pwd)/output"
+export TAG_FILE
+
+test_expect_success 'Setting up post-tag hook' '
+    mkdir -p .git/hooks &&
+    echo >.git/hooks/post-tag "#!/bin/sh
+    echo -n \$@ > \"\${TAG_FILE}\"
+    echo Post commit hook was called." &&
+    chmod +x .git/hooks/post-tag
+'
+
+test_expect_success 'post-tag hook gets correct input' '
+    test \! -e "${TAG_FILE}" &&
+    echo initial >file &&
+    git add file &&
+    git commit -m initial &&
+    git tag mytag &&
+    test -r "${TAG_FILE}" &&
+    test "z$(cat "${TAG_FILE}")" = zmytag
+'
+
+rm -rf "${TAG_FILE}"
+
+test_done
diff --git a/templates/hooks--post-tag.sample b/templates/hooks--post-tag.sample
new file mode 100755
index 0000000..5f6a3d3
--- /dev/null
+++ b/templates/hooks--post-tag.sample
@@ -0,0 +1,8 @@
+#!/bin/sh
+#
+# An example hook script that is called after a successful
+# tag is made.
+#
+# To enable this hook, rename this file to "post-tag".
+
+: Nothing
-- 
1.5.4.3

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

* Re: [PATCH] Add a post-tag hook
  2009-04-17 22:15 [PATCH] Add a post-tag hook Ammon Riley
@ 2009-04-17 22:19 ` Shawn O. Pearce
  2009-04-17 22:28   ` Ammon Riley
  0 siblings, 1 reply; 4+ messages in thread
From: Shawn O. Pearce @ 2009-04-17 22:19 UTC (permalink / raw)
  To: Ammon Riley; +Cc: git

Ammon Riley <ammon.riley@gmail.com> wrote:
> Add a post-tag hook, to allow notifications when a tag is created.
> The hook is given the name of the newly created tag.

Why would you want to send notifications upon creating a tag in
your local repository?

Usually a tag is only interesting when it has been sent to a shared
public repository, which is by git push, and thus is caught by a
git receive-pack hook like post-update or post-receive.

> +HOOKS
> +-----
> +This command can run the `post-tag` hook. See linkgit:githooks[5]
> +for more information.
...
> +post-tag
> +--------
> +
> +This hook is invoked by 'git-tag'.  It takes one parameter, the name
> +of the tag, and is invoked after a tag is made.
> +
> +This hook is meant primarily for notification, and cannot affect
> +the outcome of 'git-tag'.

-- 
Shawn.

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

* Re: [PATCH] Add a post-tag hook
  2009-04-17 22:19 ` Shawn O. Pearce
@ 2009-04-17 22:28   ` Ammon Riley
  2009-04-24 16:41     ` Pat Notz
  0 siblings, 1 reply; 4+ messages in thread
From: Ammon Riley @ 2009-04-17 22:28 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: git

On Fri, Apr 17, 2009 at 3:19 PM, Shawn O. Pearce <spearce@spearce.org> wrote:
> Ammon Riley <ammon.riley@gmail.com> wrote:
>> Add a post-tag hook, to allow notifications when a tag is created.
>> The hook is given the name of the newly created tag.
>
> Why would you want to send notifications upon creating a tag in
> your local repository?
>
> Usually a tag is only interesting when it has been sent to a shared
> public repository, which is by git push, and thus is caught by a
> git receive-pack hook like post-update or post-receive.

On the particular project I'm working on, we're not really using git
in the most distributed fashion -- it's completely internal to the
company. In our case, the tags are being created directly on
the shared repository, rather than on a local repository and being
pushed.

Cheers,
Ammon

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

* Re: [PATCH] Add a post-tag hook
  2009-04-17 22:28   ` Ammon Riley
@ 2009-04-24 16:41     ` Pat Notz
  0 siblings, 0 replies; 4+ messages in thread
From: Pat Notz @ 2009-04-24 16:41 UTC (permalink / raw)
  To: Ammon Riley; +Cc: Shawn O. Pearce, git

On Fri, Apr 17, 2009 at 4:28 PM, Ammon Riley <ammon.riley@gmail.com> wrote:
>
> On Fri, Apr 17, 2009 at 3:19 PM, Shawn O. Pearce <spearce@spearce.org> wrote:
> > Ammon Riley <ammon.riley@gmail.com> wrote:
> >> Add a post-tag hook, to allow notifications when a tag is created.
> >> The hook is given the name of the newly created tag.
> >
> > Why would you want to send notifications upon creating a tag in
> > your local repository?
> >
> > Usually a tag is only interesting when it has been sent to a shared
> > public repository, which is by git push, and thus is caught by a
> > git receive-pack hook like post-update or post-receive.
>
> On the particular project I'm working on, we're not really using git
> in the most distributed fashion -- it's completely internal to the
> company. In our case, the tags are being created directly on
> the shared repository, rather than on a local repository and being
> pushed.

Today, this same situation came up in my organization.  It seem like a
natural partner of the post-commit hook.

>
> Cheers,
> Ammon
> --
> 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

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

end of thread, other threads:[~2009-04-24 16:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-17 22:15 [PATCH] Add a post-tag hook Ammon Riley
2009-04-17 22:19 ` Shawn O. Pearce
2009-04-17 22:28   ` Ammon Riley
2009-04-24 16:41     ` Pat Notz

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