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

[RFC PATCH v4 0/2] %(push) and %(push:remoteref) bug fixes

From
DRDamien Robert <damien.olivier.robert@gmail.com>
Date
Apr 6, 2020, 17:56 UTC
Message-ID
<20200406175648.25737-1-damien.olivier.robert+git@gmail.com>
In-Reply-To
<20200312164558.2388589-1-damien.olivier.robert+git@gmail.com>

This fix several bugs in for-each-ref for %(push) and %(push:remoteref), as explained in the commit messages.

Note that there are still several bugs:
- the memory leak mentioned by Jeff in
  https://public-inbox.org/git/20200328131553.GA643242@coredump.intra.peff.net/
- in my patch, to detect if the workflow is triangular, I use:
static int is_workflow_triangular(struct branch *branch)
{
	struct remote *fetch_remote = remote_get(remote_for_branch(branch, NULL));
	struct remote *push_remote = remote_get(pushremote_for_branch(branch, NULL));
	return (fetch_remote && push_remote && fetch_remote != push_remote);
}

But remote_get will always fallback to 'origin'. So this means that if we set up a pushRemote="foobar" and no 'remote', the workflow is detected as triangular.

Whereas in `git push`, this workflow will not be detected as triangular.

=> So I can check that by looking at *explicit, but I actually have a question about what constitutes a triangular workflow, hence the RFC.

Furthermore, the upstream (and simple in non triangular workflow) case of %(push) and (push:remoteref) are essentially via `branch_get_upstream`, which is also used for %(upstream):

	branch && branch->merge && branch->merge[0] &&
		    	    branch->merge[0]->dst)
but `git push` does different checks:
	if (!branch->merge_nr || !branch->merge || !branch->remote_name)
		die(_("The current branch %s has no upstream branch.\n"...
	if (branch->merge_nr != 1)
		die(_("The current branch %s has multiple upstream branches, "
		    "refusing to push."), branch->name);

in particular git push fails if merge_nr !=1 or if branch has no remote, whereas %(push) will still indicates a push branch (assuming I fix is_workflow_triangular).

So I'll need to add a `branch_get_push` with these checks instead.

So I first send this patch as an RFC, and I'll see how to proceed afterwards to handle these remaining corner cases. Luckily, having a pushRemote but no remote, or several merge in the branch config are probably not too common.

=> So one question I have first is about the case when we do have a branch.pushRemote but not a branch.remote. Should this still be considered a triangular workflow?

According to git-push, no:
	static int is_workflow_triangular(struct remote *remote)
	{
		struct remote *fetch_remote = remote_get(NULL);
		return (fetch_remote && fetch_remote != remote);
	}
but I would argue that we should.

This would change nothing for push.default=upstream, since currently we check that `branch` has a remote_name in `setup_push_upstream` so it fails anyway even if the workflow is not explicitly triangular, but this would make push.default=simple behave as current, exactly as when branch.remote is different from branch.pushRemote (and I would argue that no branch.remote is a particular case of this situation).

PS: the first patch has no tests because I add them in the second patch, it
is more convenient to add them at once and test both patches.
PPS: v4 and v5 are intermediate versions I made but did not send to the ML.
Damien Robert (2):
  remote.c: fix %(push) for triangular workflows
  remote.c: fix handling of %(push:remoteref)
 remote.c                | 139 ++++++++++++++++++++++++++++++----------
 t/t6300-for-each-ref.sh |  81 +++++++++++++++++++++--
 2 files changed, 180 insertions(+), 40 deletions(-)
-- 
Patched on top of v2.26.0-106-g9fadedd637 (git version 2.26.0)
Next: Damien Robert
Message 1 of 3 in “%(push) and %(push:remoteref) bug fixes”
  1. 0/2 %(push) and %(push:remoteref) bug fixesDamien Robert, Apr 6, 2020
  2. 1/2 remote.c: fix %(push) for triangular workflowsDamien Robert, Apr 6, 2020
  3. 2/2 remote.c: fix handling of %(push:remoteref)Damien Robert, Apr 6, 2020

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.