mirror of
https://github.com/iwata/git-now.git
synced 2026-09-10 07:26:29 -04:00
68 lines
1.5 KiB
Plaintext
68 lines
1.5 KiB
Plaintext
usage() {
|
|
echo "usage: git now rebase [<base_branch>]"
|
|
echo " git now rebase --push|-p [--remote|-r <remote>] [<base_branch>]"
|
|
}
|
|
|
|
|
|
cmd_default() {
|
|
parse_args "$@"
|
|
|
|
WORKING_BRANCH=$(git_current_branch)
|
|
INITIAL_COMMIT=$(git_now_initial_commit)
|
|
|
|
if [ -n "$BASE_BRANCH" ]; then
|
|
COMMON_ANCESTOR_COMMIT=`git merge-base ${BASE_BRANCH} ${WORKING_BRANCH}`
|
|
FIRST_NOW_COMMIT=$(git_now_first_commit $COMMON_ANCESTOR_COMMIT)
|
|
|
|
if [ "$FIRST_NOW_COMMIT" != "$INITIAL_COMMIT" ]; then
|
|
git rebase -i ${FIRST_NOW_COMMIT}^
|
|
else
|
|
git checkout ${FIRST_NOW_COMMIT}
|
|
git commit --amend
|
|
git rebase --onto HEAD ${FIRST_NOW_COMMIT} ${WORKING_BRANCH}
|
|
fi
|
|
else
|
|
FIRST_NOW_COMMIT=$(git_now_first_commit)
|
|
|
|
if [ "$FIRST_NOW_COMMIT" != "$INITIAL_COMMIT" ]; then
|
|
git rebase -i ${FIRST_NOW_COMMIT}^
|
|
else
|
|
git checkout ${FIRST_NOW_COMMIT}
|
|
git commit --amend
|
|
git rebase --onto HEAD ${FIRST_NOW_COMMIT} ${WORKING_BRANCH}
|
|
fi
|
|
fi
|
|
|
|
if flag push; then
|
|
_cmd_push $WORKING_BRANCH $REMOTE
|
|
fi
|
|
}
|
|
|
|
cmd_help() {
|
|
usage
|
|
exit 0
|
|
}
|
|
|
|
parse_args() {
|
|
# parse options
|
|
DEFINE_boolean 'push' false 'push to remote repository finally' 'p'
|
|
DEFINE_string 'remote' '' 'remote branch name to --set-upstream' 'r'
|
|
FLAGS "$@" || exit $?
|
|
eval set -- "${FLAGS_ARGV}"
|
|
|
|
# read arguments into global variables
|
|
BASE_BRANCH=$1
|
|
REMOTE=$FLAGS_remote
|
|
}
|
|
|
|
_cmd_push() {
|
|
local branch=$1
|
|
local remote=$2
|
|
if [ -n "$remote" ]; then
|
|
git push --set-upstream ${remote} ${branch}
|
|
else
|
|
git push
|
|
fi
|
|
}
|
|
|