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

[PATCH v3 0/7] clone: allow configurable default for -o/--origin

From
Sean Barag via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 1, 2020, 03:46 UTC
Message-ID
<pull.727.v3.git.1601523977.gitgitgadget@gmail.com>
In-Reply-To
<pull.727.v2.git.1601350615.gitgitgadget@gmail.com>
v3 (changes since v2):
 * [5/7] fix compilation error: validate option_origin since remote_name
   doesn't exist yet
 * [7/7] remove default_remote_name; apply default value inline if no other
   value applied
v2 (changes since v1):
 * Convert Thanks-to trailer to Helped-by
 * Rewrite several commit titles and messages
 * Unify error reporting between clone.c and remote.c
 * Add tests for git remote add and git remote rename with invalid remote
   names
 * Prevent leak of old remote_name

v1: Took another pass at supporting a configurable default for-o/--origin, this time following Junio's suggestions from a previous approach as much as possible [1]. Unfortunately, Johannes mentioned that --template can write new config values that aren't automatically merged without re-calling git_config. There doesn't appear to be a way around this without rewriting significant amounts of init and config logic across the codebase.

While this could have been v2 of the original patchset, it's diverged so drastically from the original that it likely warrants its own root thread. If that's not appropriate though, I'd be happy to restructure!

Thanks for all the advice Junio and Johannes! This feels significantly better than my first attempt.

[1] https://lore.kernel.org/git/pull.710.git.1598456751674.gitgitgadget@gmail.com/ [2] https://github.com/gitgitgadget/git/pull/727#issuecomment-689740195

Sean Barag (7):
  clone: add tests for --template and some disallowed option pairs
  clone: use more conventional config/option layering
  remote: add tests for add and rename with invalid names
  refs: consolidate remote name validation
  clone: validate --origin option before use
  clone: read new remote name from remote_name instead of option_origin
  clone: allow configurable default for `-o`/`--origin`
 Documentation/config.txt       |  2 +
 Documentation/config/clone.txt |  5 +++
 Documentation/git-clone.txt    |  5 ++-
 builtin/clone.c                | 71 +++++++++++++++++++++++++++-------
 builtin/remote.c               |  7 +---
 refspec.c                      | 10 +++++
 refspec.h                      |  1 +
 t/t5505-remote.sh              | 13 +++++++
 t/t5606-clone-options.sh       | 68 +++++++++++++++++++++++++++++++-
 9 files changed, 159 insertions(+), 23 deletions(-)
 create mode 100644 Documentation/config/clone.txt
base-commit: 306ee63a703ad67c54ba1209dc11dd9ea500dc1f
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-727%2Fsjbarag%2Fclone_add-configurable-default-for--o-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-727/sjbarag/clone_add-configurable-default-for--o-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/727
Range-diff vs v2:
 1:  29ab418b1b = 1:  4195dec00c clone: add tests for --template and some disallowed option pairs
 2:  e3479e7b35 ! 2:  1abcf417d9 clone: use more conventional config/option layering
     @@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)
      -	git_config(git_default_config, NULL);
      +	/*
      +	 * re-read config after init_db and write_config to pick up any config
     -+	 * injected by --template and --config, respectively
     ++	 * injected by --template and --config, respectively.
      +	 */
      +	git_config(git_clone_config, NULL);
       
 3:  85be780b8e = 3:  ec371306ec remote: add tests for add and rename with invalid names
 4:  42dc18601a = 4:  cb686b4129 refs: consolidate remote name validation
 5:  fdc9d3b369 ! 5:  e1d3b54fdc clone: validate --origin option before use
     @@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)
       	if (!option_origin)
       		option_origin = "origin";
       
     -+	if (!valid_remote_name(remote_name))
     -+		die(_("'%s' is not a valid remote name"), remote_name);
     ++	if (!valid_remote_name(option_origin))
     ++		die(_("'%s' is not a valid remote name"), option_origin);
      +
       	repo_name = argv[0];
       
 6:  99f4d765b4 ! 6:  c3fba50092 clone: read new remote name from remote_name instead of option_origin
     @@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)
      +	if (option_origin)
      +		remote_name = option_origin;
       
     - 	if (!valid_remote_name(remote_name))
     - 		die(_("'%s' is not a valid remote name"), remote_name);
     +-	if (!valid_remote_name(option_origin))
     +-		die(_("'%s' is not a valid remote name"), option_origin);
     ++	if (!valid_remote_name(remote_name))
     ++		die(_("'%s' is not a valid remote name"), remote_name);
     + 
     + 	repo_name = argv[0];
     + 
      @@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)
       
       		git_config_set("core.bare", "true");
 7:  737f91c624 ! 7:  da8212e500 clone: allow configurable default for `-o`/`--origin`
     @@ builtin/clone.c: static int option_shallow_submodules;
       static char *option_template, *option_depth, *option_since;
       static char *option_origin = NULL;
      -static char *remote_name = "origin";
     -+static char *default_remote_name = "origin";
      +static char *remote_name = NULL;
       static char *option_branch = NULL;
       static struct string_list option_not = STRING_LIST_INIT_NODUP;
     @@ builtin/clone.c: static int checkout(int submodule_progress)
       static int git_clone_config(const char *k, const char *v, void *cb)
       {
      +	if (!strcmp(k, "clone.defaultremotename")) {
     -+		if (remote_name != default_remote_name)
     -+			free(remote_name);
     ++		free(remote_name);
      +		remote_name = xstrdup(v);
      +	}
       	return git_default_config(k, v, cb);
       }
       
     -@@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)
     - 	int submodule_progress;
     - 
     - 	struct strvec ref_prefixes = STRVEC_INIT;
     -+	remote_name = default_remote_name;
     - 
     - 	packet_trace_identity("clone");
     - 
      @@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)
       		option_no_checkout = 1;
       	}
     @@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)
       
       	path = get_repo_path(repo_name, &is_bundle);
      @@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)
     - 
     - 	/*
     - 	 * re-read config after init_db and write_config to pick up any config
     --	 * injected by --template and --config, respectively
     -+	 * injected by --template and --config, respectively.
       	 */
       	git_config(git_clone_config, NULL);
       
     @@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)
      +	 * apply the remote name provided by --origin only after this second
      +	 * call to git_config, to ensure it overrides all config-based values.
      +	 */
     -+	if (option_origin)
     -+		remote_name = option_origin;
     ++	if (option_origin != NULL)
     ++		remote_name = xstrdup(option_origin);
     ++
     ++	if (remote_name == NULL)
     ++		remote_name = xstrdup("origin");
      +
      +	if (!valid_remote_name(remote_name))
      +		die(_("'%s' is not a valid remote name"), remote_name);
     @@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)
       	if (option_bare) {
       		if (option_mirror)
       			src_ref_prefix = "refs/";
     +@@ builtin/clone.c: int cmd_clone(int argc, const char **argv, const char *prefix)
     + 	junk_mode = JUNK_LEAVE_REPO;
     + 	err = checkout(submodule_progress);
     + 
     ++	free(remote_name);
     + 	strbuf_release(&reflog_msg);
     + 	strbuf_release(&branch_top);
     + 	strbuf_release(&key);
      
       ## t/t5606-clone-options.sh ##
      @@ t/t5606-clone-options.sh: test_expect_success 'clone -o' '
-- 
gitgitgadget
Previous: Sean BaragNext: Sean Barag via GitGitGadget
Message 41 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.