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

Re: [PATCH v5 6/6] add worktree.guessRemote config option

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Nov 27, 2017, 20:59 UTC
Message-ID
<20171127205918.GB32057@hank>
In-Reply-To
<xmqq8tescj9p.fsf@gitster.mtv.corp.google.com>
On 11/27, Junio C Hamano wrote:
Show 54 quoted lines
> Thomas Gummerer <t.gummerer@gmail.com> writes:
> 
> > +worktree.guessRemote::
> > +	With `add`, if no branch argument, and neither of `-b` nor
> > +	`-B` nor `--detach` are given, the command defaults to
> > +	creating a new branch from HEAD.  If `worktree.guessRemote` is
> > +	set to true, `worktree add` tries to find a remote-tracking
> > +	branch whose name uniquely matches the new branch name.  If
> > +	such a branch exists, it is checked out and set as "upstream"
> > +	for the new branch.  If no such match can be found, it falls
> > +	back to creating a new branch from the current HEAD.
> 
> Unlike the part I commented on in the previous step, this one is
> clear that the feature only kicks in for 'add <path>' without
> anything else, which is good.
> 
> > diff --git a/builtin/worktree.c b/builtin/worktree.c
> > index 15cb1600ee..426aea8761 100644
> > --- a/builtin/worktree.c
> > +++ b/builtin/worktree.c
> > @@ -33,8 +33,19 @@ struct add_opts {
> >  
> >  static int show_only;
> >  static int verbose;
> > +static int guess_remote;
> >  static timestamp_t expire;
> >  
> > +static int git_worktree_config(const char *var, const char *value, void *cb)
> > +{
> > +	if (!strcmp(var, "worktree.guessremote")) {
> > +		guess_remote = git_config_bool(var, value);
> > +		return 0;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> 
> It is a lot more consistent with the established practice if this
> function had
> 
> 	return git_default_config(var, value, cb);
> 
> instead of "return 0" at the end, and then have the call to
> 
> 	git_config(git_default_config, NULL);
> 
> we have in cmd_worktree() replaced with
> 
> 	git_config(git_worktree_config, NULL);
> 
> That would avoid having to scan the entire set of config keys once
> in cmd_worktree() and then again in add(), the latter one only
> looking for a single variable.

Makes sense, I missed that. I'll fix it in the re-roll. I'll wait a few days to see if there are any more comments on the series and then re-roll it with the suggested changes.

Thanks for the review!
Previous: Junio C HamanoNext: Thomas Gummerer
Message 26 of 36 in “make git worktree add dwim more”
  1. 0/4 make git worktree add dwim moreThomas Gummerer, Nov 22, 2017
  2. 4/4 worktree: make add <path> dwimThomas Gummerer, Nov 22, 2017
  3. Junio C HamanoNov 24, 2017
  4. Thomas GummererNov 25, 2017
  5. Paul SmithNov 25, 2017
  6. Thomas GummererNov 25, 2017
  7. Randall S. BeckerNov 25, 2017
  8. Thomas GummererNov 25, 2017
  9. Paul SmithNov 25, 2017
  10. Junio C HamanoNov 26, 2017
  11. Thomas GummererNov 26, 2017
  12. 3/4 worktree: make add <path> <branch> dwimThomas Gummerer, Nov 22, 2017
  13. Junio C HamanoNov 24, 2017
  14. 1/4 checkout: factor out functions to new lib fileThomas Gummerer, Nov 22, 2017
  15. Junio C HamanoNov 24, 2017
  16. 2/4 worktree: add --[no-]track option to the add subcommandThomas Gummerer, Nov 22, 2017
  17. Junio C HamanoNov 24, 2017
  18. Thomas GummererNov 25, 2017
  19. 0/6 make git worktree add dwim moreThomas Gummerer, Nov 26, 2017
  20. 1/6 checkout: factor out functions to new lib fileThomas Gummerer, Nov 26, 2017
  21. 2/6 worktree: add can be created from any commit-ishThomas Gummerer, Nov 26, 2017
  22. 3/6 worktree: add --[no-]track option to the add subcommandThomas Gummerer, Nov 26, 2017
  23. 4/6 worktree: make add <path> <branch> dwimThomas Gummerer, Nov 26, 2017
  24. 6/6 add worktree.guessRemote config optionThomas Gummerer, Nov 26, 2017
  25. Junio C HamanoNov 27, 2017
  26. Thomas GummererNov 27, 2017
  27. 5/6 worktree: add --guess-remote flag to add subcommandThomas Gummerer, Nov 26, 2017
  28. Junio C HamanoNov 27, 2017
  29. Thomas GummererNov 27, 2017
  30. 0/6 make git worktree add dwim moreThomas Gummerer, Nov 29, 2017
  31. 1/6 checkout: factor out functions to new lib fileThomas Gummerer, Nov 29, 2017
  32. 2/6 worktree: add can be created from any commit-ishThomas Gummerer, Nov 29, 2017
  33. 3/6 worktree: add --[no-]track option to the add subcommandThomas Gummerer, Nov 29, 2017
  34. 5/6 worktree: add --guess-remote flag to add subcommandThomas Gummerer, Nov 29, 2017
  35. 6/6 add worktree.guessRemote config optionThomas Gummerer, Nov 29, 2017
  36. 4/6 worktree: make add <path> <branch> dwimThomas Gummerer, Nov 29, 2017

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.