[git] Add git-merge-ff-only

This commit is contained in:
Matteo Cypriani 2012-02-08 19:00:47 +01:00
parent bca8250c5a
commit 6c5525185c
2 changed files with 56 additions and 0 deletions

View File

@ -28,3 +28,21 @@ in a directory in the PATH (for instance /usr/local/bin) and add an
alias:
git config --global alias.cherry-move "\!sh -c 'git-cherry-move'"
# git-merge-ff-only #
git-merge-ff-only main_branch topic_branch is the equivalent of the
following commands:
git checkout main_branch && git merge --ff-only topic_branch
except that main_branch is not checked out. The reference is updated
directly (if possible), and HEAD stays on whatever branch was checked
out before running the command.
To activate the git merge-ff-only command, put the git-merge-ff-only
script in a directory in the PATH (for instance /usr/local/bin) and
add an alias:
git config --global alias.merge-ff-only "\!sh -c 'git-merge-ff-only'"

38
git/git-merge-ff-only Executable file
View File

@ -0,0 +1,38 @@
#!/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