pre-rebase hook update
This hook is what I have been using to manage topic branches in git.git, but have not been updated to the Real Thing for a while. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jun 24, 2008 at 19:05 UTC
ba2d0f4f35beffbf715ca652d5b36df8c0ad5ceb
1 file changed
+23
-4
templates/hooks--pre-rebase
+23
-4
@@ -1,7 +1,19 @@
1
#!/bin/sh
2
#
3
-# Copyright (c) 2006 Junio C Hamano
3
+# Copyright (c) 2006, 2008 Junio C Hamano
4
#
5
+# The "pre-rebase" hook is run just before "git-rebase" starts doing
6
+# its job, and can prevent the command from running by exiting with
7
+# non-zero status.
8
+#
9
+# The hook is called with the following parameters:
10
+#
11
+# $1 -- the upstream the series was forked from.
12
+# $2 -- the branch being rebased (or empty when rebasing the current branch).
13
+#
14
+# This sample shows how to prevent topic branches that are already
15
+# merged to 'next' branch from getting rebased, because allowing it
16
+# would result in rebasing already published history.
17
18
publish=next
19
basebranch="$1"
@@ -9,11 +21,12 @@ if test "$#" = 2
21
then
22
topic="refs/heads/$2"
23
else
12
- topic=`git symbolic-ref HEAD`
24
+ topic=`git symbolic-ref HEAD` ||
25
+ exit 0 ;# we do not interrupt rebasing detached HEAD
26
fi
27
15
-case "$basebranch,$topic" in
16
-master,refs/heads/??/*)
28
+case "$topic" in
29
+refs/heads/??/*)
30
;;
31
*)
32
exit 0 ;# we do not interrupt others.
@@ -23,6 +36,12 @@ esac
36
# Now we are dealing with a topic branch being rebased
37
# on top of master. Is it OK to rebase it?
38
39
+# Does the topic really exist?
40
+git show-ref -q "$topic" || {
41
+ echo >&2 "No such branch $topic"
42
+ exit 1
43
+}
44
+
45
# Is topic fully merged to master?
46
not_in_master=`git-rev-list --pretty=oneline ^master "$topic"`
47
if test -z "$not_in_master"