#!/bin/sh
#############################################################################
# Copyright (c) 2009 Novell, Inc.
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com
#############################################################################
#
# Script to merge the scripts branch into another branch, e.g.
# ... hack on scripts branch ...
# git commit
# ./scripts/merge-scripts-branch SLE11_BRANCH SL110_BRANCH SL103_BRANCH ...
SUBDIRECTORY_OK=true
. "$(git --exec-path)/git-sh-setup"
require_work_tree
if test -z "$merge_scripts_branch_copy"; then
# copy ourself out of the git working dir
copy=$(mktemp)
cp "$0" "$copy"
chmod +x "$copy"
merge_scripts_branch_copy=true exec /bin/sh -$- "$copy" "$@"
fi
usage()
{
die "Usage: $0 [--overwrite] [-p|--pull] branch..."
}
opt_overwrite=false
opt_pull=false
while test $# -gt 0; do
case "$1" in
--overwrite)
opt_overwrite=true
shift
;;
-p | --pull)
opt_pull=true
shift
;;
--)
shift
break
;;
-*)
usage
;;
*)
break
;;
esac
done
if test $# = 0; then
# "" means current branch
set -- ""
fi
# remove the copy
trap 'rm -f "$0"' EXIT
cd_to_toplevel
if $opt_overwrite; then
# temporarily set up an overwriting merge driver
git config merge.overwrite.name "overwrite our files by theirs"
git config merge.overwrite.driver "cp %B %A"
mkdir -p "$GIT_DIR"/info
echo '* merge=overwrite' >>"$GIT_DIR"/info/attributes
trap "sed -i '/merge=overwrite/d' \"$GIT_DIR\"/info/attributes;
rm -f $0" EXIT
fi
oldbranch=
if test -n "$*"; then
oldbranch=$(sed -n 's|^ref: refs/heads/||p' "$GIT_DIR"/HEAD 2>/dev/null)
if test -z "$oldbranch"; then
oldbranch=$(git rev-parse HEAD)
fi
fi
for branch; do
if test "$branch" = "scripts"; then
echo "warning: skipping branch 'scripts'" >&2
continue
fi
if test -n "$branch"; then
git checkout "$branch" || exit
fi
if $opt_pull; then
git pull || exit
fi
git merge "scripts" || exit
done
if test -n "$oldbranch"; then
git checkout "$oldbranch"
fi