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

Re: [PATCH v3 1/2] status: introduce status.short to enable --short by default

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 10, 2013, 18:16 UTC
Message-ID
<7vr4g9j0gh.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1370878068-7643-1-git-send-email-Jorge-Juan.Garcia-Garcia@ensimag.imag.fr>

Jorge Juan Garcia Garcia <Jorge-Juan.Garcia-Garcia@ensimag.imag.fr> writes:

Show 43 quoted lines
> Some people always run 'git status -s'.
> The configuration variable status.short allows to set it by default.
>
> Signed-off-by: Jorge Juan Garcia Garcia <Jorge-Juan.Garcia-Garcia@ensimag.imag.fr>
> Signed-off-by: Mathieu Lienard--Mayor <Mathieu.Lienard--Mayor@ensimag.imag.fr>
> Signed-off-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
> ---
>
> Changes since v2:
>  -removal of double quotes in test
>  -use of git config --unset to clean up test environment
>
>  Documentation/config.txt |    4 ++++
>  builtin/commit.c         |    5 +++++
>  t/t7508-status.sh        |   35 +++++++++++++++++++++++++++++++++++
>  3 files changed, 44 insertions(+), 0 deletions(-)
>
> diff --git a/Documentation/config.txt b/Documentation/config.txt
> index 6e53fc5..1983bf7 100644
> --- a/Documentation/config.txt
> +++ b/Documentation/config.txt
> @@ -2066,6 +2066,10 @@ status.relativePaths::
>  	relative to the repository root (this was the default for Git
>  	prior to v1.5.4).
>  
> +status.short::
> +	Set to true to enable --short by default in linkgit:git-status[1].
> +	The option --no-short takes precedence over this variable.
> +
>  status.showUntrackedFiles::
>  	By default, linkgit:git-status[1] and linkgit:git-commit[1] show
>  	files which are not currently tracked by Git. Directories which
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 1621dfc..287f1cb 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -1112,6 +1112,11 @@ static int git_status_config(const char *k, const char *v, void *cb)
>  			s->submodule_summary = -1;
>  		return 0;
>  	}
> +	if (!strcmp(k, "status.short")) {
> +		if (git_config_bool(k, v))
> +			status_format = STATUS_FORMAT_SHORT;
And if the user has
	[status]
        	short = no

in $GIT_DIR/config for this particular project, perhaps in order to override a blanket setting

	[status]
		short
that is in $HOME/.gitconfig, what should happen?
Perhaps you need
	if (git_config_bool(...))
        	status_format = STATUS_FORMAT_SHORT;
	else        	
        	status_format = STATUS_FORMAT_NONE; /* default */
or something here?
Show 47 quoted lines
> +		return 0;
> +	}
>  	if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
>  		s->use_color = git_config_colorbool(k, v);
>  		return 0;
> diff --git a/t/t7508-status.sh b/t/t7508-status.sh
> index e2ffdac..d99ca9f 100755
> --- a/t/t7508-status.sh
> +++ b/t/t7508-status.sh
> @@ -1335,4 +1335,39 @@ test_expect_failure '.git/config ignore=all suppresses submodule summary' '
>  	git config -f .gitmodules  --remove-section submodule.subname
>  '
>  
> +test_expect_success 'Setup of test environment' '
> +	git config status.showUntrackedFiles no
> +'
> +
> +test_expect_success '"status.short=true" same as "-s"' '
> +	git -c status.short=true status >actual &&
> +	git status -s >expected_short &&
> +	test_cmp actual expected_short
> +'
> +
> +test_expect_success '"status.short=true" different from "--no-short"' '
> +	git status --no-short >expected_noshort &&
> +	test_must_fail test_cmp actual expected_noshort
> +'
> +
> +test_expect_success '"status.short=true" weaker than "--no-short"' '
> +	git -c status.short=true status --no-short >actual &&
> +	test_cmp actual expected_noshort
> +'
> +
> +test_expect_success '"status.short=false" same as "--no-short"' '
> +	git -c status.short=false status >actual &&
> +	git status -s >expected_short &&
> +	test_cmp actual expected_noshort
> +'
> +
> +test_expect_success '"status.short=false" weaker than "-s"' '
> +	git -c status.short=false status -s >actual &&
> +	test_cmp actual expected_short
> +'
> +
> +test_expect_success 'Restore default test environment' '
> +	git config --unset status.showUntrackedFiles
> +'
A few observations.
 * It is very good that you check not just positive cases that show
   off how well this new feature works (i.e. status.short set
   without command line override gives a short output) but also
   negative cases that make sure the new feature does not kick in
   when it should not.  You test all four combinations, which is
   good.
 * If any of the first three fails, you may not have the correct
   string in expected_short or expected_noshort when running later
   tests that depend on them.
 * Similarly, if the first one to set showUntrackedFiles fails, the
   last one to --unset would also fail.

Perhaps limiting the number of tests that must pass (otherwise the remainder becomes useless) by doing something like this is a better alternative:

	test_expect_success 'setup for status.short' '
		git status --short >expected_short &&
                git status --no-short >expected_noshort
	'
	test_expect_success '-c status.short=true == status -s' '
        	test_config status.showUntrackedFile no &&
        	test_config status.short yes &&
                git status >actual &&
                test_cmp expected_short actual
	'
	test_expect_success 'status --no-short defeats status.short=true' '
        	test_config status.showUntrackedFile no &&
        	test_config status.short yes &&
                git status --no-short >actual &&
                test_cmp expected_noshort actual
	'
	... other two combinations here ...
Points to note:
 * test_config takes care of setting configuration variables and
   then unsetting them when the test is done.
 * test_cmp should compare expected with actual, not the other way,
   so that "./t7508-status.sh -v" shows the diff between the two 
   shows how the actual output differs from what is expected.
Previous: Junio C HamanoNext: Matthieu Moy
Message 4 of 5 in “status: introduce status.short to enable --short by default”
  1. 1/2 status: introduce status.short to enable --short by defaultJorge Juan Garcia Garcia, Jun 10, 2013
  2. 2/2 status:introduce status.branch to enable --branch by defaultJorge Juan Garcia Garcia, Jun 10, 2013
  3. Junio C HamanoJun 10, 2013
  4. Junio C HamanoJun 10, 2013
  5. Matthieu MoyJun 10, 2013

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.