[PATCH v4 0/2] remote: url-based pushRemote with renamed remotes

"Harald Nordgren via GitGitGadget" <[email protected]>
Newsgroups org.kernel.vger.git
Message-ID <[email protected]>
Fix git status not showing the push branch after remotes are renamed, when
branch.<name>.pushRemote is a URL matching exactly one configured remote.

Changes in v4:

 * Match configured remotes by effective push URL, preferring pushurl over
   url.
 * Update the documentation and rationale to describe where the remote would
   push.

Changes in v3:

 * Revamp commit messages to clarify motivation.

Changes in v2:

 * Clarify that URL push destinations already work and that this change only
   restores their tracking information.
 * Document URL values for branch.<name>.pushRemote and their @{push}
   behavior.

Harald Nordgren (2):
  remote: pass repository to push tracking helper
  remote: find tracking branches for URL push destinations

 Documentation/config/branch.adoc |   1 +
 Documentation/revisions.adoc     |   3 +
 remote.c                         |  54 ++++++++++--
 remote.h                         |   2 +
 t/t5505-remote.sh                | 144 +++++++++++++++++++++++++++++++
 transport.c                      |   5 +-
 6 files changed, 203 insertions(+), 6 deletions(-)


base-commit: 5d2e7709234afea1b6ddb25cd4f60d3d5fb3c200
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2358%2FHaraldNordgren%2Fremote-resolve-url-push-tracking-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2358/HaraldNordgren/remote-resolve-url-push-tracking-v4
Pull-Request: https://github.com/git/git/pull/2358

Range-diff vs v3:

 1:  b1ac49de87 = 1:  494287bade remote: pass repository to push tracking helper
 2:  a343af9d50 ! 2:  08c432a2d4 remote: find tracking branches for URL push destinations
     @@ Commit message
          "git status" cannot show the push branch, and an up-to-date push can
          leave its tracking information stale.
      
     -    When exactly one configured remote uses the push destination URL, use
     -    that remote for push tracking. Continue to push to the URL so the
     -    configured remote's push settings do not change existing behavior. Keep
     -    the current behavior when no remote matches or multiple remotes match.
     +    When exactly one configured remote would push to the same URL, use that
     +    remote for push tracking. Continue to push to the URL so the configured
     +    remote's push settings do not change existing behavior. Keep the current
     +    behavior when no remote matches or multiple remotes match.
      
          Signed-off-by: Harald Nordgren <[email protected]>
      
     @@ Documentation/revisions.adoc: some output processing may assume ref names in UTF
         `git push` were run while `branchname` was checked out (or the current
         `HEAD` if no branchname is specified). Like for '@\{upstream\}', we report
         the remote-tracking branch that corresponds to that branch at the remote.
     -+  If the push destination is a URL and exactly one configured remote has
     -+  that URL among its `remote.<name>.url` values, '@\{push}' reports that
     -+  remote's remote-tracking branch.
     ++  If the push destination is a URL and exactly one configured remote uses
     ++  that URL for pushing, '@\{push}' reports that remote's remote-tracking
     ++  branch.
       +
       Here's an example to make it more clear:
       +
      
       ## remote.c ##
     +@@ remote.c: struct strvec *push_url_of_remote(struct remote *remote)
     + 	return remote->pushurl.nr ? &remote->pushurl : &remote->url;
     + }
     + 
     ++static bool remote_has_push_url(struct remote *remote, const char *url)
     ++{
     ++	const struct strvec *push_urls = push_url_of_remote(remote);
     ++
     ++	for (size_t i = 0; i < push_urls->nr; i++) {
     ++		if (!strcmp(push_urls->v[i], url))
     ++			return true;
     ++	}
     ++	return false;
     ++}
     ++
     + void ref_push_report_free(struct ref_push_report *report)
     + {
     + 	while (report) {
      @@ remote.c: const char *branch_get_upstream(struct branch *branch, struct strbuf *err)
       	return branch->merge[0]->dst;
       }
     @@ remote.c: const char *branch_get_upstream(struct branch *branch, struct strbuf *
      +
      +		if (!candidate || candidate == remote ||
      +		    !remote_is_configured(candidate, 0) ||
     -+		    !remote_has_url(candidate, check_url))
     ++		    !remote_has_push_url(candidate, check_url))
      +			continue;
      +		if (first_match)
      +			return remote;
     @@ t/t5505-remote.sh: test_expect_success 'rename a remote renames repo remote.push
      +	EOF
      +'
      +
     ++test_expect_success 'configured pushurl makes URL-valued pushRemote trackable' '
     ++	setup_url_pushremote &&
     ++
     ++	(
     ++		cd client &&
     ++		git remote rename origin upstream &&
     ++		git remote add -f origin ../fork.git &&
     ++		git remote set-url --push origin "$fork_url"
     ++	) &&
     ++
     ++	check_status <<-EOF
     ++	On branch topic
     ++	Your branch is ahead of ${SQ}upstream/main${SQ} by 1 commit.
     ++
     ++	Your branch is up to date with ${SQ}origin/topic${SQ}.
     ++
     ++	nothing to commit, working tree clean
     ++	EOF
     ++'
     ++
      +test_expect_success 'pushInsteadOf URL pushRemote is trackable' '
      +	setup_url_pushremote &&
      +	(

-- 
gitgitgadget
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.