From f29680221124d05581dd2db52a4e7f0fa15fa929 Mon Sep 17 00:00:00 2001 From: Markus Heidelberg Date: Mon, 29 Dec 2008 18:45:20 +0100 Subject: [PATCH 1/2] git-cherry: make parameter optional The upstream branch now defaults to the first tracked remote branch, which is set by the configuration variables branch..remote and branch..merge of the current branch. Without such a remote branch, the command "git cherry [-v]" fails with usage output as before and an additional message. Signed-off-by: Markus Heidelberg Signed-off-by: Junio C Hamano --- Documentation/git-cherry.txt | 3 ++- builtin-log.c | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Documentation/git-cherry.txt b/Documentation/git-cherry.txt index 74d14c4e7f..556ea23cd9 100644 --- a/Documentation/git-cherry.txt +++ b/Documentation/git-cherry.txt @@ -7,7 +7,7 @@ git-cherry - Find commits not merged upstream SYNOPSIS -------- -'git cherry' [-v] [] [] +'git cherry' [-v] [] [] [] DESCRIPTION ----------- @@ -51,6 +51,7 @@ OPTIONS :: Upstream branch to compare against. + Defaults to the first tracked remote branch, if available. :: Working branch; defaults to HEAD. diff --git a/builtin-log.c b/builtin-log.c index 99d1137b08..243f8573e4 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -16,6 +16,7 @@ #include "patch-ids.h" #include "run-command.h" #include "shortlog.h" +#include "remote.h" /* Set a default date-time format for git log ("log.date" config variable) */ static const char *default_date_mode = NULL; @@ -1070,13 +1071,14 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags) } static const char cherry_usage[] = -"git cherry [-v] [] []"; +"git cherry [-v] [] [] []"; int cmd_cherry(int argc, const char **argv, const char *prefix) { struct rev_info revs; struct patch_ids ids; struct commit *commit; struct commit_list *list = NULL; + struct branch *current_branch; const char *upstream; const char *head = "HEAD"; const char *limit = NULL; @@ -1099,7 +1101,17 @@ int cmd_cherry(int argc, const char **argv, const char *prefix) upstream = argv[1]; break; default: - usage(cherry_usage); + current_branch = branch_get(NULL); + if (!current_branch || !current_branch->merge + || !current_branch->merge[0] + || !current_branch->merge[0]->dst) { + fprintf(stderr, "Could not find a tracked" + " remote branch, please" + " specify manually.\n"); + usage(cherry_usage); + } + + upstream = current_branch->merge[0]->dst; } init_revisions(&revs, prefix); From 3bc52d7a95676bcdeeb61c372b44358daf817baa Mon Sep 17 00:00:00 2001 From: Markus Heidelberg Date: Thu, 1 Jan 2009 22:56:29 +0100 Subject: [PATCH 2/2] Documentation: clarify which parameters are optional to git-cherry An earlier parameter is only optional when all of the later parameters are omitted. Signed-off-by: Junio C Hamano --- Documentation/git-cherry.txt | 2 +- builtin-log.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/git-cherry.txt b/Documentation/git-cherry.txt index 556ea23cd9..7deefdae8f 100644 --- a/Documentation/git-cherry.txt +++ b/Documentation/git-cherry.txt @@ -7,7 +7,7 @@ git-cherry - Find commits not merged upstream SYNOPSIS -------- -'git cherry' [-v] [] [] [] +'git cherry' [-v] [ [ []]] DESCRIPTION ----------- diff --git a/builtin-log.c b/builtin-log.c index 243f8573e4..7e9616e5e7 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -1071,7 +1071,7 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags) } static const char cherry_usage[] = -"git cherry [-v] [] [] []"; +"git cherry [-v] [ [ []]]"; int cmd_cherry(int argc, const char **argv, const char *prefix) { struct rev_info revs;