From: Felipe Contreras <felipe.contreras@gmail.com>
To: Ilya Bobyr <ilya.bobyr@gmail.com>,
Felipe Contreras <felipe.contreras@gmail.com>,
git@vger.kernel.org
Subject: Re: [RTC/PATCH] Add 'update-branch' hook
Date: Tue, 22 Apr 2014 11:27:02 -0500 [thread overview]
Message-ID: <535698563b5d1_3e5aed7308da@nysa.notmuch> (raw)
In-Reply-To: <53560DA6.5040202@gmail.com>
Ilya Bobyr wrote:
> On 4/20/2014 7:23 PM, Felipe Contreras wrote:
> > [...]
> >
> > diff --git a/branch.c b/branch.c
> > index 660097b..c2058d1 100644
> > --- a/branch.c
> > +++ b/branch.c
> > @@ -4,6 +4,7 @@
> > #include "refs.h"
> > #include "remote.h"
> > #include "commit.h"
> > +#include "run-command.h"
> >
> > struct tracking {
> > struct refspec spec;
> > @@ -304,6 +305,11 @@ void create_branch(const char *head,
> > if (real_ref && track)
> > setup_tracking(ref.buf + 11, real_ref, track, quiet);
> >
> > + if (run_hook_le(NULL, "update-branch", ref.buf + 11, sha1_to_hex(sha1), NULL)) {
> > + unlock_ref(lock);
>
> lock is NULL if dont_change_ref is true. unlock_ref() would crash in
> that case.
> You may want to add a test for that.
That should be easy to fix.
> > + die("hook 'update-branch' returned error");
> > + }
> > +
> > if (!dont_change_ref)
> > if (write_ref_sha1(lock, sha1, msg) < 0)
> > die_errno(_("Failed to write ref"));
> > diff --git a/builtin/clone.c b/builtin/clone.c
> > index 9b3c04d..6ec96e5 100644
> > --- a/builtin/clone.c
> > +++ b/builtin/clone.c
> > @@ -581,9 +581,10 @@ static void update_remote_refs(const struct ref *refs,
> > }
> > }
> >
> > -static void update_head(const struct ref *our, const struct ref *remote,
> > +static int update_head(const struct ref *our, const struct ref *remote,
> > const char *msg)
> > {
> > + int err = 0;
> > if (our && starts_with(our->name, "refs/heads/")) {
> > /* Local default branch link */
> > create_symref("HEAD", our->name, NULL);
> > @@ -591,6 +592,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
> > const char *head = skip_prefix(our->name, "refs/heads/");
> > update_ref(msg, "HEAD", our->old_sha1, NULL, 0, DIE_ON_ERR);
> > install_branch_config(0, head, option_origin, our->name);
> > + err = run_hook_le(NULL, "update-branch", head, sha1_to_hex(our->old_sha1), NULL);
>
> This is happening after the branch is updated and a config section for
> it is created.
I see that now, however, I cannot find where in builtin/clone.c is the branch
ref actually updated.
Worst, I don't see how I could possibly configure a hook to be triggered when
cloning, so I cannot test.
> > }
> > } else if (our) {
> > struct commit *c = lookup_commit_reference(our->old_sha1);
> > @@ -606,6 +608,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
> > update_ref(msg, "HEAD", remote->old_sha1,
> > NULL, REF_NODEREF, DIE_ON_ERR);
> > }
> > + return err;
> > }
> >
> > static int checkout(void)
> > @@ -987,7 +990,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
> > update_remote_refs(refs, mapped_refs, remote_head_points_at,
> > branch_top.buf, reflog_msg.buf, transport, !is_local);
> >
> > - update_head(our_head_points_at, remote_head, reflog_msg.buf);
> > + err = update_head(our_head_points_at, remote_head, reflog_msg.buf);
> >
> > transport_unlock_pack(transport);
> > transport_disconnect(transport);
> > diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
> > index 1c41cbd..084dc36 100644
> > --- a/git-rebase--interactive.sh
> > +++ b/git-rebase--interactive.sh
> > @@ -631,7 +631,11 @@ do_next () {
> > git update-ref -m "$message" $head_name $newhead $orig_head &&
> > git symbolic-ref \
> > -m "$GIT_REFLOG_ACTION: returning to $head_name" \
> > - HEAD $head_name
> > + HEAD $head_name &&
> > + if test -x "$GIT_DIR"/hooks/update-branch; then
> > + "$GIT_DIR"/hooks/update-branch $branch_name \
> > + $newhead $onto
> > + fi
>
> It looks like this is also after the branch was already updated.
This and the one below should be easy to fix.
--
Felipe Contreras
prev parent reply other threads:[~2014-04-22 16:37 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-21 2:23 [RTC/PATCH] Add 'update-branch' hook Felipe Contreras
2014-04-21 7:25 ` Eric Sunshine
2014-04-21 20:02 ` Ilya Bobyr
2014-04-21 20:49 ` Felipe Contreras
2014-04-21 21:15 ` Ilya Bobyr
2014-04-21 21:17 ` Felipe Contreras
2014-04-21 21:39 ` Ilya Bobyr
2014-04-21 21:36 ` Felipe Contreras
2014-04-22 14:43 ` Stephen Leake
2014-04-22 16:31 ` Felipe Contreras
2014-04-22 17:09 ` Ilya Bobyr
2014-04-22 17:28 ` Felipe Contreras
2014-04-23 7:49 ` Stephen Leake
2014-04-23 9:07 ` Felipe Contreras
2014-04-23 22:44 ` Junio C Hamano
2014-04-24 1:11 ` Felipe Contreras
2014-04-26 17:38 ` Junio C Hamano
2014-04-26 19:28 ` Felipe Contreras
2014-04-24 14:26 ` Stephen Leake
2014-04-24 18:08 ` Felipe Contreras
2014-04-21 21:52 ` Junio C Hamano
2014-04-21 22:26 ` Felipe Contreras
2014-04-21 23:00 ` Junio C Hamano
2014-04-23 21:30 ` Felipe Contreras
2014-04-23 22:15 ` Junio C Hamano
2014-04-24 1:00 ` Felipe Contreras
2014-04-22 6:41 ` Ilya Bobyr
2014-04-22 16:30 ` Felipe Contreras
2014-04-21 21:17 ` Ilya Bobyr
2014-04-21 21:15 ` Felipe Contreras
2014-04-21 21:36 ` Ilya Bobyr
2014-04-21 21:35 ` Felipe Contreras
[not found] ` <CADcHDF+XcWEkvyP3tL4ibicnaMVJpixUZu1Ces0BXWkzPGsodw@mail.gmail.com>
2014-04-21 22:24 ` Felipe Contreras
2014-04-22 6:05 ` Ilya Bobyr
2014-04-22 6:45 ` Felipe Contreras
2014-04-22 7:00 ` Ilya Bobyr
2014-04-22 6:56 ` Felipe Contreras
2014-04-22 6:35 ` Ilya Bobyr
2014-04-22 16:27 ` Felipe Contreras [this message]
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=535698563b5d1_3e5aed7308da@nysa.notmuch \
--to=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
--cc=ilya.bobyr@gmail.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).