From 5dee137de758abca1d12c78749e83201f1aefaf1 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 5 Sep 2017 10:59:32 +0200 Subject: [PATCH 1/3] squash! for-each-ref: mark :remote-name and :remote-ref as experimental for-each-ref: mark :remotename and :remoteref as experimental These expansions will most likely be introduced into Git for Windows as a test balloon first, and if they work out as expected, we'll try to get the patches into upstream Git. Signed-off-by: Johannes Schindelin From 48326c38a040432d90076c0423b58e94c7aa6bb5 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 1 Sep 2017 16:35:17 +0200 Subject: [PATCH 2/3] squash! for-each-ref: let upstream/push optionally report the remote name for-each-ref: let upstream/push optionally report the remote name There are times when e.g. scripts want to know not only the name of the upstream branch on the remote repository, but also the name of the remote. This patch offers the new suffix :remotename for the upstream and for the push atoms, allowing to show exactly that. Example: $ cat .git/config ... [remote "origin"] url = https://where.do.we.come/from fetch = refs/heads/*:refs/remote/origin/* [remote "hello-world"] url = https://hello.world/git fetch = refs/heads/*:refs/remote/origin/* pushURL = hello.world:git push = refs/heads/*:refs/heads/* [branch "master"] remote = origin pushRemote = hello-world ... $ git for-each-ref \ --format='%(upstream) %(upstream:remotename) \ %(push:remotename)' refs/heads/master refs/remotes/origin/master origin hello-world The implementation chooses *not* to DWIM the push remote if no explicit push remote was configured; The reason is that it is possible to DWIM this by using %(if)%(push:remotename)%(then) %(push:remotename) %(else) %(upstream:remotename) %(end) while it would be impossible to "un-DWIM" the information in case the caller is really only interested in explicit push remotes. While `:remote` would be shorter, it would also be a bit more ambiguous, and it would also shut the door e.g. for `:remoteref` (which would obviously refer to the corresponding ref in the remote repository). Note: the dashless, non-CamelCased form `:remotename` follows the example of the `:trackshort` example. Signed-off-by: Johannes Schindelin From 88c3cbc10522f2ada32985239a256fc0f87515f8 Mon Sep 17 00:00:00 2001 From: J Wyman Date: Thu, 5 Oct 2017 13:00:41 +0200 Subject: [PATCH 3/3] squash! for-each-ref: let upstream/push optionally remote ref name for-each-ref: let upstream/push optionally report the remote ref name There are times when scripts want to know not only the name of the push branch on the remote, but also the name of the branch as known by the remote repository. An example of this is when a tool wants to push to the very same branch from which it would pull automatically, i.e. the `` and the `` in `git push :` would be provided by `%(upstream:remotename)` and `%(upstream:remoteref)`, respectively. This patch offers the new suffix :remoteref for the `upstream` and `push` atoms, allowing to show exactly that. Example: $ cat .git/config ... [remote "origin"] url = https://where.do.we.come/from fetch = refs/heads/*:refs/remote/origin/* [branch "master"] remote = origin merge = refs/heads/master [branch "develop/with/topics"] remote = origin merge = refs/heads/develop/with/topics ... $ git for-each-ref \ --format='%(push) %(push:remoteref)' \ refs/heads refs/remotes/origin/master refs/heads/master refs/remotes/origin/develop/with/topics refs/heads/develop/with/topics Signed-off-by: J Wyman Signed-off-by: Johannes Schindelin --- ref-filter.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 2556c7885d..6ab12658cb 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1268,9 +1268,11 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname, else *s = ""; } else if (atom->u.remote_ref.option == RR_REMOTE_REF) { - int explicit, for_push = starts_with(atom->name, "push"); - const char *merge = remote_ref_for_branch(branch, for_push, - &explicit); + int explicit; + const char *merge; + + merge = remote_ref_for_branch(branch, atom->u.remote_ref.push, + &explicit); if (explicit) *s = xstrdup(merge); else