Various scripts in various languages.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.3 KiB

# 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
# 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
USAGE=$(cat <<EOF
$0 <main_branch> <topic_branch>"
<main_branch> will be fast-forwarded to <topic_branch> if possible."
if [ $# -ne 2 ] ; then
printf '%s\n' "$USAGE" >&2
exit 1
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"
echo -- "$TOPIC_BRANCH does not contain all the commits of $MAIN_BRANCH."
echo "Fast-forward impossible, aborting."