#! /bin/bash # Copyright (C) 2022 Oswald Buddenhagen # # You may use this file under the terms of the 3-clause BSD license. gitdir=$(git rev-parse --git-dir) || exit if ! git diff --quiet HEAD; then echo "Working directory or index not clean." >&2 exit 1 fi rbdir=$gitdir/rebase-merge if ! test -d "$rbdir"; then echo "No rebase ongoing?" >&2 exit 1 fi onto=$(<"$rbdir/onto") || exit todo=$rbdir/git-rebase-todo git log --reverse --pretty="tformat:pick %h %s" $onto.. > "$todo.new" || exit (echo "break"; echo; cat "$todo") >> "$todo.new" || exit mv "$todo" "$todo.old" || exit mv "$todo.new" "$todo" || exit if ! git rebase --edit-todo; then mv "$todo.old" "$todo" exit 1 fi if ! test -s "$todo"; then echo "Empty todo; canceling rewind." >&2 mv "$todo.old" "$todo" exit 1 fi rm "$todo.old" : > "$rbdir/done" git reset --hard $onto || exit git rebase --continue || exit