@@ -33,6 +33,20 @@ warn () {
3333 echo " $* " >&2
3434}
3535
36+ output () {
37+ case " $VERBOSE " in
38+ ' ' )
39+ " $@ " > " $DOTEST " /output 2>&1
40+ status=$?
41+ test $status ! = 0 &&
42+ cat " $DOTEST " /output
43+ return $status
44+ ;;
45+ * )
46+ " $@ "
47+ esac
48+ }
49+
3650require_clean_work_tree () {
3751 # test if working tree is dirty
3852 git rev-parse --verify HEAD > /dev/null &&
@@ -56,6 +70,10 @@ mark_action_done () {
5670 sed -e 1q < " $TODO " >> " $DONE "
5771 sed -e 1d < " $TODO " >> " $TODO " .new
5872 mv -f " $TODO " .new " $TODO "
73+ count=$(( $(wc - l < "$DONE ")) )
74+ total=$(( $count + $(wc - l < "$TODO ")) )
75+ printf " Rebasing (%d/%d)\r" $count $total
76+ test -z " $VERBOSE " || echo
5977}
6078
6179make_patch () {
@@ -79,18 +97,18 @@ die_abort () {
7997
8098pick_one () {
8199 case " $1 " in -n) sha1=$2 ;; * ) sha1=$1 ;; esac
82- git rev-parse --verify $sha1 || die " Invalid commit name: $sha1 "
100+ output git rev-parse --verify $sha1 || die " Invalid commit name: $sha1 "
83101 test -d " $REWRITTEN " &&
84102 pick_one_preserving_merges " $@ " && return
85103 parent_sha1=$( git rev-parse --verify $sha1 ^ 2> /dev/null)
86104 current_sha1=$( git rev-parse --verify HEAD)
87105 if [ $current_sha1 = $parent_sha1 ]; then
88- git reset --hard $sha1
89- test " a$1 " = a-n && git reset --soft $current_sha1
106+ output git reset --hard $sha1
107+ test " a$1 " = a-n && output git reset --soft $current_sha1
90108 sha1=$( git rev-parse --short $sha1 )
91- warn Fast forward to $sha1
109+ output warn Fast forward to $sha1
92110 else
93- git cherry-pick $STRATEGY " $@ "
111+ output git cherry-pick $STRATEGY " $@ "
94112 fi
95113}
96114
@@ -127,15 +145,15 @@ pick_one_preserving_merges () {
127145 done
128146 case $fast_forward in
129147 t)
130- echo " Fast forward to $sha1 "
148+ output warn " Fast forward to $sha1 "
131149 test $preserve =f && echo $sha1 > " $REWRITTEN " /$sha1
132150 ;;
133151 f)
134152 test " a$1 " = a-n && die " Refusing to squash a merge: $sha1 "
135153
136154 first_parent=$( expr " $new_parents " : " \([^ ]*\)" )
137155 # detach HEAD to current parent
138- git checkout $first_parent 2> /dev/null ||
156+ output git checkout $first_parent 2> /dev/null ||
139157 die " Cannot move HEAD to $first_parent "
140158
141159 echo $sha1 > " $DOTEST " /current-commit
@@ -147,14 +165,14 @@ pick_one_preserving_merges () {
147165 msg=" $( git cat-file commit $sha1 | \
148166 sed -e ' 1,/^$/d' -e " s/[\"\\ ]/\\\\ &/g" ) "
149167 # NEEDSWORK: give rerere a chance
150- if ! git merge $STRATEGY -m " $msg " $new_parents
168+ if ! output git merge $STRATEGY -m " $msg " $new_parents
151169 then
152170 echo " $msg " > " $GIT_DIR " /MERGE_MSG
153171 die Error redoing merge $sha1
154172 fi
155173 ;;
156174 * )
157- git cherry-pick $STRATEGY " $@ " ||
175+ output git cherry-pick $STRATEGY " $@ " ||
158176 die_with_patch $sha1 " Could not pick $sha1 "
159177 esac
160178 esac
@@ -241,15 +259,15 @@ do_next () {
241259
242260 failed=f
243261 pick_one -n $sha1 || failed=t
244- git reset --soft HEAD^
262+ output git reset --soft HEAD^
245263 author_script=$( get_author_ident_from_commit $sha1 )
246264 echo " $author_script " > " $DOTEST " /author-script
247265 case $failed in
248266 f)
249267 # This is like --amend, but with a different message
250268 eval " $author_script "
251269 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
252- git commit -F " $MSG " $EDIT_COMMIT
270+ output git commit -F " $MSG " $EDIT_COMMIT
253271 ;;
254272 t)
255273 cp " $MSG " " $GIT_DIR " /MERGE_MSG
324342 HEADNAME=$( cat " $DOTEST " /head-name)
325343 HEAD=$( cat " $DOTEST " /head)
326344 git symbolic-ref HEAD $HEADNAME &&
327- git reset --hard $HEAD &&
345+ output git reset --hard $HEAD &&
328346 rm -rf " $DOTEST "
329347 exit
330348 ;;
333351
334352 test -d " $DOTEST " || die " No interactive rebase running"
335353
336- git reset --hard && do_rest
354+ output git reset --hard && do_rest
337355 ;;
338356 -s|--strategy)
339357 shift
387405
388406 if [ ! -z " $2 " ]
389407 then
390- git show-ref --verify --quiet " refs/heads/$2 " ||
408+ output git show-ref --verify --quiet " refs/heads/$2 " ||
391409 die " Invalid branchname: $2 "
392- git checkout " $2 " ||
410+ output git checkout " $2 " ||
393411 die " Could not checkout $2 "
394412 fi
395413
456474 test -z " $( grep -ve ' ^$' -e ' ^#' < $TODO ) " &&
457475 die_abort " Nothing to do"
458476
459- git checkout $ONTO && do_rest
477+ output git checkout $ONTO && do_rest
460478 esac
461479 shift
462480done
0 commit comments