annotate vendor/drupal/coder/.git/hooks/pre-rebase.sample @ 5:12f9dff5fda9 tip

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