Created
November 8, 2017 13:51
-
-
Save Ashaba/42a0a762e8458226da8fc28a1c6fd1f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mv pre-rebase.sample pre-rebase #renaming sample to pre-rebase. | |
#!/bin/sh | |
publish=next | |
basebranch="$1" | |
if test "$#" = 2 | |
then | |
topic="refs/heads/$2" | |
else | |
topic=`git symbolic-ref HEAD` || | |
exit 0 ;# we do not interrupt rebasing detached HEAD | |
fi | |
case "$topic" in | |
refs/heads/??/*) | |
;; | |
*) | |
exit 0 ;# we do not interrupt others. | |
;; | |
esac | |
# Now we are dealing with a topic branch being rebased | |
# on top of master. Is it OK to rebase it? | |
# Does the topic really exist? | |
git show-ref -q "$topic" || { | |
echo >&2 "No such branch $topic" | |
exit 1 | |
} | |
# Is topic fully merged to master? | |
not_in_master=`git rev-list --pretty=oneline ^master "$topic"` | |
if test -z "$not_in_master" | |
then | |
echo >&2 "$topic is fully merged to master; better remove it." | |
exit 1 ;# we could allow it, but there is no point. | |
fi | |
# Is topic ever merged to next? If so you should not be rebasing it. | |
only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` | |
only_next_2=`git rev-list ^master ${publish} | sort` | |
if test "$only_next_1" = "$only_next_2" | |
then | |
not_in_topic=`git rev-list "^$topic" master` | |
if test -z "$not_in_topic" | |
then | |
echo >&2 "$topic is already up-to-date with master" | |
exit 1 ;# we could allow it, but there is no point. | |
else | |
exit 0 | |
fi | |
else | |
not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` | |
/usr/bin/perl -e ' | |
my $topic = $ARGV[0]; | |
my $msg = "* $topic has commits already merged to public branch:\n"; | |
my (%not_in_next) = map { | |
/^([0-9a-f]+) /; | |
($1 => 1); | |
} split(/\n/, $ARGV[1]); | |
for my $elem (map { | |
/^([0-9a-f]+) (.*)$/; | |
[$1 => $2]; | |
} split(/\n/, $ARGV[2])) { | |
if (!exists $not_in_next{$elem->[0]}) { | |
if ($msg) { | |
print STDERR $msg; | |
undef $msg; | |
} | |
print STDERR " $elem->[1]\n"; | |
} | |
} | |
' "$topic" "$not_in_next" "$not_in_master" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment