summaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-11-15 03:14:32 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-11-15 03:14:32 (GMT)
commit093048b22913be23fe45635e8723d3aa3a185ff3 (patch)
tree06a0911c433afb298a50329663c6c1a4fb3a8e8f /remote.c
parent1eb2bd939aa535e9b87f5a13e7bdb5616ce86030 (diff)
parent1b586867dba322c911cc9b4441e2be130ba76cd5 (diff)
downloadgit-093048b22913be23fe45635e8723d3aa3a185ff3.zip
git-093048b22913be23fe45635e8723d3aa3a185ff3.tar.gz
git-093048b22913be23fe45635e8723d3aa3a185ff3.tar.bz2
Merge branch 'js/for-each-ref-remote-name-and-ref'
The "--format=..." option "git for-each-ref" takes learned to show the name of the 'remote' repository and the ref at the remote side that is affected for 'upstream' and 'push' via "%(push:remotename)" and friends. * js/for-each-ref-remote-name-and-ref: for-each-ref: test :remotename and :remoteref for-each-ref: let upstream/push report the remote ref name for-each-ref: let upstream/push optionally report the remote name
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/remote.c b/remote.c
index 685e776..4e93753 100644
--- a/remote.c
+++ b/remote.c
@@ -675,6 +675,36 @@ const char *pushremote_for_branch(struct branch *branch, int *explicit)
return remote_for_branch(branch, explicit);
}
+const char *remote_ref_for_branch(struct branch *branch, int for_push,
+ int *explicit)
+{
+ if (branch) {
+ if (!for_push) {
+ if (branch->merge_nr) {
+ if (explicit)
+ *explicit = 1;
+ return branch->merge_name[0];
+ }
+ } else {
+ const char *dst, *remote_name =
+ pushremote_for_branch(branch, NULL);
+ struct remote *remote = remote_get(remote_name);
+
+ if (remote && remote->push_refspec_nr &&
+ (dst = apply_refspecs(remote->push,
+ remote->push_refspec_nr,
+ branch->refname))) {
+ if (explicit)
+ *explicit = 1;
+ return dst;
+ }
+ }
+ }
+ if (explicit)
+ *explicit = 0;
+ return "";
+}
+
static struct remote *remote_get_1(const char *name,
const char *(*get_default)(struct branch *, int *))
{