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

Re: [PATCH 6/6] push: honor branch.*.push

From
Johan Herland <johan@herland.net>
Date
Jun 24, 2013, 06:58 UTC
Message-ID
<CALKQrgebusbcDOTR+bFccoT4qzDJ8E=2LULutL0egEN9YY1v_g@mail.gmail.com>
In-Reply-To
<1372048388-16742-7-git-send-email-gitster@pobox.com>
On Mon, Jun 24, 2013 at 6:33 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 27 quoted lines
> When branch.*.push configuration variable is defined for the current
> branch, a lazy-typing "git push" (and "git push there") will push
> the commit at the tip of the current branch to the destination and
> update the branch named by that variable.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  builtin/push.c | 18 +++++++++++++++++-
>  remote.c       |  5 +++++
>  remote.h       |  2 ++
>  3 files changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/push.c b/builtin/push.c
> index f6c8047..a140b8e 100644
> --- a/builtin/push.c
> +++ b/builtin/push.c
> @@ -185,6 +185,15 @@ static void warn_unspecified_push_default_configuration(void)
>         warning("%s\n", _(warn_unspecified_push_default_msg));
>  }
>
> +static void setup_per_branch_push(struct branch *branch)
> +{
> +       struct strbuf refspec = STRBUF_INIT;
> +
> +       strbuf_addf(&refspec, "%s:%s",
> +                   branch->name, branch->push_name);
> +       add_refspec(refspec.buf);

This goes back to the question I raised in 3/6: If this code path adds refspec "foo:bar", and - say - setup_push_current() has already added refspec "foo:foo" (or simply "foo"), then do we end up pushing into "foo" or "bar"? To me, "branch.*.push" feels more specific than "push.default = current", so it would make sense that "foo:bar" overrides "foo:foo", but that is not obvious from the refspec alone. IMHO, this definitely needs some tests.

Show 15 quoted lines
> +}
> +
>  static int is_workflow_triagular(struct remote *remote)
>  {
>         struct remote *fetch_remote = remote_get(NULL);
> @@ -194,7 +203,14 @@ static int is_workflow_triagular(struct remote *remote)
>  static void setup_default_push_refspecs(struct remote *remote)
>  {
>         struct branch *branch = branch_get(NULL);
> -       int triangular = is_workflow_triagular(remote);
> +       int triangular;
> +
> +       if (branch->push_name) {
> +               setup_per_branch_push(branch);
> +               return;

I guess this return ensures that branch.*.push overrides push.default, but might there be other sources of add_refspec() that would complicate things?

Show 35 quoted lines
> +       }
> +
> +       triangular = is_workflow_triagular(remote);
>
>         switch (push_default) {
>         default:
> diff --git a/remote.c b/remote.c
> index e71f66d..e033fef 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -372,6 +372,11 @@ static int handle_config(const char *key, const char *value, void *cb)
>                         if (!value)
>                                 return config_error_nonbool(key);
>                         add_merge(branch, xstrdup(value));
> +               } else if (!strcmp(subkey, ".push")) {
> +                       if (!value)
> +                               return config_error_nonbool(key);
> +                       free(branch->push_name);
> +                       branch->push_name = xstrdup(value);
>                 }
>                 return 0;
>         }
> diff --git a/remote.h b/remote.h
> index cf56724..84e0f72 100644
> --- a/remote.h
> +++ b/remote.h
> @@ -138,6 +138,8 @@ struct branch {
>         struct refspec **merge;
>         int merge_nr;
>         int merge_alloc;
> +
> +       char *push_name;
>  };
>
>  struct branch *branch_get(const char *name);
Otherwise, this patch, and the entire series looks good to me.
...Johan
-- 
Johan Herland, <johan@herland.net>
www.herland.net
Previous: Junio C HamanoNext: Junio C Hamano
Message 21 of 36 in “Reroll of rr/triangular-push-fix”
  1. 0/6 Reroll of rr/triangular-push-fixJunio C Hamano, Jun 24, 2013
  2. 1/6 t/t5528-push-default: remove redundant test_config linesJunio C Hamano, Jun 24, 2013
  3. 2/6 config doc: rewrite push.default sectionJunio C Hamano, Jun 24, 2013
  4. 3/6 push: change `simple` to accommodate triangular workflowsJunio C Hamano, Jun 24, 2013
  5. Johan HerlandJun 24, 2013
  6. Junio C HamanoJun 24, 2013
  7. Ramkumar RamachandraJun 24, 2013
  8. Johan HerlandJun 24, 2013
  9. Ramkumar RamachandraJun 24, 2013
  10. Junio C HamanoJun 24, 2013
  11. Johan HerlandJun 24, 2013
  12. 4/6 t/t5528-push-default: generalize test_push_*Junio C Hamano, Jun 24, 2013
  13. Johan HerlandJun 24, 2013
  14. Junio C HamanoJun 24, 2013
  15. Johan HerlandJun 24, 2013
  16. Eric SunshineJun 24, 2013
  17. Johan HerlandJun 24, 2013
  18. Junio C HamanoJun 24, 2013
  19. 5/6 t/t5528-push-default: test pushdefault workflowsJunio C Hamano, Jun 24, 2013
  20. 6/6 push: honor branch.*.pushJunio C Hamano, Jun 24, 2013
  21. Johan HerlandJun 24, 2013
  22. Junio C HamanoJun 24, 2013
  23. Ramkumar RamachandraJun 24, 2013
  24. Junio C HamanoJun 24, 2013
  25. Ramkumar RamachandraJun 24, 2013
  26. Johan HerlandJun 24, 2013
  27. Junio C HamanoJun 24, 2013
  28. Junio C HamanoJun 24, 2013
  29. Ramkumar RamachandraJun 24, 2013
  30. Junio C HamanoJun 24, 2013
  31. Ramkumar RamachandraJun 24, 2013
  32. Junio C HamanoJun 24, 2013
  33. Ramkumar RamachandraJun 24, 2013
  34. Ramkumar RamachandraJun 24, 2013
  35. Junio C HamanoJun 24, 2013
  36. Ramkumar RamachandraJun 24, 2013

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.