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

[PATCH 3/4] shortlog: Document and test --format option

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Apr 26, 2010, 09:59 UTC
Message-ID
<20100426095937.GD31483@progeny.tock>
In-Reply-To
<20100426095206.GA31483@progeny.tock>

Do not document the --pretty synonym, since it takes too long to explain the name to people.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 Documentation/git-shortlog.txt |    8 ++++++
 t/t4201-shortlog.sh            |   53 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 60 insertions(+), 1 deletions(-)
diff --git a/Documentation/git-shortlog.txt b/Documentation/git-shortlog.txt
index dfd4d0c..15e92ed 100644
--- a/Documentation/git-shortlog.txt
+++ b/Documentation/git-shortlog.txt
@@ -39,6 +39,14 @@ OPTIONS
 --email::
 	Show the email address of each author.
 
+--format[='<format>']::
+	Instead of the commit subject, use some other information to
+	describe each commit.  '<format>' can be any string accepted
+	by the `--format` option of 'git log', such as '* [%h] %s'.
+	(See the "PRETTY FORMATS" section of linkgit:git-log[1].)
+
+	Each pretty-printed commit will be rewrapped before it is shown.
+
 -w[<width>[,<indent1>[,<indent2>]]]::
 	Linewrap the output by wrapping each line at `width`.  The first
 	line of each entry is indented by `indent1` spaces, and the second
diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh
index 6bfd0c0..899ddbe 100755
--- a/t/t4201-shortlog.sh
+++ b/t/t4201-shortlog.sh
@@ -39,7 +39,58 @@ test_expect_success 'setup' '
 
 	echo 6 >a1 &&
 	git commit --quiet -m "Commit by someone else" \
-		--author="Someone else <not!me>" a1
+		--author="Someone else <not!me>" a1 &&
+
+	cat >expect.template <<-\EOF
+	A U Thor (5):
+	      SUBJECT
+	      SUBJECT
+	      SUBJECT
+	      SUBJECT
+	      SUBJECT
+
+	Someone else (1):
+	      SUBJECT
+
+	EOF
+'
+
+fuzz() {
+	file=$1 &&
+	sed "
+			s/$_x40/OBJECT_NAME/g
+			s/$_x05/OBJID/g
+			s/^ \{6\}[CTa].*/      SUBJECT/g
+			s/^ \{8\}[^ ].*/        CONTINUATION/g
+		" <"$file" >"$file.fuzzy" &&
+	sed "/CONTINUATION/ d" <"$file.fuzzy"
+}
+
+test_expect_success 'default output format' '
+	git shortlog >log &&
+	fuzz log >log.predictable &&
+	test_cmp expect.template log.predictable
+'
+
+test_expect_success 'pretty format' '
+	sed s/SUBJECT/OBJECT_NAME/ expect.template >expect &&
+	git shortlog --format="%H" >log &&
+	fuzz log >log.predictable &&
+	test_cmp expect log.predictable
+'
+
+test_expect_failure '--abbrev' '
+	sed s/SUBJECT/OBJID/ expect.template >expect &&
+	git shortlog --format="%h" --abbrev=5 >log &&
+	fuzz log >log.predictable &&
+	test_cmp expect log.predictable
+'
+
+test_expect_success 'output from user-defined format is re-wrapped' '
+	sed "s/SUBJECT/two lines/" expect.template >expect &&
+	git shortlog --format="two%nlines" >log &&
+	fuzz log >log.predictable &&
+	test_cmp expect log.predictable
 '
 
 test_expect_success 'shortlog wrapping' '
-- 
1.7.1.3.g5f1e.dirty
Previous: Jonathan NiederNext: Jonathan Nieder
Message 18 of 27 in “pretty: format aliases”
  1. 0/3 pretty: format aliasesWill Palmer, Apr 25, 2010
  2. 1/3 pretty: add conditional %C?colorname placeholdersWill Palmer, Apr 25, 2010
  3. 2/3 pretty: make %H/%h dependent on --abbrev[-commit]Will Palmer, Apr 25, 2010
  4. 3/3 pretty: add aliases for pretty formatsWill Palmer, Apr 25, 2010
  5. Jonathan NiederApr 26, 2010
  6. Will PalmerApr 26, 2010
  7. Will PalmerApr 26, 2010
  8. Jonathan NiederApr 26, 2010
  9. Jeff KingApr 26, 2010
  10. Jonathan NiederApr 26, 2010
  11. Jonathan NiederApr 26, 2010
  12. Jeff KingApr 26, 2010
  13. Jeff KingApr 26, 2010
  14. Will PalmerApr 26, 2010
  15. Jonathan NiederApr 26, 2010
  16. 1/4 t4201 (shortlog): guard setup with test_expect_successJonathan Nieder, Apr 26, 2010
  17. 2/4 t4201 (shortlog): Test output format with multiple authorsJonathan Nieder, Apr 26, 2010
  18. 3/4 shortlog: Document and test --format optionJonathan Nieder, Apr 26, 2010
  19. 4/4 pretty: Respect --abbrev optionJonathan Nieder, Apr 26, 2010
  20. Will PalmerApr 26, 2010
  21. Jonathan NiederApr 26, 2010
  22. Will PalmerApr 26, 2010
  23. Jonathan NiederApr 26, 2010
  24. Jonathan NiederApr 26, 2010
  25. Jeff KingApr 26, 2010
  26. Jonathan NiederApr 26, 2010
  27. Jeff KingApr 26, 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.