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

Re: [PATCH 3/4] clone: validate --origin option before use

From
Sean Barag <sean@barag.org>
Date
Sep 16, 2020, 16:28 UTC
Message-ID
<20200916162839.1877248-1-sean@barag.org>
In-Reply-To
<bf0107fb-2a6c-68d3-df24-72c6a9df6182@gmail.com>
On Fri, 11 Sep 2020 at 15:24:15 -0400, Derrick Stolee writes:
Show 10 quoted lines
> On 9/11/2020 2:25 PM, Sean Barag via GitGitGadget wrote:
> > +	strbuf_addf(&resolved_refspec, "refs/heads/test:refs/remotes/%s/test", option_origin);
> > +	if (!valid_fetch_refspec(resolved_refspec.buf))
> > +		/* TRANSLATORS: %s will be the user-provided --origin / -o option */
> > +		die(_("'%s' is not a valid origin name"), option_origin);
>
> Looking at this again, I'm not sure the translators note is
> necessary. Also, I would say "is not a valid remote name".
> That makes the string align with the already-translated string
> in builtin/remote.c.

Makes perfect sense! My original intention was to provide a separate use-case specific message, but you're right: "is not a valid remote name" (as in `builtin/remote.c`) is still very clear.

Show 25 quoted lines
> This code is duplicated from builtin/remote.c, so I'd rather
> see this be a helper method in refspec.c and have both
> builtin/clone.c and builtin/remote.c call that helper.
>
> Here is the helper:
>
> void valid_remote_name(const char *name)
> {
> 	int result;
> 	struct strbuf refspec = STRBUF_INIT;
> 	strbuf_addf(&refspec, "refs/heads/test:refs/remotes/%s/test", name);
> 	result = valid_fetch_refspec(refspec.buf);
> 	strbuf_release(&refspec);
> 	return result;
> }
>
> And here is the use in builtin/clone.c:
>
> 	if (!valid_remote_name(option_origin))
> 		die(_("'%s' is not a valid remote name"), option_origin);
>
> and in builtin/remote.c:
>
> 	if (!valid_remote_name(name))
> 		die(_("'%s' is not a valid remote name"), name);

That's a fantastic idea -- thanks for the suggestion! I'll do that for v2.

Show 11 quoted lines
> > +test_expect_success 'rejects invalid -o/--origin' '
> > +
> > +	test_expect_code 128 git clone -o "bad...name" parent clone-bad-name 2>err &&
> > +	test_debug "cat err" &&
> > +	test_i18ngrep "'\''bad...name'\'' is not a valid origin name" err
> > +
> > +'
> > +
>
> Double newlines here! I personally appreciate newlines to
> spread out content, but it doesn't fit our guidelines.
Darn, I missed this one.  Thanks for the heads-up :)

-- Sean

Previous: Derrick StoleeNext: Junio C Hamano
Message 18 of 49 in “clone: allow configurable default for -o/--origin”
  1. 0/4 clone: allow configurable default for -o/--originSean Barag via GitGitGadget, Sep 11, 2020
  2. 2/4 clone: call git_config before parse_optionsSean Barag via GitGitGadget, Sep 11, 2020
  3. Derrick StoleeSep 11, 2020
  4. Junio C HamanoSep 11, 2020
  5. Sean BaragSep 16, 2020
  6. 1/4 clone: add tests for --template and some disallowed option pairsSean Barag via GitGitGadget, Sep 11, 2020
  7. Derrick StoleeSep 11, 2020
  8. Jeff KingSep 11, 2020
  9. Eric SunshineSep 11, 2020
  10. Sean BaragSep 16, 2020
  11. Taylor BlauSep 12, 2020
  12. Sean BaragSep 15, 2020
  13. Jeff KingSep 16, 2020
  14. Junio C HamanoSep 11, 2020
  15. Derrick StoleeSep 12, 2020
  16. 3/4 clone: validate --origin option before useSean Barag via GitGitGadget, Sep 11, 2020
  17. Derrick StoleeSep 11, 2020
  18. Sean BaragSep 16, 2020
  19. Junio C HamanoSep 11, 2020
  20. Sean BaragSep 16, 2020
  21. Sean BaragSep 21, 2020
  22. 4/4 clone: allow configurable default for `-o`/`--origin`Sean Barag via GitGitGadget, Sep 11, 2020
  23. Derrick StoleeSep 11, 2020
  24. Sean BaragSep 28, 2020
  25. Junio C HamanoSep 11, 2020
  26. Sean BaragSep 28, 2020
  27. Andrei RybakSep 17, 2020
  28. Derrick StoleeSep 11, 2020
  29. Junio C HamanoSep 11, 2020
  30. 0/7 clone: allow configurable default for -o/--originSean Barag via GitGitGadget, Sep 29, 2020
  31. 1/7 clone: add tests for --template and some disallowed option pairsSean Barag via GitGitGadget, Sep 29, 2020
  32. 2/7 clone: use more conventional config/option layeringSean Barag via GitGitGadget, Sep 29, 2020
  33. 3/7 remote: add tests for add and rename with invalid namesSean Barag via GitGitGadget, Sep 29, 2020
  34. 6/7 clone: read new remote name from remote_name instead of option_originSean Barag via GitGitGadget, Sep 29, 2020
  35. 5/7 clone: validate --origin option before useSean Barag via GitGitGadget, Sep 29, 2020
  36. 4/7 refs: consolidate remote name validationSean Barag via GitGitGadget, Sep 29, 2020
  37. 7/7 clone: allow configurable default for `-o`/`--origin`Sean Barag via GitGitGadget, Sep 29, 2020
  38. Junio C HamanoSep 29, 2020
  39. Sean BaragSep 29, 2020
  40. 0/7 clone: allow configurable default for -o/--originSean Barag, Sep 29, 2020
  41. 0/7 clone: allow configurable default for -o/--originSean Barag via GitGitGadget, Oct 1, 2020
  42. 1/7 clone: add tests for --template and some disallowed option pairsSean Barag via GitGitGadget, Oct 1, 2020
  43. 5/7 clone: validate --origin option before useSean Barag via GitGitGadget, Oct 1, 2020
  44. 7/7 clone: allow configurable default for `-o`/`--origin`Sean Barag via GitGitGadget, Oct 1, 2020
  45. 2/7 clone: use more conventional config/option layeringSean Barag via GitGitGadget, Oct 1, 2020
  46. 3/7 remote: add tests for add and rename with invalid namesSean Barag via GitGitGadget, Oct 1, 2020
  47. 6/7 clone: read new remote name from remote_name instead of option_originSean Barag via GitGitGadget, Oct 1, 2020
  48. 4/7 refs: consolidate remote name validationSean Barag via GitGitGadget, Oct 1, 2020
  49. Derrick StoleeOct 2, 2020

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.