3 # Rebase 'master' on top of an upstream branch (defaults to 'junio/next'),
4 # retaining "fast-forwardability" by "merging" (with the "ours" strategy) the
5 # previous state on top of the current upstream state.
9 # do not perform the rebase but only display the revisions selected
12 # as for dry-run but display the commits as a graph
15 # as for --dry-run but display the commits using cherry notation to mark
16 # commits that are suitable for upstream consideration.
28 -s|
--show|
-d|
--dry-run)
41 Usage: $0 [options] [<upstream>]
44 -s|--show show which commits would be cherry-picked
45 -g|--graph like --show, but with the commit graph
46 -c|--cherry try to leave out commits that were applied upstream
51 echo "Unknown option: $1" >&2
63 if test -z "$force" && test -z "$(git rev-list .."$TO")"
65 echo "Nothing new in $TO; To force a rebase, use the --force, Luke!" >&2
69 HEAD_NAME
="$(git rev-parse --symbolic-full-name HEAD)"
72 UPSTREAM
=$
(git rev-parse
--symbolic-full-name HEAD@
{u
}) ||
{
73 echo "Not tracking any remote branch!" >&2
76 test "$(git rev-parse HEAD)" = "$(git rev-parse $UPSTREAM)" ||
77 test "$(git rev-parse $HEAD_NAME@{1})" = "$(git rev-parse $UPSTREAM)" ||
{
78 echo "Your '$HEAD_NAME' is not up-to-date!" >&2
84 echo "Not on any branch!" >&2
88 FROM_SHA1
=$
(git rev-parse
--short HEAD
)
89 TO_SHA1
=$
(git rev-parse
--short $TO)
92 test "$(git rev-parse $1:)" = "$(git rev-parse "$1^
:")"
96 git rev-list
--parents "$@" |
sed -n 's/ .* .*//p'
99 # Find old merging rebase, if any
102 for commit
in $
(list_merges
$TO..
)
104 if is_ours_merge
$commit
106 subject
="$(git show -s --format=%s $commit)"
110 printf "%s\n\n%s\n%s\n\n(y/n) " \
111 "Is this the latest merging rebase?" \
119 REBASING_BASE
=$commit
125 if test -n "$REBASING_BASE"
127 BASE_MESSAGE
="using $REBASING_BASE as base."
128 MESSAGE
="$(git cat-file commit $REBASING_BASE |
130 # old style rebasing merge?
132 "Rebasing merge to "*)
133 BASE_MESSAGE
="using the rebasing merge $REBASING_BASE."
134 # Fake a commit such that 'git log <commit>..' shows all the
135 # commits we want to rebase
136 PREVIOUS_REBASING
="$(git rev-parse $REBASING_BASE^2)"
137 PREVIOUS_ONTO
="$(echo "$MESSAGE" |
138 sed -n '1s/Rebasing merge .*(\(.*\))/\1/p')"
139 # To avoid checking out unneeded files/file versions, the
140 # throw-away base points to the tree we want to rebase onto
141 REBASING_BASE
="$(echo Dummy |
142 git commit-tree $TO_SHA1: \
143 -p $PREVIOUS_ONTO -p $PREVIOUS_REBASING)"
148 RANGE
=$REBASING_BASE..
151 git log
--oneline $graph $cherry --boundary $RANGE
155 exec "$(dirname "$0")"/shears.sh
$force --merging --onto=$TO ${REBASING_BASE:-$TO}