From: Santi Béjar Date: Thu, 18 Jun 2009 07:57:12 GMT Subject: [RFC/PATCH 1/2] remote tracking: return the tracking branch for the given branches Message-ID: <1245311834-5290-2-git-send-email-santi@agolina.net> In-Reply-To: <1245311834-5290-1-git-send-email-santi@agolina.net> Signed-off-by: Santi Béjar --- Documentation/git-remote.txt | 7 +++++++ builtin-remote.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 0 deletions(-) diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt index 9e2b4ea..e444899 100644 --- a/Documentation/git-remote.txt +++ b/Documentation/git-remote.txt @@ -17,6 +17,7 @@ SYNOPSIS 'git remote show' [-n] 'git remote prune' [-n | --dry-run] 'git remote update' [-p | --prune] [group | remote]... +'git remote tracking' ... DESCRIPTION ----------- @@ -128,6 +129,12 @@ be updated. (See linkgit:git-config[1]). + With `--prune` option, prune all the remotes that are updated. +'tracking':: + +Returns the tracking branch for the given remote () and branch +(). Note that must exactly match the left hand side of +the refspec of the given remote. + DISCUSSION ---------- diff --git a/builtin-remote.c b/builtin-remote.c index 709f8a6..bb8e73b 100644 --- a/builtin-remote.c +++ b/builtin-remote.c @@ -16,6 +16,7 @@ static const char * const builtin_remote_usage[] = { "git remote show [-n] ", "git remote prune [-n | --dry-run] ", "git remote [-v | --verbose] update [-p | --prune] [group]", + "git remote tracking ...", NULL }; @@ -665,6 +666,38 @@ static int remove_branches(struct string_list *branches) return result; } +static int tracking(int argc, const char **argv) +{ + struct option options[] = { + OPT_END() + }; + struct remote *remote; + static const char **refs = NULL; + int ref_nr = 0; + int i = 0; + struct refspec *refspec; + + if (argc < 3) + usage_with_options(builtin_remote_usage, options); + remote = remote_get(argv[1]); + if (!remote) + die("No such remote: %s", argv[1]); + refs = xcalloc(argc + 1, sizeof(const char *)); + for (i = 2; i < argc; i++) { + refs[ref_nr++] = argv[i]; + } + refs[ref_nr] = NULL; + memset(&refspec, 0, sizeof(*refspec)); + refspec = parse_fetch_refspec(ref_nr, refs); + for (i = 0; i < ref_nr ; i++) { + if (!remote_find_tracking(remote, &refspec[i])) + printf("%s\n", refspec[i].dst); + else + return 1; + } + return 0; +} + static int rm(int argc, const char **argv) { struct option options[] = { @@ -1348,6 +1381,8 @@ int cmd_remote(int argc, const char **argv, const char *prefix) result = show_all(); else if (!strcmp(argv[0], "add")) result = add(argc, argv); + else if (!strcmp(argv[0], "tracking")) + result = tracking(argc, argv); else if (!strcmp(argv[0], "rename")) result = mv(argc, argv); else if (!strcmp(argv[0], "rm")) -- 1.6.3.2.406.gd6a466