git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCH] rebase -i: add run command to launch a shell command

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Jul 28, 2010, 13:29 UTC
Message-ID
<1280323784-27462-1-git-send-email-Matthieu.Moy@imag.fr>

The typical usage pattern would be to run a test (or simply a compilation command) at given points in history.

The shell command is ran, and the rebase is stopped when the command fails, to give the user an opportunity to fix the problem before continuing with "git rebase --continue".

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---

The name of the command may be subject to discussions. I've chosen "run", but maybe "shell" would be OK too. In both cases, it doesn't allow the one-letter version since both "r" and "s" are already used.

 Documentation/git-rebase.txt  |   18 ++++++++++++++++++
 git-rebase--interactive.sh    |   15 +++++++++++++++
 t/lib-rebase.sh               |    2 ++
 t/t3404-rebase-interactive.sh |   31 +++++++++++++++++++++++++++++++
 4 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index be23ad2..72e3152 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -459,6 +459,24 @@ sure that the current HEAD is "B", and call
 $ git rebase -i -p --onto Q O
 -----------------------------
 
+Reordering and editing commits usually creates untested intermediate
+steps.  You may want to check that your history editting did not break
+anything by running a test, or at least recompiling at intermediate
+points in history by using the "run" command.  You may do so by
+creating a todo list like this one:
+
+-------------------------------------------
+pick deadbee The oneline of this commit
+run make
+pick c0ffeee The oneline of the next commit
+run make test
+...
+-------------------------------------------
+
+The interactive rebase will stop when a command fails (i.e. exists
+with non-0 status) to give you an opportunity to fix the problem.  You
+can continue with `git rebase --continue`.
+
 
 SPLITTING COMMITS
 -----------------
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index b94c2a0..ab8bae0 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -537,6 +537,20 @@ do_next () {
 		esac
 		record_in_rewritten $sha1
 		;;
+	run)
+		read -r command rest < "$TODO"
+		mark_action_done
+		printf 'Running command: %s\n' "$rest"
+		if ! eval "$rest"
+		then
+			warn "Command $rest failed"
+			warn "You can fix the problem, and then run"
+			warn
+			warn "	git rebase --continue"
+			warn
+			exit 0
+		fi
+		;;
 	*)
 		warn "Unknown command: $command $sha1 $rest"
 		if git rev-parse --verify -q "$sha1" >/dev/null
@@ -957,6 +971,7 @@ first and then run 'git rebase --continue' again."
 #  e, edit = use commit, but stop for amending
 #  s, squash = use commit, but meld into previous commit
 #  f, fixup = like "squash", but discard this commit's log message
+#  run <command> = Run a shell command, and stop if it fails
 #
 # If you remove a line here THAT COMMIT WILL BE LOST.
 # However, if you remove everything, the rebase will be aborted.
diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index 6aefe27..81dd17b 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -47,6 +47,8 @@ for line in $FAKE_LINES; do
 	case $line in
 	squash|fixup|edit|reword)
 		action="$line";;
+	run*)
+		echo "$line" | sed 's/_/ /g' >> "$1";;
 	"#")
 		echo '# comment' >> "$1";;
 	">")
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 9f03ce6..274a767 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -64,6 +64,37 @@ test_expect_success 'setup' '
 	done
 '
 
+test_expect_success 'rebase -i with the run command' '
+	git checkout master
+	FAKE_LINES="1 run_touch_touch-one 2 run_touch_touch-two run_false run_touch_touch-three 3 4
+		run_touch_\"touch-file__name_with_spaces\" 5" \
+		git rebase -i A &&
+	if ! [ -f touch-one ]; then
+		echo file touch-one not created
+		exit 1
+	fi &&
+	if ! [ -f touch-two ]; then
+		echo file touch-two not created
+		exit 1
+	fi &&
+	if [ -f touch-three ]; then
+		echo "file touch-three already created. Should have stopped before"
+		exit 1
+	fi &&
+	test $(git rev-parse C) = $(git rev-parse HEAD) &&
+	git rebase --continue &&
+	if ! [ -f touch-three ]; then
+		echo "file touch-three not created"
+		exit 1
+	fi &&
+	if ! [ -f "touch-file  name with spaces" ]; then
+		echo "file \"touch-file  name with spaces\" not created"
+		exit 1
+	fi &&
+	test $(git rev-parse master) = $(git rev-parse HEAD) &&
+	rm -f touch-*
+'
+
 test_expect_success 'no changes are a nop' '
 	git checkout branch2 &&
 	git rebase -i F &&
-- 
1.7.2.21.ge9796
Next: Santi Béjar
Message 1 of 27 in “rebase -i: add run command to launch a shell command”
  1. rebase -i: add run command to launch a shell commandMatthieu Moy, Jul 28, 2010
  2. Santi BéjarJul 28, 2010
  3. Matthieu MoyJul 28, 2010
  4. Matthieu MoyJul 30, 2010
  5. Marc BranchaudJul 30, 2010
  6. Matthieu MoyJul 30, 2010
  7. Neal KreitzingerJul 30, 2010
  8. Matthieu MoyJul 31, 2010
  9. Ævar Arnfjörð BjarmasonJul 31, 2010
  10. Miles BaderJul 31, 2010
  11. Matthieu MoyAug 2, 2010
  12. rebase -i: add exec command to launch a shell commandMatthieu Moy, Aug 2, 2010
  13. Jared HanceAug 2, 2010
  14. Ævar Arnfjörð BjarmasonAug 2, 2010
  15. Johannes SixtAug 6, 2010
  16. Matthieu MoyAug 7, 2010
  17. 1/2 rebase -i: add exec command to launch a shell commandMatthieu Moy, Aug 7, 2010
  18. 2/2 test-lib: user-friendly alternatives to test [!] [-d|-f]Matthieu Moy, Aug 7, 2010
  19. Paolo BonziniAug 2, 2010
  20. Junio C HamanoAug 2, 2010
  21. Matthieu MoyAug 3, 2010
  22. Kris ShannonAug 3, 2010
  23. Matthieu MoyAug 3, 2010
  24. Paolo BonziniJul 31, 2010
  25. Ævar Arnfjörð BjarmasonJul 31, 2010
  26. Jared HanceJul 31, 2010
  27. Jared HanceJul 31, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.