t8200: test export subject stripping behaviors
[topgit/pro.git] / tg-rebase.sh
blob7df5b4d5e0b15ba307d8d04cd925fc397653be32
1 #!/bin/sh
2 # TopGit rebase command
3 # (C) 2015 Kyle J. McKay <mackyle@gmail.com>
4 # GPLv2
6 USAGE="Usage: ${tgname:-tg} [...] rebase (-m | --merge) [<git-rebase-arg>...]"
8 case "$1" in -h|--help)
9 printf '%s\n' "$USAGE"
10 exit 0
11 esac
12 ensure_work_tree
14 optmerge=
15 optcontinue=
16 for arg; do
17 case "$arg" in
18 -m|--merge)
19 optmerge=1
21 --skip|--continue|--abort|--edit-todo)
22 optcontinue=1
24 esac
25 done
26 if [ -n "$optcontinue" ]; then
27 if [ -n "$git_dir" ] && [ -d "$git_dir" ] && ! [ -d "$git_dir/rebase-merge" ]; then
28 exec git rebase "$@"
29 exit 1
32 if [ -z "$optmerge" -a -z "$optcontinue" ]; then
33 cat <<EOT >&2
34 ${tgname:-tg} rebase is intended as a drop-in replacement for git rebase -m.
35 Either add the -m (or --merge) option to the command line or use git rebase
36 directly. When using rebase to flatten history the merge mode is superior.
37 EOT
38 exit 1
41 if [ -z "$optcontinue" ]; then
42 rerereon="$(git config --get --bool rerere.enabled 2>/dev/null)" || :
43 [ "$rerereon" = "true" ] ||
44 warn "rerere.enabled is false, automatic --continue not possible"
47 [ "$*" = "--abort" ] || ensure_ident_available
48 continuemsg='"git rebase --continue"'
49 lasthead=
50 newhead="$(git rev-parse --verify --quiet HEAD --)" || :
52 while
53 lasthead="$newhead"
54 hascontinuemsg=
55 err=0
56 msg="$(git -c rerere.autoupdate=true rebase "$@" 3>&2 2>&1 1>&3 3>&-)" || err=$?
57 case "$msg" in *"$continuemsg"*) hascontinuemsg=1; esac
58 newhead="$(git rev-parse --verify --quiet HEAD --)" || :
59 [ "$newhead" != "$lasthead" ] || hascontinuemsg=
60 msg="$(printf '%s\n' "$msg" | sed -e 's~git rebase ~'"$tgdisplay"' rebase ~g')"
61 [ $err -ne 0 ]
63 if [ -n "$hascontinuemsg" ] && [ $(git ls-files --unmerged | wc -l) -eq 0 ]; then
64 while IFS= read -r line; do case "$line" in
65 "Staged "*|"Resolved "*|"Recorded "*)
66 printf '%s\n' "$line";;
68 break;;
69 esac; done <<-EOT
70 $msg
71 EOT
72 set -- --continue
73 continue
75 break
76 done
78 [ -z "$msg" ] || printf '%s\n' "$msg" >&2
79 exit $err