Re: [RTC/PATCH] Add 'update-branch' hook
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Apr 21, 2014, 07:25 UTC
- Message-ID
- <CAPig+cRbP_+fBBtmyLAbbj6685+OhrG_7sOD7hD_HJSZJoAWKg@mail.gmail.com>
- In-Reply-To
- <1398047016-21643-1-git-send-email-felipe.contreras@gmail.com>
On Sun, Apr 20, 2014 at 10:23 PM, Felipe Contreras <felipe.contreras@gmail.com> wrote:
Show 45 quoted lines
> This hook is invoked whenever a branch is updated, either when a branch
> is created or updated with 'git branch', or when it's rebased with 'git
> rebase'. It receives two parameters; the name of the branch, and the
> SHA-1 of the latest commit, additionally, if there was a base commit the
> branch was rebased onto, a third parameter contains it.
>
> It can be used to verify the validity of branch names, and also to keep
> track of the origin point of a branch, which is otherwise not possible
> to find out [1].
>
> [1] http://thread.gmane.org/gmane.comp.version-control.git/198587
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
> diff --git a/t/t5408-update-branch-hook.sh b/t/t5408-update-branch-hook.sh
> new file mode 100755
> index 0000000..d921c0e
> --- /dev/null
> +++ b/t/t5408-update-branch-hook.sh
> @@ -0,0 +1,39 @@
> +#!/bin/sh
> +
> +test_description='Test the update-branch hook'
> +
> +. ./test-lib.sh
> +
> +setup () {
> + mkdir -p .git/hooks &&
> + cat > .git/hooks/update-branch <<-'EOF' &&
> + #!/bin/sh
> + echo $@ > .git/update-branch.args
> + EOF
> + chmod +x .git/hooks/update-branch &&
> + echo one > content &&
> + git add content &&
> + git commit -a -m one
> +}
> +
> +setup
> +
> +test_expect_success 'creating a branch' '
> + git checkout -b test master &&
> + echo two > new &&
> + git add new &&
> + git commit -a -m twoBroken &&-chain.
Show 16 quoted lines
> + echo "test $(git rev-parse master)" > expected && > + test_cmp expected .git/update-branch.args > +' > + > +test_expect_success 'doing a rebase' ' > + git checkout -b next master && > + echo three > content && > + git commit -a -m three && > + git rebase --onto next master test && > + echo "test $(git rev-parse HEAD) $(git rev-parse next)" > expected && > + test_cmp expected .git/update-branch.args > +' > + > +test_done > -- > 1.9.2+fc1.1.g5c924db