3 # stolen from http://stackoverflow.com/questions/4156957/merging-branches-without-checkout/4157435#4157435
6 echo "Usage: git merge-ff <branch> <committish-to-merge>" 1>&2
14 branch_orig_hash="$(git show-ref -s --verify refs/heads/$branch 2> /dev/null)"
16 echo "Error: unknown branch $branch" 1>&2
20 commit_orig_hash="$(git rev-parse --verify $commit 2> /dev/null)"
22 echo "Error: unknown revision $commit" 1>&2
26 if [ "$(git symbolic-ref HEAD)" = "refs/heads/$branch" ]; then
27 git merge $quiet --ff-only "$commit" --
29 if [ "$(git merge-base $branch_orig_hash $commit_orig_hash)" != "$branch_orig_hash" ]; then
30 echo "Error: merging $commit into $branch would not be a fast-forward" 1>&2
33 echo "Updating ${branch_orig_hash:0:7}..${commit_orig_hash:0:7}"
34 if git update-ref -m "merge $commit: Fast forward" "refs/heads/$branch" "$commit_orig_hash" "$branch_orig_hash"; then
35 if [ -z $quiet ]; then
37 git diff --stat "$branch@{1}" "$branch" --
40 echo "Error: fast forward using update-ref failed" 1>&2
45 while getopts "q" opt; do
54 2 ) _merge_ff "$1" "$2";;