tg.sh: fix recurse_deps pre-order traversal with remotes enabled
[topgit/pro.git] / tg-rebase.sh
blobdedccb14f317cb08535d66bf2a05046432b24a15
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
13 optmerge=
14 optcontinue=
15 for arg; do
16 case "$arg" in
17 -m|--merge)
18 optmerge=1
20 --skip|--continue|--abort|--edit-todo)
21 optcontinue=1
23 esac
24 done
25 if [ -n "$optcontinue" ]; then
26 if [ -n "$git_dir" ] && [ -d "$git_dir" ] && ! [ -d "$git_dir/rebase-merge" ]; then
27 exec git rebase "$@"
28 exit 1
31 if [ -z "$optmerge" -a -z "$optcontinue" ]; then
32 cat <<EOT >&2
33 ${tgname:-tg} rebase is intended as a drop-in replacement for git rebase -m.
34 Either add the -m (or --merge) option to the command line or use git rebase
35 directly. When using rebase to flatten history the merge mode is superior.
36 EOT
37 exit 1
40 if [ -z "$optcontinue" ]; then
41 rerereon="$(git config --get --bool rerere.enabled 2>/dev/null || :)"
42 [ "$rerereon" = "true" ] || \
43 warn "rerere.enabled is false, automatic --continue not possible"
46 continuemsg='"git rebase --continue"'
48 while
49 hascontinuemsg=
50 err=0
51 msg="$(git -c rerere.autoupdate=true rebase "$@" 3>&2 2>&1 1>&3 3>&-)" || err=$?
52 case "$msg" in *"$continuemsg"*) hascontinuemsg=1; esac
53 msg="$(printf '%s\n' "$msg" | sed -e 's~"git rebase ~"'"$tgdisplay"' rebase ~g')"
54 [ $err -ne 0 ]
56 if [ -n "$hascontinuemsg" ] && [ $(git ls-files --unmerged | wc -l) -eq 0 ]; then
57 while IFS= read -r line; do case "$line" in
58 "Staged "*|"Resolved "*|"Recorded "*)
59 printf '%s\n' "$line";;
61 break;;
62 esac; done <<-EOT
63 $msg
64 EOT
65 set -- --continue
66 continue
68 break
69 done
71 [ -z "$msg" ] || printf '%s\n' "$msg" >&2
72 exit $err