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