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

[PATCH 1/2] git-rebase: Add --stat and --no-stat for producing diffstat on rebase

From
Tor Arne Vestbø <torarnv@gmail.com>
Date
Mar 1, 2009, 21:28 UTC
Message-ID
<1235942908-5419-2-git-send-email-torarnv@gmail.com>
In-Reply-To
<1235942908-5419-1-git-send-email-torarnv@gmail.com>

The behavior of --verbose is unchanged, but uses a different state variable internally, so that the meaning of verbose output may be expanded without affecting the diffstat. This is also reflected in the documentation.

The configuration option rebase.stat works the same was as merg.stat, but the default is currently false.

Signed-off-by: Tor Arne Vestbø <torarnv@gmail.com>
---
 Documentation/git-rebase.txt |   17 ++++++++++++++++-
 git-rebase.sh                |   25 ++++++++++++++++++-------
 t/t3406-rebase-message.sh    |   23 ++++++++++++++++++++++-
 3 files changed, 56 insertions(+), 9 deletions(-)
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index da3c38c..57bd333 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -192,6 +192,13 @@ Alternatively, you can undo the 'git-rebase' with
 
     git rebase --abort
 
+CONFIGURATION
+-------------
+
+rebase.stat::
+	Whether to show a diffstat of what changed upstream since the last
+	rebase. False by default.
+
 OPTIONS
 -------
 <newbase>::
@@ -232,7 +239,15 @@ OPTIONS
 
 -v::
 --verbose::
-	Display a diffstat of what changed upstream since the last rebase.
+	Be verbose. Implies --stat.
+
+--stat::
+	Show a diffstat of what changed upstream since the last rebase. The
+	diffstat is also controlled by the configuration option rebase.stat.
+
+-n::
+--no-stat::
+	Do not show a diffstat as part of the rebase process.
 
 --no-verify::
 	This option bypasses the pre-rebase hook.  See also linkgit:githooks[5].
diff --git a/git-rebase.sh b/git-rebase.sh
index 368c0ef..26d7566 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -46,6 +46,7 @@ do_merge=
 dotest="$GIT_DIR"/rebase-merge
 prec=4
 verbose=
+diffstat=$(git config --bool rebase.stat)
 git_am_opt=
 rebase_root=
 
@@ -289,8 +290,15 @@ do
 		esac
 		do_merge=t
 		;;
+	-n|--no-stat)
+		diffstat=
+		;;
+	--stat)
+		diffstat=t
+		;;
 	-v|--verbose)
 		verbose=t
+		diffstat=t
 		;;
 	--whitespace=*)
 		git_am_opt="$git_am_opt $1"
@@ -426,18 +434,21 @@ then
 	exit 0
 fi
 
-if test -n "$verbose"
-then
-	echo "Changes from $mb to $onto:"
-	# We want color (if set), but no pager
-	GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
-fi
-
 # Detach HEAD and reset the tree
 echo "First, rewinding head to replay your work on top of it..."
 git checkout -q "$onto^0" || die "could not detach HEAD"
 git update-ref ORIG_HEAD $branch
 
+if test -n "$diffstat"
+then
+	if test -n "$verbose"
+	then
+		echo "Changes from $mb to $onto:"
+	fi
+	# We want color (if set), but no pager
+	GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
+fi
+
 # If the $onto is a proper descendant of the tip of the branch, then
 # we just fast forwarded.
 if test "$mb" = "$branch"
diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh
index 5391080..85fc7c4 100755
--- a/t/t3406-rebase-message.sh
+++ b/t/t3406-rebase-message.sh
@@ -22,7 +22,8 @@ test_expect_success setup '
 	git checkout topic &&
 	quick_one A &&
 	quick_one B &&
-	quick_one Z
+	quick_one Z &&
+	git tag start
 
 '
 
@@ -41,4 +42,24 @@ test_expect_success 'rebase -m' '
 
 '
 
+test_expect_success 'rebase --stat' '
+        git reset --hard start
+        git rebase --stat master >diffstat.txt &&
+        grep "^ fileX |  *1 +$" diffstat.txt
+'
+
+test_expect_success 'rebase w/config rebase.stat' '
+        git reset --hard start
+        git config rebase.stat true &&
+        git rebase master >diffstat.txt &&
+        grep "^ fileX |  *1 +$" diffstat.txt
+'
+
+test_expect_success 'rebase -n overrides config rebase.stat config' '
+        git reset --hard start
+        git config rebase.stat true &&
+        git rebase -n master >diffstat.txt &&
+        ! grep "^ fileX |  *1 +$" diffstat.txt
+'
+
 test_done
-- 
1.6.2.rc2.11.g80931
Previous: Tor Arne VestbøNext: Tor Arne Vestbø
Message 2 of 5 in “git-pull: Allow --stat and --no-stat to be used with --rebase”
  1. 0/2 git-pull: Allow --stat and --no-stat to be used with --rebaseTor Arne Vestbø, Mar 1, 2009
  2. 1/2 git-rebase: Add --stat and --no-stat for producing diffstat on rebaseTor Arne Vestbø, Mar 1, 2009
  3. 2/2 git-pull: Allow --stat and --no-stat to be used with --rebaseTor Arne Vestbø, Mar 1, 2009
  4. Jakub NarebskiMar 1, 2009
  5. git-rebase: Add --stat and --no-stat for producing diffstat on rebaseTor Arne Vestbø, Mar 1, 2009

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.