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

[PATCH 2/2] rebase -i: Preserve whitespace at beginning of commit header in $GIT_EDITOR

From
Nazri Ramliy <ayiehere@gmail.com>
Date
Jul 9, 2010, 05:20 UTC
Message-ID
<1278652843-30872-2-git-send-email-ayiehere@gmail.com>
In-Reply-To
<1278652843-30872-1-git-send-email-ayiehere@gmail.com>

During "git rebase -i", when the commit headers are shown in the editor for action (pick/squash/etc), the whitespace (if any) at the beginning of commit headers are stripped out due to the use of "read shortsha1 rest" for reading the output of "git rev-list".

The missing beginning whitespace do not pose any harm but this could be annoying when you want to identify these commits to perform actions on, for example, rewording them to remove the beginning whitespace.

Not having the whitespace makes them hard to spot, and you have to rely on something like "git log --oneline" to identify them.

This patch:
	1. Ensures that the commit header shown in $GIT_EDITOR is
	   identical to actual commit header
	2. Add a test for it
Signed-off-by: Nazri Ramliy <ayiehere@gmail.com>
---
 git-rebase--interactive.sh    |   25 ++++++++++++++-----------
 t/t3404-rebase-interactive.sh |   13 +++++++++++++
 2 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 31e6860..726cb6a 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -889,14 +889,15 @@ first and then run 'git rebase --continue' again."
 		fi
 		git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
 			--abbrev=7 --reverse --left-right --topo-order \
-			$REVISIONS | \
-			sed -n "s/^>//p" |
-		while read -r shortsha1 rest
-		do
-			if test t != "$PRESERVE_MERGES"
-			then
-				echo "pick $shortsha1 $rest" >> "$TODO"
-			else
+			$REVISIONS | sed -n "s/^>//p" > "$TODO.tmp"
+
+		if test t != "$PRESERVE_MERGES"
+		then
+			cat "$TODO.tmp" | sed "s/^/pick /" > "$TODO"
+		else
+			cat "$TODO.tmp" |
+			while read -r shortsha1 rest
+			do
 				sha1=$(git rev-parse $shortsha1)
 				if test -z "$REBASE_ROOT"
 				then
@@ -914,10 +915,12 @@ first and then run 'git rebase --continue' again."
 				if test f = "$preserve"
 				then
 					touch "$REWRITTEN"/$sha1
-					echo "pick $shortsha1 $rest" >> "$TODO"
+					grep "^$shortsha1" "$TODO.tmp" | sed "s/^/pick /" >> "$TODO"
 				fi
-			fi
-		done
+			done
+
+		fi
+		rm -f "$TODO.tmp"
 
 		# Watch for commits that been dropped by --cherry-pick
 		if test t = "$PRESERVE_MERGES"
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 47ca88f..2c3a0b9 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -648,4 +648,17 @@ test_expect_success 'rebase-i history with funny messages' '
 	test_cmp expect actual
 '
 
+cat >expect <<EOF
+pick COMMIT_ID   Commit header with beginning whitespace
+
+EOF
+
+test_expect_success 'preserve whitespace in commit summary' '
+	git checkout -b preserve-whitespace master &&
+	echo a >whitespace_test &&
+	git add whitespace_test &&
+	git commit -m"  Commit header with beginning whitespace" &&
+	REPLACE_COMMIT_ID=COMMIT_ID EXPECT_NON_COMMENT_LINES="expect" git rebase -i HEAD~1
+'
+
 test_done
-- 
1.7.2.rc2
Previous: Nazri RamliyNext: Junio C Hamano
Message 2 of 5 in “lib-rebase.sh: fake-editor.sh: Allow checking of non-comment lines in $GIT_EDITOR”
  1. 1/2 lib-rebase.sh: fake-editor.sh: Allow checking of non-comment lines in $GIT_EDITORNazri Ramliy, Jul 9, 2010
  2. 2/2 rebase -i: Preserve whitespace at beginning of commit header in $GIT_EDITORNazri Ramliy, Jul 9, 2010
  3. Junio C HamanoJul 9, 2010
  4. Nazri RamliyJul 10, 2010
  5. Junio C HamanoJul 9, 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.