From 88c3cbc10522f2ada32985239a256fc0f87515f8 Mon Sep 17 00:00:00 2001 From: J Wyman Date: Thu, 5 Oct 2017 13:00:41 +0200 Subject: [PATCH] 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