git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Tao Klerks via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Tao Klerks <tao@klerks.biz>
Subject: Re: [PATCH v2 1/2] merge: new autosetupmerge option 'simple' for matching branches
Date: Fri, 25 Feb 2022 12:15:52 -0800	[thread overview]
Message-ID: <xmqqczjaaeiv.fsf@gitster.g> (raw)
In-Reply-To: <890e016bfc0809d25a4ae8ae924b23895f520810.1645815142.git.gitgitgadget@gmail.com> (Tao Klerks via GitGitGadget's message of "Fri, 25 Feb 2022 18:52:21 +0000")

"Tao Klerks via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Tao Klerks <tao@klerks.biz>
>
> This commit introduces a new option to the branch.autosetupmerge
> setting, "simple", which is intended to be consistent with and
> complementary to the push.default "simple" option.

Documentation/SubmittingPatches.

We do not say "This commit does this".  Instead, we say "Add a new
option that does X".  Usually that is done after the explanation of
the status quo is finished to make readers understand what the
problem the change is trying to solve is.  So...

> The push.defaut option "simple" helps produce
> predictable/understandable behavior for beginners, where they don't
> accidentally push to the "wrong" branch in centralized workflows. If
> they create a local branch with a different name and then try to do a
> plain push, it will helpfully fail and explain why.

... this would be a better first paragraph to start the proposed log
message with.

	With push.default set to "simple", the users fork from a
	local branch from a remote-tracking branch of the same name,
	and are protected from a mistake to push to a wrong branch.
	If they create a ... and explain why.

> However, such users can often find themselves confused by the behavior
> of git after they first branch, and before they push. At that stage,

Depending on how they "branch", they may or may not be confused.  Be
more specific to illustrate what problem you are solving, e.g.

	... after they create a new local branch from a
	remote-tracking branch with a different name.

> their upstream tracking branch is the original remote branch, and pull
> will be bringing in "upstream changes" - eg all changes to "main", in
> a typical project where that's where they branched from.

OK.  So "pull" tries to grab from the upstream (which is most likely
an integration branch with bland name like 'master', 'main' or
'trunk'), while "push" does not allow the work on a branch (which is
named after the theme of the work and not a bland name suitable for
integration branches) to be pushed to the upstream.

It may probably not be so clear why it is a problem to many readers,
I suspect.  Isn't that what happens in a typical triangular workflow
to work with a project with a centralized repository?  You fork from
the integration branch shared among project participants, you work on
your own branch, occasionally rebasing on top of the updated upstream,
and when you are done, try to push it out to the integration branch,
and that final leg needs to be explicit to make sure you won't push
out to a wrong branch (in this case, a new branch at the remote with
the same name as your local topic branch) by mistake?

> On the other hand, once they push their new branch (dealing with the
> initial error, following instructions to push to the right name),
> subsequent "pull" calls will behave as expected, only bring in any
> changes to that new branch they pushed.

Is that because the upstream for this local branch is updated?
The "following instructions..." part may want to clarify.

It somehow feels that a better solution might be to suggest
updating the push.default to 'upstream' when it happens?  I dunno.

In any case, now we have explained what happens with today's code,
here is a good place to propose a solution.  Do so in imperative,
e.g.

    Allow branch.autosetupmerge to take a new value, 'simple', which 
    sets the upstream of the new branch only when the local branch
    being created has the same name as the remote-tracking branch it
    was created out of.  Otherwise the new local branch will not get
    any tracking information and 

or something, perhaps?

> +	/*
> +	 * This check does not apply to the BRANCH_TRACK_INHERIT
> +	 * option; you can inherit one or more tracking entries
> +	 * and the tracking.matches counter is not incremented.
> +	 */
>  	if (tracking.matches > 1)
>  		die(_("not tracking: ambiguous information for ref %s"),
>  		    orig_ref);

> +	if (track == BRANCH_TRACK_SIMPLE) {
> +		/*
> +		 * Only track if remote branch name matches.
> +		 * Reaching into items[0].string is safe because
> +		 * we know there is at least one and not more than
> +		 * one entry (because not BRANCH_TRACK_INHERIT).
> +		 */

OK, because in the pre-context of this hunk, we would have jumped to
cleanup: if there were no .matches; so we know there should at least
be one, and we rejected ambiguous matches already, so we know there
is only one.

> +		const char *tracked_branch;
> +		if (!skip_prefix(tracking.srcs->items[0].string,
> +				 "refs/heads/", &tracked_branch) ||
> +		    strcmp(tracked_branch, new_ref))
> +			return;
> +	}

That looks sensible.  Sometimes we do not set tracking information
and just return.

  reply	other threads:[~2022-02-25 20:16 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-24  9:45 [PATCH 0/3] adding new branch.autosetupmerge option "simple" Tao Klerks via GitGitGadget
2022-02-24  9:45 ` [PATCH 1/3] merge: new autosetupmerge option 'simple' for matching branches Tao Klerks via GitGitGadget
2022-02-24 19:20   ` Junio C Hamano
2022-02-24  9:45 ` [PATCH 2/3] t3200: tests for new branch.autosetupmerge option "simple" Tao Klerks via GitGitGadget
2022-02-24  9:45 ` [PATCH 3/3] branch documentation: new autosetupmerge " Tao Klerks via GitGitGadget
2022-02-24 19:38   ` Junio C Hamano
2022-02-25 18:52 ` [PATCH v2 0/2] adding new branch.autosetupmerge " Tao Klerks via GitGitGadget
2022-02-25 18:52   ` [PATCH v2 1/2] merge: new autosetupmerge option 'simple' for matching branches Tao Klerks via GitGitGadget
2022-02-25 20:15     ` Junio C Hamano [this message]
2022-02-27 23:59       ` Tao Klerks
2022-02-25 18:52   ` [PATCH v2 2/2] t3200: tests for new branch.autosetupmerge option "simple" Tao Klerks via GitGitGadget
2022-02-28  7:14   ` [PATCH v3 0/2] adding " Tao Klerks via GitGitGadget
2022-02-28  7:14     ` [PATCH v3 1/2] merge: new autosetupmerge option 'simple' for matching branches Tao Klerks via GitGitGadget
2022-02-28 10:39       ` Ævar Arnfjörð Bjarmason
2022-03-02  9:35         ` Tao Klerks
2022-03-20 17:00           ` Tao Klerks
2022-02-28  7:14     ` [PATCH v3 2/2] t3200: tests for new branch.autosetupmerge option "simple" Tao Klerks via GitGitGadget
2022-02-28  9:34       ` Ævar Arnfjörð Bjarmason
2022-03-01  2:58         ` Eric Sunshine
2022-03-01  9:59           ` Tao Klerks
2022-03-01  9:59         ` Tao Klerks
2022-03-21  6:17     ` [PATCH v4] merge: new autosetupmerge option 'simple' for matching branches Tao Klerks via GitGitGadget
2022-04-18 18:15       ` Josh Steadmon
2022-04-20  5:12         ` Tao Klerks
2022-04-20 17:19           ` Josh Steadmon
2022-04-20 17:43           ` Junio C Hamano
2022-04-20 21:31             ` Tao Klerks
2022-04-21  1:53               ` Junio C Hamano
2022-04-21 10:04                 ` Tao Klerks
2022-04-22  2:27                   ` Junio C Hamano
2022-04-22  9:24                     ` Tao Klerks
2022-04-22 13:27                       ` Tao Klerks
2022-04-23  4:44                       ` Junio C Hamano
2022-04-24 11:57                         ` Tao Klerks
2022-04-29  7:31                           ` Tao Klerks
2022-04-29  9:56       ` [PATCH v5 0/3] New options to support "simple" centralized workflow Tao Klerks via GitGitGadget
2022-04-29  9:56         ` [PATCH v5 1/3] branch: new autosetupmerge option 'simple' for matching branches Tao Klerks via GitGitGadget
2022-04-29  9:56         ` [PATCH v5 2/3] push: default to single remote even when not named origin Tao Klerks via GitGitGadget
2022-04-29  9:56         ` [PATCH v5 3/3] push: new config option "push.autoSetupRemote" supports "simple" push Tao Klerks via GitGitGadget
2022-04-29 18:50         ` [PATCH v5 0/3] New options to support "simple" centralized workflow Junio C Hamano
2022-04-30 15:48           ` Tao Klerks

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqczjaaeiv.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=tao@klerks.biz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).