annotate glang-galaxy-conf/.git/hooks/pre-rebase.sample @ 2:8947fca5f715 draft default tip

Uploaded
author ktnyt
date Fri, 26 Jun 2015 05:21:44 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
1 #!/bin/sh
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
2 #
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
3 # Copyright (c) 2006, 2008 Junio C Hamano
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
4 #
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
5 # The "pre-rebase" hook is run just before "git rebase" starts doing
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
6 # its job, and can prevent the command from running by exiting with
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
7 # non-zero status.
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
8 #
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
9 # The hook is called with the following parameters:
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
10 #
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
11 # $1 -- the upstream the series was forked from.
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
12 # $2 -- the branch being rebased (or empty when rebasing the current branch).
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
13 #
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
14 # This sample shows how to prevent topic branches that are already
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
15 # merged to 'next' branch from getting rebased, because allowing it
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
16 # would result in rebasing already published history.
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
17
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
18 publish=next
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
19 basebranch="$1"
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
20 if test "$#" = 2
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
21 then
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
22 topic="refs/heads/$2"
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
23 else
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
24 topic=`git symbolic-ref HEAD` ||
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
25 exit 0 ;# we do not interrupt rebasing detached HEAD
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
26 fi
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
27
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
28 case "$topic" in
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
29 refs/heads/??/*)
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
30 ;;
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
31 *)
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
32 exit 0 ;# we do not interrupt others.
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
33 ;;
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
34 esac
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
35
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
36 # Now we are dealing with a topic branch being rebased
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
37 # on top of master. Is it OK to rebase it?
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
38
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
39 # Does the topic really exist?
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
40 git show-ref -q "$topic" || {
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
41 echo >&2 "No such branch $topic"
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
42 exit 1
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
43 }
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
44
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
45 # Is topic fully merged to master?
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
46 not_in_master=`git rev-list --pretty=oneline ^master "$topic"`
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
47 if test -z "$not_in_master"
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
48 then
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
49 echo >&2 "$topic is fully merged to master; better remove it."
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
50 exit 1 ;# we could allow it, but there is no point.
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
51 fi
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
52
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
53 # Is topic ever merged to next? If so you should not be rebasing it.
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
54 only_next_1=`git rev-list ^master "^$topic" ${publish} | sort`
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
55 only_next_2=`git rev-list ^master ${publish} | sort`
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
56 if test "$only_next_1" = "$only_next_2"
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
57 then
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
58 not_in_topic=`git rev-list "^$topic" master`
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
59 if test -z "$not_in_topic"
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
60 then
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
61 echo >&2 "$topic is already up-to-date with master"
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
62 exit 1 ;# we could allow it, but there is no point.
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
63 else
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
64 exit 0
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
65 fi
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
66 else
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
67 not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"`
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
68 /usr/bin/perl -e '
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
69 my $topic = $ARGV[0];
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
70 my $msg = "* $topic has commits already merged to public branch:\n";
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
71 my (%not_in_next) = map {
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
72 /^([0-9a-f]+) /;
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
73 ($1 => 1);
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
74 } split(/\n/, $ARGV[1]);
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
75 for my $elem (map {
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
76 /^([0-9a-f]+) (.*)$/;
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
77 [$1 => $2];
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
78 } split(/\n/, $ARGV[2])) {
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
79 if (!exists $not_in_next{$elem->[0]}) {
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
80 if ($msg) {
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
81 print STDERR $msg;
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
82 undef $msg;
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
83 }
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
84 print STDERR " $elem->[1]\n";
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
85 }
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
86 }
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
87 ' "$topic" "$not_in_next" "$not_in_master"
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
88 exit 1
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
89 fi
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
90
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
91 exit 0
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
92
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
93 ################################################################
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
94
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
95 This sample hook safeguards topic branches that have been
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
96 published from being rewound.
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
97
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
98 The workflow assumed here is:
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
99
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
100 * Once a topic branch forks from "master", "master" is never
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
101 merged into it again (either directly or indirectly).
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
102
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
103 * Once a topic branch is fully cooked and merged into "master",
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
104 it is deleted. If you need to build on top of it to correct
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
105 earlier mistakes, a new topic branch is created by forking at
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
106 the tip of the "master". This is not strictly necessary, but
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
107 it makes it easier to keep your history simple.
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
108
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
109 * Whenever you need to test or publish your changes to topic
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
110 branches, merge them into "next" branch.
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
111
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
112 The script, being an example, hardcodes the publish branch name
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
113 to be "next", but it is trivial to make it configurable via
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
114 $GIT_DIR/config mechanism.
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
115
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
116 With this workflow, you would want to know:
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
117
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
118 (1) ... if a topic branch has ever been merged to "next". Young
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
119 topic branches can have stupid mistakes you would rather
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
120 clean up before publishing, and things that have not been
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
121 merged into other branches can be easily rebased without
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
122 affecting other people. But once it is published, you would
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
123 not want to rewind it.
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
124
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
125 (2) ... if a topic branch has been fully merged to "master".
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
126 Then you can delete it. More importantly, you should not
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
127 build on top of it -- other people may already want to
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
128 change things related to the topic as patches against your
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
129 "master", so if you need further changes, it is better to
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
130 fork the topic (perhaps with the same name) afresh from the
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
131 tip of "master".
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
132
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
133 Let's look at this example:
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
134
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
135 o---o---o---o---o---o---o---o---o---o "next"
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
136 / / / /
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
137 / a---a---b A / /
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
138 / / / /
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
139 / / c---c---c---c B /
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
140 / / / \ /
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
141 / / / b---b C \ /
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
142 / / / / \ /
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
143 ---o---o---o---o---o---o---o---o---o---o---o "master"
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
144
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
145
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
146 A, B and C are topic branches.
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
147
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
148 * A has one fix since it was merged up to "next".
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
149
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
150 * B has finished. It has been fully merged up to "master" and "next",
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
151 and is ready to be deleted.
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
152
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
153 * C has not merged to "next" at all.
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
154
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
155 We would want to allow C to be rebased, refuse A, and encourage
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
156 B to be deleted.
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
157
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
158 To compute (1):
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
159
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
160 git rev-list ^master ^topic next
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
161 git rev-list ^master next
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
162
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
163 if these match, topic has not merged in next at all.
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
164
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
165 To compute (2):
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
166
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
167 git rev-list master..topic
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
168
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
169 if this is empty, it is fully merged to "master".