2012-02-08 19:00:47 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# git-merge-ff-only, Copyright © 2012 Matteo Cypriani
|
|
|
|
#
|
|
|
|
# This program is free software. It comes without any warranty, to
|
|
|
|
# the extent permitted by applicable law. You can redistribute it
|
|
|
|
# and/or modify it under the terms of the Do What The Fuck You Want
|
|
|
|
# To Public License, Version 2, as published by Sam Hocevar. See
|
|
|
|
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
|
|
|
#
|
|
|
|
# This script fast-forwards a branch (main_branch) to another branch
|
|
|
|
# (topic_branch), if possible. It is equivalent to git checkout
|
|
|
|
# main_branch && git merge --ff-only topic_branch, but the effort of
|
|
|
|
# checking out the main branch is saved (git branch -f is used to update
|
|
|
|
# the reference directly).
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2018-04-11 23:28:36 +02:00
|
|
|
USAGE=$(cat <<EOF
|
|
|
|
Usage:
|
|
|
|
$0 <main_branch> <topic_branch>"
|
|
|
|
|
|
|
|
<main_branch> will be fast-forwarded to <topic_branch> if possible."
|
|
|
|
EOF
|
|
|
|
)
|
|
|
|
|
2012-02-08 19:00:47 +01:00
|
|
|
if [ $# -ne 2 ] ; then
|
2018-04-11 23:28:36 +02:00
|
|
|
printf '%s\n' "$USAGE" >&2
|
2012-02-08 19:00:47 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
MAIN_BRANCH="$1"
|
|
|
|
TOPIC_BRANCH="$2"
|
|
|
|
|
|
|
|
echo "Trying to merge $TOPIC_BRANCH into $MAIN_BRANCH..."
|
|
|
|
|
|
|
|
DIFF="$(git rev-list "$TOPIC_BRANCH".."$MAIN_BRANCH")"
|
|
|
|
if [ -z "$DIFF" ] ; then
|
2018-04-11 23:28:36 +02:00
|
|
|
echo -- "$TOPIC_BRANCH contains all the commits of $MAIN_BRANCH."
|
2012-02-08 19:00:47 +01:00
|
|
|
echo "Fast-forwarding $MAIN_BRANCH to $TOPIC_BRANCH."
|
|
|
|
git branch -f "$MAIN_BRANCH" "$TOPIC_BRANCH"
|
|
|
|
else
|
2018-04-11 23:28:36 +02:00
|
|
|
echo -- "$TOPIC_BRANCH does not contain all the commits of $MAIN_BRANCH."
|
2012-02-08 19:00:47 +01:00
|
|
|
echo "Fast-forward impossible, aborting."
|
|
|
|
fi
|