Skip to content

check-ref-format: use parse-options API - #2470

Open
CodeWithHusain wants to merge 1 commit into
git:masterfrom
CodeWithHusain:outreachy-microproject
Open

CodeWithHusain wants to merge 1 commit into
git:masterfrom
CodeWithHusain:outreachy-microproject

Conversation

@CodeWithHusain

@CodeWithHusain CodeWithHusain commented Oct 29, 2026 •

Copy link
Copy Markdown

cc: Karthik Nayak karthik.188@gmail.com
cc: Hussain Sitamouwala husainsitamuwala21@gmail.com

@gitgitgadget-git

Copy link
Copy Markdown

Welcome to GitGitGadget

Hi @CodeWithHusain, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests.

Please make sure that either:

  • Your Pull Request has a good description, if it consists of multiple commits, as it will be used as cover letter.
  • Your Pull Request description is empty, if it consists of a single commit, as the commit message should be descriptive enough by itself.

You can CC potential reviewers by adding a footer to the PR description with the following syntax:

CC: Revi Ewer <revi.ewer@example.com>, Ill Takalook <ill.takalook@example.net>

NOTE: DO NOT copy/paste your CC list from a previous GGG PR's description,
because it will result in a malformed CC list on the mailing list. See
example.

Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:

  • the lines should not exceed 76 columns,
  • the first line should be like a header and typically start with a prefix like "tests:" or "revisions:" to state which subsystem the change is about, and
  • the commit messages' body should be describing the "why?" of the change.
  • Finally, the commit messages should end in a Signed-off-by: line matching the commits' author.

It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code.

Contributing the patches

Before you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form /allow. A good way to find other contributors is to locate recent pull requests where someone has been /allowed:

Both the person who commented /allow and the PR author are able to /allow you.

An alternative is the channel #git-devel on the Libera Chat IRC network:

<newcontributor> I've just created my first PR, could someone please /allow me? https://github.com/gitgitgadget/git/pull/12345
<veteran> newcontributor: it is done
<newcontributor> thanks!

Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment /submit.

If you want to see what email(s) would be sent for a /submit request, add a PR comment /preview to have the email(s) sent to you. You must have a public GitHub email address for this. Note that any reviewers CC'd via the list in the PR description will not actually be sent emails.

After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail).

If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the (raw) link), then import it into your mail program. If you use GMail, you can do this via:

curl -g --user "<EMailAddress>:<Password>" \
    --url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txt

To iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description):

Changes since v1:
- Fixed a typo in the commit message (found by ...)
- Added a code comment to ... as suggested by ...
...

To send a new iteration, just add another PR comment with the contents: /submit.

Need help?

New contributors who want advice are encouraged to join git-mentoring@googlegroups.com, where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join.

You may also be able to find help in real time in the developer IRC channel, #git-devel on Libera Chat. Remember that IRC does not support offline messaging, so if you send someone a private message and log out, they cannot respond to you. The scrollback of #git-devel is archived, though.

@gitgitgadget-git

Copy link
Copy Markdown

There are issues in commit f577427:
check-ref-format: use parse-options API

  • Commit checks stopped - the message is too short
  • Commit not signed off

@dscho

dscho commented Oct 29, 2026

Copy link
Copy Markdown
Member

@CodeWithHusain could you please use your real name in the Signed-off-by line and in your author information? The Git project insists on that. You can fix it by configuring user.name, then git commit --amend --reset-author --signoff (deleting the superseded Signed-off-by line), and force-pushing.

You will also want to extend the commit message. Please follow the guidance in https://github.blog/2022-06-30-write-better-commits-build-better-projects/ to improve it, in particular with a strong focus on this part:

  What you’re doing Why you’re doing it
High-level (strategic) Intent (what does this accomplish?) Context (why does the code do what it does now?)
Low-level (tactical) Implementation (what did you do to accomplish your goal?) Justification (why is this change being made?)

@dscho

dscho commented Oct 29, 2026

Copy link
Copy Markdown
Member

/allow

@gitgitgadget-git

Copy link
Copy Markdown

User CodeWithHusain is now allowed to use GitGitGadget.

WARNING: CodeWithHusain has no public email address set on GitHub; GitGitGadget needs an email address to Cc: you on your contribution, so that you receive any feedback on the Git mailing list. Go to https://github.com/settings/profile to make your preferred email public to let GitGitGadget know which email address to use.

@gitgitgadget-git

Copy link
Copy Markdown

There is an issue in commit 92662ba:
check-ref-format: use parse-options API

  • Lines in the body of the commit messages should be wrapped between 60 and 76 characters.
    Indented lines, and lines without whitespace, are exempt

@CodeWithHusain

Copy link
Copy Markdown
Author

/preview

@gitgitgadget-git

Copy link
Copy Markdown

There is an issue in commit 92662ba:
check-ref-format: use parse-options API

  • Lines in the body of the commit messages should be wrapped between 60 and 76 characters.
    Indented lines, and lines without whitespace, are exempt

@CodeWithHusain

Copy link
Copy Markdown
Author

/preview

@gitgitgadget-git

Copy link
Copy Markdown

Preview email sent as pull.2470.git.git.1793298659175.gitgitgadget@gmail.com

@CodeWithHusain

Copy link
Copy Markdown
Author

/submit

@gitgitgadget-git

Copy link
Copy Markdown

Submitted as pull.2470.git.git.1793298807397.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2470/CodeWithHusain/outreachy-microproject-v1

To fetch this version to local tag pr-git-2470/CodeWithHusain/outreachy-microproject-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2470/CodeWithHusain/outreachy-microproject-v1

@gitgitgadget-git

Copy link
Copy Markdown

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

"Husain Sitamuwala via GitGitGadget" <gitgitgadget@gmail.com>
writes:

Didn't I read very recently that somebody else was updating
check-ref-format?  Perhaps I am hallucinating.

Anyway.

>  static const char builtin_check_ref_format_usage[] =
> -"git check-ref-format [--normalize] [<options>] <refname>\n"
> -"   or: git check-ref-format --branch <branchname-shorthand>";
> +	"git check-ref-format [--normalize] [<options>] <refname>\n"
> +	"   or: git check-ref-format --branch <branchname-shorthand>";

What is this change about?  More importantly, is it sensible to have
this and ...

> +static const char * const builtin_check_ref_format_usages[] = {
> +	"git check-ref-format [--normalize] [<options>] <refname>",
> +	"   or: git check-ref-format --branch <branchname-shorthand>",
> +	NULL
> +};

... another variable with very similar and confusing name with very
similar contents?  How do we plan to pay for the cost maintaining
them in sync?  Do we even need both of them?

> @@ -58,13 +65,26 @@ int cmd_check_ref_format(int argc,
>  			 const char *prefix,
>  			 struct repository *repo UNUSED)
>  {
> -	int i;
>  	int normalize = 0;
>  	int flags = 0;
>  	const char *refname;
>  	char *to_free = NULL;
>  	int ret = 1;
>  
> +	struct option options[] = {
> +		OPT_BOOL(0, "normalize", &normalize,
> +			 N_("normalize refname")),
> +		OPT_BOOL(0, "print", &normalize,
> +			 N_("print normalized refname")),

As can be seen in the usage string and in the "git blame" output for
the code before this patch to parse "--print", which points at
a40e6fb67a (Change check_refname_format() to reject unnormalized
refnames, 2011-09-15), we still accept "--print" as a deprecated
synonym but we do not advertise it.  A good candidate for using
PARSE_OPT_HIDDEN, probably.

> +		OPT_BIT(0, "allow-onelevel", &flags,
> +			N_("allow one-level refnames"),
> +			REFNAME_ALLOW_ONELEVEL),
> +		OPT_BIT(0, "refspec-pattern", &flags,
> +			N_("allow refspec patterns"),
> +			REFNAME_REFSPEC_PATTERN),
> +		OPT_END()
> +	};

Do we want to barf when the user says

    $ git check-ref-format --no-print --no-normalize --no-refspec-pattern ...

by the way?  With the above, we suddenly start taking these options,
and I offhand do not know what the ramifications of doing so are.

>  	BUG_ON_NON_EMPTY_PREFIX(prefix);
>  
>  	show_usage_if_asked(argc, argv,

The call to show_usage_if_asked() is still here, which means

    $ git check-ref-format -h

is intercepted by this call and the control will never come back.

We will never reach parse_options() call below, so you lose 80% of
the value of using parse-options API, which is that you get the list
of options and its descriptions for free (well not free, you
carefully prepared them in the option[] array above, and they are
wasted).

> @@ -73,22 +93,13 @@ int cmd_check_ref_format(int argc,
>  	if (argc == 3 && !strcmp(argv[1], "--branch"))
>  		return check_ref_format_branch(argv[2]);
>  
> -	for (i = 1; i < argc && argv[i][0] == '-'; i++) {
> -		if (!strcmp(argv[i], "--normalize") || !strcmp(argv[i], "--print"))
> -			normalize = 1;
> -		else if (!strcmp(argv[i], "--allow-onelevel"))
> -			flags |= REFNAME_ALLOW_ONELEVEL;
> -		else if (!strcmp(argv[i], "--no-allow-onelevel"))
> -			flags &= ~REFNAME_ALLOW_ONELEVEL;
> -		else if (!strcmp(argv[i], "--refspec-pattern"))
> -			flags |= REFNAME_REFSPEC_PATTERN;
> -		else
> -			usage(builtin_check_ref_format_usage);
> -	}
> -	if (! (i == argc - 1))
> +	argc = parse_options(argc, argv, prefix, options,
> +			     builtin_check_ref_format_usages, 0);
> +
> +	if (argc != 1)
>  		usage(builtin_check_ref_format_usage);
>  
> -	refname = argv[i];
> +	refname = argv[0];
>  	if (normalize)
>  		refname = to_free = collapse_slashes(refname);
>  	if (check_refname_format(refname, flags))
>
> base-commit: 37b3475fb530c14109211faca33716a173db61ed

The command parses its options by hand, comparing each argument
against string literals. Use the parse-options API instead so that
option handling is consistent with other builtins and the help
output is generated from the option table.

Keep the existing behavior: --print stays a hidden, deprecated
synonym for --normalize, only --allow-onelevel can be negated, and
parsing stops at the first non-option argument so that options
after <refname> are still rejected.

Drop the early show_usage_if_asked() call, so that -h is handled by
parse_options().

Two minor differences come with parse_options(): unambiguous
abbreviations of long options, such as --norm, are accepted, and
"--" may now precede <refname>.

Signed-off-by: Hussain Sitamouwala <husainsitamuwala21@gmail.com>
@CodeWithHusain

Copy link
Copy Markdown
Author

/preview

1 similar comment
@CodeWithHusain

Copy link
Copy Markdown
Author

/preview

@gitgitgadget-git

Copy link
Copy Markdown

Preview email sent as pull.2470.v2.git.git.1793516702406.gitgitgadget@gmail.com

@CodeWithHusain

Copy link
Copy Markdown
Author

/submit

@gitgitgadget-git

Copy link
Copy Markdown

Submitted as pull.2470.v2.git.git.1793694813386.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2470/CodeWithHusain/outreachy-microproject-v2

To fetch this version to local tag pr-git-2470/CodeWithHusain/outreachy-microproject-v2:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2470/CodeWithHusain/outreachy-microproject-v2

@gitgitgadget-git

Copy link
Copy Markdown

Karthik Nayak wrote on the Git mailing list (how to reply to this email):

"Husain Sitamuwala via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Hussain Sitamouwala <husainsitamuwala21@gmail.com>
>
> The command parses its options by hand, comparing each argument
> against string literals. Use the parse-options API instead so that
> option handling is consistent with other builtins and the help
> output is generated from the option table.
>
> Keep the existing behavior: --print stays a hidden, deprecated
> synonym for --normalize, only --allow-onelevel can be negated, and
> parsing stops at the first non-option argument so that options
> after <refname> are still rejected.
>
> Drop the early show_usage_if_asked() call, so that -h is handled by
> parse_options().
>
> Two minor differences come with parse_options(): unambiguous
> abbreviations of long options, such as --norm, are accepted, and
> "--" may now precede <refname>.
>

If you follow our 'Documentation/SubmittingPatches' guidelines, it
states:

  It is often beneficial to allow some time for reviewers to provide
  feedback before sending a new version, rather than sending an updated
  series immediately after receiving a review. This helps collect
  broader input, gives reviewers in different time zones a fair chance
  to comment, and avoids unnecessary churn from many rapid iterations.
  Waiting also encourages you to polish each version before sending it,
  so reviewers can focus on substantial issues rather than typos or
  other small mistakes.

Seems like Junio's review went unanswered. Which makes it hard for me to
consider dedicating time to do another review of the newer version. I
would suggest that you engage in the process before sending new
versions. I'll hold off reviewing till then :)

[snip]

@gitgitgadget-git

Copy link
Copy Markdown

User Karthik Nayak <karthik.188@gmail.com> has been added to the cc: list.

@gitgitgadget-git

Copy link
Copy Markdown

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

Karthik Nayak <karthik.188@gmail.com> writes:

> If you follow our 'Documentation/SubmittingPatches' guidelines, it
> states:
>
>   It is often beneficial to allow some time for reviewers to provide
>   feedback before sending a new version, rather than sending an updated
>   series immediately after receiving a review. This helps collect
>   broader input, gives reviewers in different time zones a fair chance
>   to comment, and avoids unnecessary churn from many rapid iterations.
>   Waiting also encourages you to polish each version before sending it,
>   so reviewers can focus on substantial issues rather than typos or
>   other small mistakes.

Thanks for bringing it up.  Also MyFirstContribution has this:

    After a few days, you may receive comments on your patch series.
    Carefully read them to understand the reviewers' perspective, and do
    not hesitate to ask for clarification.

    Reviewers may also ask about your proposed commit log or the changes.
    Answer these in your response.  They often ask because the patch needs
    clarification; use this feedback to improve your writing, and update
    the patch so the next reader does not have to ask the same question.

    Do not start coding, much less send the next version, until you finish
    discussing the current one and both sides know what to expect.  This
    saves time, lets reviewers respond before you write a patch they have
    to reject, and avoids forcing them to inspect 'v2' only to find their
    concerns unaddressed.

@gitgitgadget-git

Copy link
Copy Markdown

Hussain Sitamouwala wrote on the Git mailing list (how to reply to this email):

Karthik Nayak <karthik.188@gmail.com> writes:

> Seems like Junio's review went unanswered. Which makes it hard for me
> to consider dedicating time to do another review of the newer version.

Hi Karthik, Junio,

Sorry about that. I sent v2 before replying to Junio's review of v1,
and I should have discussed it first. I have now re-read
Documentation/SubmittingPatches and MyFirstContribution, and I will
wait for feedback before sending any further version.

> What is this change about?  More importantly, is it sensible to have
> this and ... another variable with very similar and confusing name

You are right, keeping two usage variables in sync made no sense. v2
has a single builtin_check_ref_format_usage[] array, and
usage_with_options() is used for the error path, so the old string
is gone.

> As can be seen in the usage string ... we still accept "--print" as
> a deprecated synonym but we do not advertise it.

In v2, --print is marked PARSE_OPT_HIDDEN and its help text says it
is a deprecated synonym for --normalize.

> Do we want to barf when the user says
>
>     $ git check-ref-format --no-print --no-normalize
>       --no-refspec-pattern ...

No. v2 adds PARSE_OPT_NONEG to --normalize, --print and
--refspec-pattern. Only --no-allow-onelevel is still accepted, as
before, so the set of accepted options is unchanged.

> The call to show_usage_if_asked() is still here, which means
> "git check-ref-format -h" is intercepted ...

v2 drops that call, so "-h" now goes through parse_options() and the
option list is generated from the table.

I also used PARSE_OPT_STOP_AT_NON_OPTION so that options placed after
<refname> are still rejected, as they were before.

Two behavior differences come with parse_options(), both mentioned in
the commit message: unambiguous abbreviations such as --norm are now
accepted, and "--" may now precede <refname>. If either is unwanted,
I am happy to change it. I ran t1402-check-ref-format.sh and it passes.

I will wait for further comments before preparing v3.

Thanks,
Hussain Sitamouwala

@gitgitgadget-git

Copy link
Copy Markdown

User Hussain Sitamouwala <husainsitamuwala21@gmail.com> has been added to the cc: list.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants