39 lines
1.3 KiB
Bash
Executable File
39 lines
1.3 KiB
Bash
Executable File
#!/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
|
|
|
|
if [ $# -ne 2 ] ; then
|
|
echo "Usage: $0 <main_branch> <topic_branch>"
|
|
echo "<main_branch> will be fast-forwarded to <topic_branch> if possible."
|
|
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
|
|
echo "$TOPIC_BRANCH contains all the commits of $MAIN_BRANCH."
|
|
echo "Fast-forwarding $MAIN_BRANCH to $TOPIC_BRANCH."
|
|
git branch -f "$MAIN_BRANCH" "$TOPIC_BRANCH"
|
|
else
|
|
echo "$TOPIC_BRANCH does not contain all the commits of $MAIN_BRANCH."
|
|
echo "Fast-forward impossible, aborting."
|
|
fi
|