Subject: [PATCH/WIP 5/8] rebase: turn rebase--interactive into a separate program

From: Nguyễn Thái Ngọc Duy <[email-masked]>
Date: Wed, 18 Mar 2015 16:55:44 +0700

---
 Makefile                             |  2 +-
 git-rebase--interactive.sh (mode +x) | 36 +++++++++++++++++++++++++++++++++++-
 git-rebase.sh                        |  9 ++-------
 3 files changed, 38 insertions(+), 9 deletions(-)
 mode change 100644 => 100755 git-rebase--interactive.sh

diff --git a/Makefile b/Makefile
index 7ee8df7..83972a2 100644
--- a/Makefile
+++ b/Makefile
@@ -446,6 +446,7 @@ SCRIPT_SH += git-pull.sh
 SCRIPT_SH += git-quiltimport.sh
 SCRIPT_SH += git-rebase.sh
 SCRIPT_SH += git-rebase--am.sh
+SCRIPT_SH += git-rebase--interactive.sh
 SCRIPT_SH += git-rebase--merge.sh
 SCRIPT_SH += git-repack.sh
 SCRIPT_SH += git-request-pull.sh
@@ -455,7 +456,6 @@ SCRIPT_SH += git-web--browse.sh
 
 SCRIPT_LIB += git-mergetool--lib
 SCRIPT_LIB += git-parse-remote
-SCRIPT_LIB += git-rebase--interactive
 SCRIPT_LIB += git-sh-setup
 SCRIPT_LIB += git-sh-i18n
 
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
old mode 100644
new mode 100755
index 44901d5..b1c71a9
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -9,7 +9,14 @@
 #
 # The original idea comes from Eric W. Biederman, in
 # http://article.gmane.org/gmane.comp.version-control.git/22407
-#
+
+. git-sh-setup
+. git-sh-i18n
+set_reflog_action "rebase -i ($action)"
+require_work_tree_exists
+
+GIT_QUIET=$git_quiet
+
 # The file containing rebase commands, comments, and empty lines.
 # This file is created by "git rebase -i" then edited by the user.  As
 # the lines are processed, they are removed from the front of this
@@ -80,6 +87,33 @@ rewritten_pending="$state_dir"/rewritten-pending
 GIT_CHERRY_PICK_HELP="$resolvemsg"
 export GIT_CHERRY_PICK_HELP
 
+write_basic_state () {
+	echo "$head_name" > "$state_dir"/head-name &&
+	echo "$onto" > "$state_dir"/onto &&
+	echo "$orig_head" > "$state_dir"/orig-head &&
+	echo "$GIT_QUIET" > "$state_dir"/quiet &&
+	test t = "$verbose" && : > "$state_dir"/verbose
+	test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy
+	test -n "$strategy_opts" && echo "$strategy_opts" > \
+		"$state_dir"/strategy_opts
+	test -n "$allow_rerere_autoupdate" && echo "$allow_rerere_autoupdate" > \
+		"$state_dir"/allow_rerere_autoupdate
+}
+
+output () {
+	case "$verbose" in
+	'')
+		output=$("$@" 2>&1 )
+		status=$?
+		test $status != 0 && printf "%s\n" "$output"
+		return $status
+		;;
+	*)
+		"$@"
+		;;
+	esac
+}
+
 warn () {
 	printf '%s\n' "$*" >&2
 }
diff --git a/git-rebase.sh b/git-rebase.sh
index ff2c2ae..86119e7 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -154,13 +154,8 @@ run_specific_rebase () {
 	export action allow_rerere_autoupdate git_am_opt git_quiet head_name keep_empty
 	export onto orig_head rebase_root resolvemsg revisions
 	export state_dir verbose strategy strategy_opts
-	if [ "$type" = am ]; then
-		exec git-rebase--am
-	elif [ "$type" = merge ]; then
-		exec git-rebase--merge
-	else
-		. git-rebase--$type
-	fi
+	export autosquash cmd force_rebase preserve_merges squash_onto switch_to upstream
+	exec git-rebase--$type
 }
 
 run_pre_rebase_hook () {
-- 
2.3.0.rc1.137.g477eb31