Skip to content

Commit 88c3cbc

Browse files
J Wymandscho
authored andcommitted
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 `<remote>` and the `<to>` in `git push <remote> <from>:<to>` 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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 48326c3 commit 88c3cbc

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

ref-filter.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,9 +1268,11 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname,
12681268
else
12691269
*s = "";
12701270
} else if (atom->u.remote_ref.option == RR_REMOTE_REF) {
1271-
int explicit, for_push = starts_with(atom->name, "push");
1272-
const char *merge = remote_ref_for_branch(branch, for_push,
1273-
&explicit);
1271+
int explicit;
1272+
const char *merge;
1273+
1274+
merge = remote_ref_for_branch(branch, atom->u.remote_ref.push,
1275+
&explicit);
12741276
if (explicit)
12751277
*s = xstrdup(merge);
12761278
else

0 commit comments

Comments
 (0)