-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathgit-now-rebase
More file actions
59 lines (49 loc) · 1.38 KB
/
git-now-rebase
File metadata and controls
59 lines (49 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
usage() {
echo "usage: git now rebase [--mine|-m] [<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}`
if flag mine; then
FIRST_NOW_COMMIT=$(git_now_my_first_commit $COMMON_ANCESTOR_COMMIT)
else
FIRST_NOW_COMMIT=$(git_now_first_commit $COMMON_ANCESTOR_COMMIT)
fi
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
if flag mine; then
FIRST_NOW_COMMIT=$(git_now_my_first_commit)
else
FIRST_NOW_COMMIT=$(git_now_first_commit)
fi
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
}
cmd_help() {
usage
exit 0
}
parse_args() {
# parse options
DEFINE_boolean 'mine' false 'limit git-now commits by my name' 'm'
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
# read arguments into global variables
BASE_BRANCH=$1
}
# vim: set ff=unix ft=sh :