Skip to content

Commit ba2d0f4

Browse files
committed
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 <[email protected]>
1 parent 27d69a4 commit ba2d0f4

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

templates/hooks--pre-rebase

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
#!/bin/sh
22
#
3-
# Copyright (c) 2006 Junio C Hamano
3+
# Copyright (c) 2006, 2008 Junio C Hamano
44
#
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.
517

618
publish=next
719
basebranch="$1"
820
if test "$#" = 2
921
then
1022
topic="refs/heads/$2"
1123
else
12-
topic=`git symbolic-ref HEAD`
24+
topic=`git symbolic-ref HEAD` ||
25+
exit 0 ;# we do not interrupt rebasing detached HEAD
1326
fi
1427

15-
case "$basebranch,$topic" in
16-
master,refs/heads/??/*)
28+
case "$topic" in
29+
refs/heads/??/*)
1730
;;
1831
*)
1932
exit 0 ;# we do not interrupt others.
@@ -23,6 +36,12 @@ esac
2336
# Now we are dealing with a topic branch being rebased
2437
# on top of master. Is it OK to rebase it?
2538

39+
# Does the topic really exist?
40+
git show-ref -q "$topic" || {
41+
echo >&2 "No such branch $topic"
42+
exit 1
43+
}
44+
2645
# Is topic fully merged to master?
2746
not_in_master=`git-rev-list --pretty=oneline ^master "$topic"`
2847
if test -z "$not_in_master"

0 commit comments

Comments
 (0)