Subject: Re: [GSoC RFC PATCH v2 4/7] repo-info: add the --allow-empty flag

From: Junio C Hamano <[email-masked]>
Date: Fri, 20 Jun 2025 14:39:21 -0700

Lucas Seiki Oshiro <[email-masked]> writes:

> Add a flag --allow-empty, which will force the output data to be empty
> when no field is requested.

I still think we should flip the polarity of the option and give "--all"
to iterate over all variables, and by default show nothing.

> Mentored-by: Karthik Nayak <[email-masked]>
> Mentored-by Patrick Steinhardt <[email-masked]>
> Signed-off-by: Lucas Seiki Oshiro <[email-masked]>
> ---
>  builtin/repo-info.c  | 3 +++
>  t/t1900-repo-info.sh | 5 +++--
>  2 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/repo-info.c b/builtin/repo-info.c
> index cd7c110f47..6499be0eae 100644
> --- a/builtin/repo-info.c
> +++ b/builtin/repo-info.c
> @@ -68,9 +68,12 @@ int cmd_repo_info(int argc,
>  	};
>  	struct repo_info repo_info;
>  	char *format = NULL;
> +	int allow_empty = 0;
>  	struct option options[] = {
>  		OPT_STRING(0, "format", &format, N_("format"),
>  			   N_("output format")),
> +		OPT_BOOL(0, "allow-empty", &allow_empty,
> +			 "when set, it will use an empty set of fields if no field is requested"),
>  		OPT_END()
>  	};
>  
> diff --git a/t/t1900-repo-info.sh b/t/t1900-repo-info.sh
> index 998c835795..db4a6aad17 100755
> --- a/t/t1900-repo-info.sh
> +++ b/t/t1900-repo-info.sh
> @@ -15,11 +15,12 @@ test_lazy_prereq PERLJSON '
>  '
>  
>  test_expect_success PERLJSON 'json: returns empty output with allow-empty' '
> -	git repo-info --format=json >output &&
> +	git repo-info --allow-empty --format=json >output &&
>  	test_line_count = 2 output
>  '
> +
>  test_expect_success 'plaintext: returns empty output with allow-empty' '
> -	git repo-info --format=plaintext >output &&
> +	git repo-info --allow-empty --format=plaintext >output &&
>  	test_line_count = 0 output
>  '