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

Re: [PATCH] symbolic-ref: check format of given reference

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 17, 2012, 20:55 UTC
Message-ID
<7vaa017j51.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4FDE3D7D.4090502@elegosoft.com>
Michael Schubert <mschub@elegosoft.com> writes:
Show 6 quoted lines
> This was discussed earlier this year:
>
> http://thread.gmane.org/gmane.comp.version-control.git/189715
>
> What about pointing at non-existing references? Should this
> still be allowed?

How else would you reimplement "checkout --orphan" in your own Porcelain using symbolic-ref?

>
> Additionally, I had to reindent two lines to make git-am happy
> (indent with spaces).

I doubt that it is needed; the '-' lines show runs of HT followed by fewer than 8 SP, which should not trigger "indent with spaces".

Show 29 quoted lines
>  builtin/symbolic-ref.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
> index 801d62e..22362e0 100644
> --- a/builtin/symbolic-ref.c
> +++ b/builtin/symbolic-ref.c
> @@ -43,16 +43,18 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
>  
>  	git_config(git_default_config, NULL);
>  	argc = parse_options(argc, argv, prefix, options,
> -			     git_symbolic_ref_usage, 0);
> -	if (msg &&!*msg)
> +				git_symbolic_ref_usage, 0);
> +	if (msg && !*msg)
>  		die("Refusing to perform update with empty message");
>  	switch (argc) {
>  	case 1:
>  		check_symref(argv[0], quiet);
>  		break;
>  	case 2:
> +		if (check_refname_format(argv[1], 0))
> +			die("No valid reference format: '%s'", argv[1]);
>  		if (!strcmp(argv[0], "HEAD") &&
> -		    prefixcmp(argv[1], "refs/"))
> +			prefixcmp(argv[1], "refs/"))
>  			die("Refusing to point HEAD outside of refs/");
>  		create_symref(argv[0], argv[1], msg);
>  		break;
Previous: Michael SchubertNext: Michael Schubert
Message 2 of 8 in “symbolic-ref: check format of given reference”
  1. symbolic-ref: check format of given referenceMichael Schubert, Jun 17, 2012
  2. Junio C HamanoJun 17, 2012
  3. Michael SchubertJun 18, 2012
  4. Junio C HamanoJun 18, 2012
  5. Junio C HamanoJun 18, 2012
  6. Jeff KingJun 19, 2012
  7. Jeff KingJun 19, 2012
  8. Michael SchubertJun 19, 2012

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.