git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 18:04 UTC

Re: [PATCH v3 3/3] branch: add '--no-name-prefix' option

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 6, 2026, 21:38 UTC
Message-ID
<xmqqzf4ky6xb.fsf@gitster.g>
In-Reply-To
<8f45374007fddfa4cc81e536ae6e095b0d67d5e6.1772802872.git.gitgitgadget@gmail.com>
"VALERI Yoann via GitGitGadget" <gitgitgadget@gmail.com> writes:
> -		OPT_STRING(0, "name-prefix", &name_prefix, N_("name"), N_("prefix for the branch to create")),
> +		OPT_STRING_F(0, "name-prefix", &name_prefix, N_("name"), N_("prefix for the branch to create"), PARSE_OPT_NONEG),
> +		OPT_BOOL(0, "no-name-prefix", &no_name_prefix, N_("do not use any prefix for the branch to create")),

You do not want a separate "no-*" entry in the options[] table. If we look at parse-options.c to see how OPTION_STRING is handled, we find:

	case OPTION_STRING:
		if (unset)
			*(const char **)opt->value = NULL;
		else if (opt->flags & PARSE_OPT_OPTARG && !p->opt)
			*(const char **)opt->value = (const char *)opt->defval;
		else
			return get_arg(p, opt, flags, (const char **)opt->value);
		return 0;
which tells us
 * "--no-name-prefix" is caught by "if (unset)" and causes the
   name_prefix variable set to NULL.
 * if we give OPT_OPTARG, we can allow "--name-prefix" (with no
   parameter) to default to opt->defval value; this feature is not
   very useful in our application.
 * Otherwise we get the string after "--name-prefix=".

So you do not need to do anything strange. To correctly implement the order of handling configuration and command line, you would do:

 * initialize name_prefix to NULL.  By default no name_prefix is
   used.
 * early in the cmd_branch() before you call parse_options(),
   consult the configuration and pick up branch.nameprefix
   and set it to name_prefix variable.
 * then you call parse_options().  If the command line has
   "--no-name-prefix", "if (unset)" kicks in and clears the
   name_prefix variable pointed at by the opt->value.  If the
   command line has "--name-prefix=blah", the name_prefix variable,
   which may have obtained a value from the configuration, is
   overwritten with "blah".  If the command line does not do
   anything, then the name_prefix variable will retain whatever
   value it got from the configuration.
Previous: Junio C HamanoNext: Eric Sunshine
Message 13 of 23 in “branch: add 'branch.addCurrentBranchAsPrefix' config param”
  1. branch: add 'branch.addCurrentBranchAsPrefix' config paramYoann Valeri via GitGitGadget, Feb 20, 2026
  2. Junio C HamanoFeb 20, 2026
  3. Junio C HamanoFeb 20, 2026
  4. 0/2 branch: add 'branch.addCurrentBranchAsPrefix' config paramYoann Valeri via GitGitGadget, Feb 27, 2026
  5. 1/2 branch: add 'branch.addCurrentBranchAsPrefix' config paramVALERI Yoann via GitGitGadget, Feb 27, 2026
  6. 2/2 branch: add a no-prefix optionVALERI Yoann via GitGitGadget, Feb 27, 2026
  7. Junio C HamanoFeb 27, 2026
  8. 0/3 branch: add prefixes to new branch namesYoann Valeri via GitGitGadget, Mar 6, 2026
  9. 1/3 branch: add '--name-prefix' optionVALERI Yoann via GitGitGadget, Mar 6, 2026
  10. 2/3 branch: add 'branch.namePrefix' config paramVALERI Yoann via GitGitGadget, Mar 6, 2026
  11. 3/3 branch: add '--no-name-prefix' optionVALERI Yoann via GitGitGadget, Mar 6, 2026
  12. Junio C HamanoMar 6, 2026
  13. Junio C HamanoMar 6, 2026
  14. Eric SunshineMar 7, 2026
  15. Eric SunshineMar 7, 2026
  16. Eric SunshineMar 7, 2026
  17. Junio C HamanoMar 8, 2026
  18. Junio C HamanoMar 8, 2026
  19. 0/2 branch: add prefixes to new branch namesYoann Valeri via GitGitGadget, Apr 9, 2026
  20. 1/2 branch: add '--name-prefix' optionVALERI Yoann via GitGitGadget, Apr 9, 2026
  21. 2/2 branch: add 'branch.namePrefix' config paramVALERI Yoann via GitGitGadget, Apr 9, 2026
  22. Junio C HamanoApr 9, 2026
  23. Junio C HamanoApr 9, 2026

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.