All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: Mathias Kunter <mathiaskunter@gmail.com>,
	Elijah Newren <newren@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: git push default doesn't make sense
Date: Fri, 28 May 2021 16:12:50 -0500	[thread overview]
Message-ID: <60b15cd2c4136_2183bc20893@natae.notmuch> (raw)
In-Reply-To: 287483ba-d682-6d04-23fa-22c33ab70376@gmail.com

Mathias Kunter wrote:
> However, the advised "git push <name>" command won't work on that branch 
> with the default settings of Git. To make it work, `simple` pushing 
> would have to use `current` behavior on a branch without upstream.
> 
> Please consider changing that. Thank you.

OK, after reorganizing the code to actually make it understandable [1],
I ended up with this:

	if (centralized) {
		if (!branch->merge_nr || !branch->merge || !branch->remote_name)
			die(_("The current branch %s has no upstream branch.\n"
			    "To push the current branch and set the remote as upstream, use\n"
			    "\n"
			    "    git push --set-upstream %s %s\n"),
			    branch->name,
			    remote->name,
			    branch->name);
		if (branch->merge_nr != 1)
			die(_("The current branch %s has multiple upstream branches, "
			    "refusing to push."), branch->name);

		/* Additional safety */
		if (strcmp(branch->refname, branch->merge[0]->src))
			die_push_simple(branch, remote);
	}
	refspec_appendf(&rs, "%s:%s", branch->refname, branch->refname);

I agree this doesn't make sense.

If this works:

  git clone $central .
  ...
  git push

Then this should too:

  git clone $central .
  git checkout -b fix-1
  ...
  git push

Cloning automatically sets up an upstream branch for "master", and
therore it passes the safety check of `push.default=simple`, and that is
much more dangerous than pushing any other branch.

Why do we barf with "fix-1", but not "master"? Doesn't make sense.

This is what we want:

	if (centralized &&
		(branch->merge_nr && branch->merge && branch->remote_name))
	{
		if (branch->merge_nr != 1)
			die(_("The current branch %s has multiple upstream branches, "
			    "refusing to push."), branch->name);

		/* Additional safety */
		if (strcmp(branch->refname, branch->merge[0]->src))
			die_push_simple(branch, remote);
	}
	refspec_appendf(&rs, "%s:%s", branch->refname, branch->refname);


In other words: `simple` should be the same as `current`, except when
there's an upstream branch configured *and* the destination branch has a
different name.

Cheers.

[1] https://lore.kernel.org/git/20210528201014.2175179-1-felipe.contreras@gmail.com/

-- 
Felipe Contreras

  reply	other threads:[~2021-05-28 21:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3b9bc214-a30a-ba49-af96-7eeaf37b7bbd@gmail.com>
2021-05-28  6:29 ` git push doesn't use local branch name as default Mathias Kunter
2021-05-28  7:00   ` Elijah Newren
2021-05-28  7:44     ` Mathias Kunter
2021-05-28  8:51       ` Mathias Kunter
2021-05-28 21:12         ` Felipe Contreras [this message]
2021-05-30 16:28           ` git push default doesn't make sense Mathias Kunter
2021-05-30 16:32             ` Felipe Contreras
2021-05-28 17:52       ` git push doesn't use local branch name as default Felipe Contreras
2021-05-28 17:22     ` Felipe Contreras
2021-05-28 17:44       ` Elijah Newren
2021-05-28 18:58         ` Felipe Contreras
2021-05-28 17:10   ` Felipe Contreras

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=60b15cd2c4136_2183bc20893@natae.notmuch \
    --to=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=mathiaskunter@gmail.com \
    --cc=newren@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.