Thread (12 messages) flat view 12 messages, 3 authors, 2021-05-30

Re: git push default doesn't make sense

From: Felipe Contreras <hidden>
Date: 2021-05-30 16:32:24

Mathias Kunter wrote:
Am 28.05.21 um 23:12 schrieb Felipe Contreras:
quoted
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.
I guess so. In particular, as a simple git user, I'd expect the 
following to work out of the box, without having to manually adjust the 
configuration settings:

   git clone ssh://originUrl .
   git checkout -b myBranch
   git push           # expected push to origin/myBranch, but fails
   git push origin    # expected push to origin/myBranch, but fails
   git remote add myRemote ssh://myRemoteUrl
   git push myRemote  # expected push to myRemote/myBranch - works

Will your provided patch fix these failing push commands?
It's not really a patch (yet), but yeah: it will.

-- 
Felipe Contreras
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help