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

Re: [PATCH v3 1/5] pretty: add conditional %C?colorname placeholders

From
Junio C Hamano <gitster@pobox.com>
Date
May 2, 2010, 03:12 UTC
Message-ID
<7vvdb7yp1u.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1272656128-2002-2-git-send-email-wmpalmer@gmail.com>
Will Palmer <wmpalmer@gmail.com> writes:
Show 10 quoted lines
> diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
> new file mode 100755
> index 0000000..b7ec943
> --- /dev/null
> +++ b/t/t4205-log-pretty-formats.sh
> @@ -0,0 +1,52 @@
> +#!/bin/sh
> +#
> +# Released into Public Domain by Will Palmer 2010
> +#
Hmm...
Show 12 quoted lines
> +test_description='Test pretty formats'
> +. ./test-lib.sh
> +
> +test_expect_success "set up basic repos" \
> +	">foo &&
> +	>bar &&
> +	git add foo &&
> +	test_tick &&
> +	git commit -m initial &&
> +	git add bar &&
> +	test_tick &&
> +	git commit -m 'add bar'"
Just a style thing, but it is easier to read to write:
        test_expect_success 'set up basic repos' '
                >foo &&
                >bar &&
                ...
        '
Show 9 quoted lines
> +for flag in false true always; do
> +for color in red green blue reset; do
> +
> +	make_expected="git config --get-color no.such.slot $color >expected"
> +	test_expect_success "%C$color with color.ui $flag" \
> +		"$make_expected &&
> +		git config color.ui $flag &&
> +		git log -1 --pretty=format:'%C$color' > actual &&
> +		test_cmp expected actual"

I would really prefer to see a test that checks output with real contents, not just "switch to color". E.g. --format="Title: %C${color}%s%C(normal)" or something like that.

Also you probably would want to make this one round into a shell function e.g.

	make_expected ()
        {
        	git config --get-color no.such.slot "$1"
	}
	run_format_test ()
        {
		flag=$1 color=$2
                test_expect_success "%C$color with ..." '
			make_expected $color >expected
                        git config color.ui $flag &&
                        git log -1 --pretty=format:'%C($color)' >actual &&
                        test_cmp expected actual"
                '
                ...
	}
and then run this loop:
	for flag in flase true always
        do
        	for color in red green blue reset
                do
                	run_format_test $flag $color
		done
	done
Previous: Will PalmerNext: Will Palmer
Message 3 of 21 in “pretty: format aliases”
  1. 0/5 pretty: format aliasesWill Palmer, Apr 30, 2010
  2. 1/5 pretty: add conditional %C?colorname placeholdersWill Palmer, Apr 30, 2010
  3. Junio C HamanoMay 2, 2010
  4. Will PalmerMay 2, 2010
  5. 2/5 pretty: make %H/%h/etc respect --abbrev[-commit]Will Palmer, Apr 30, 2010
  6. Junio C HamanoMay 2, 2010
  7. Jeff KingMay 2, 2010
  8. Junio C HamanoMay 2, 2010
  9. Jeff KingMay 2, 2010
  10. Will PalmerMay 2, 2010
  11. Will PalmerMay 2, 2010
  12. Junio C HamanoMay 2, 2010
  13. Jonathan NiederMay 2, 2010
  14. 3/5 pretty: make it easier to add new formatsWill Palmer, Apr 30, 2010
  15. 4/5 pretty: add infrastructure to allow format aliasesWill Palmer, Apr 30, 2010
  16. Junio C HamanoMay 2, 2010
  17. Will PalmerMay 2, 2010
  18. 5/5 pretty: add aliases for pretty formatsWill Palmer, Apr 30, 2010
  19. Junio C HamanoMay 2, 2010
  20. Jeff KingMay 2, 2010
  21. Junio C HamanoMay 2, 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.