Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions git-rebase-first-parent
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ die() {
OPTS_SPEC="\
git rebase-first-parent [-i | --interactive] [--onto <newbase>] [<upstream> [<branch>]]
--
h,help show the help
h,help! show the help

i,interactive let the user edit the list of commits to rebase
onto=newbase rebase onto given branch instead of upstream"
i,interactive! let the user edit the list of commits to rebase
x,exec!=cmd run command after each commit (e.g. to check compilation)
onto!=newbase rebase onto given branch instead of upstream"

usage() {
if [ $# -gt 0 ]; then
Expand All @@ -60,6 +61,7 @@ eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt --stuck-long -- "$@" || ech

unset INTERACTIVE
unset ONTO
GIT_REBASE_FIRST_PARENT_EXEC_CMDS=
while [ $# -gt 0 ]; do
case "$1" in
--interactive)
Expand All @@ -68,6 +70,9 @@ while [ $# -gt 0 ]; do
--onto=*)
ONTO="${1#--onto=}"
;;
--exec=*)
GIT_REBASE_FIRST_PARENT_EXEC_CMDS="${GIT_REBASE_FIRST_PARENT_EXEC_CMDS}exec ${1#--exec=}\n"
;;
--)
shift
break
Expand Down Expand Up @@ -115,5 +120,8 @@ if [ -n "${INTERACTIVE+set}" ]; then
fi
export GIT_REBASE_FIRST_PARENT_SEQUENCE_EDITOR
fi
# The variable GIT_REBASE_FIRST_PARENT_EXEC_CMDS is interpreted by
# make-rebase-first-parent to add extra "exec" lines to each rebase step.
export GIT_REBASE_FIRST_PARENT_EXEC_CMDS

env GIT_SEQUENCE_EDITOR=git-rebase-first-parent-sequence-editor GIT_REBASE_FIRST_PARENT_UPSTREAM="$UPSTREAM" GIT_REBASE_FIRST_PARENT_BRANCH="$BRANCH" git rebase "$@"
5 changes: 4 additions & 1 deletion make-rebase-first-parent
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ git log --first-parent --reverse --format='tformat:%H %P#%s' "$1".."$2" | while
l="${l%%#*}"
c="${l%% *}"
p="${l#* }"
p="`echo "$p" | sed 's/^[[:space:]]*[^[:space:]]\{1,\}//;s/[[:space:]]*\([^[:space:]]\{1,\}\)/ -p \1/g'`"
p="$(echo "$p" | sed 's/^[[:space:]]*[^[:space:]]\{1,\}//;s/[[:space:]]*\([^[:space:]]\{1,\}\)/ -p \1/g')"
if [ -z "$p" ]; then
printf 'pick %s %s\n' "$c" "$s"
else
printf '# %s\n' "$s"
echo "exec git update-ref HEAD \`git commit-tree -p HEAD$p -m 'dummy merge for $c' 'HEAD^{tree}'\` && git cherry-pick -n -m 1 $c && git commit --amend -q -n -C $c"
fi
if [ -n "${GIT_REBASE_FIRST_PARENT_EXEC_CMDS}" ]; then
printf "%b" "${GIT_REBASE_FIRST_PARENT_EXEC_CMDS}"
fi
done

sed '/^noop$/d'