@matheusbsbs / matheus-bagliano / commits / f296802211
Fork 0

git-cherry: make <upstream> parameter optional

The upstream branch <upstream> now defaults to the first tracked remote branch, which is set by the configuration variables branch.<name>.remote and branch.<name>.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 <markus.heidelberg@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Markus Heidelberg committed Dec 29, 2008 at 18:45 UTC f29680221124d05581dd2db52a4e7f0fa15fa929
2 files changed +16 -3
Documentation/git-cherry.txt
+2 -1
@@ -7,7 +7,7 @@ git-cherry - Find commits not merged upstream
7
8 SYNOPSIS
9 --------
10 -'git cherry' [-v] <upstream> [<head>] [<limit>]
10 +'git cherry' [-v] [<upstream>] [<head>] [<limit>]
11
12 DESCRIPTION
13 -----------
@@ -51,6 +51,7 @@ OPTIONS
51
52 <upstream>::
53 Upstream branch to compare against.
54 + Defaults to the first tracked remote branch, if available.
55
56 <head>::
57 Working branch; defaults to HEAD.
builtin-log.c
+14 -2
@@ -16,6 +16,7 @@
16 #include "patch-ids.h"
17 #include "run-command.h"
18 #include "shortlog.h"
19 +#include "remote.h"
20
21 /* Set a default date-time format for git log ("log.date" config variable) */
22 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)
1071 }
1072
1073 static const char cherry_usage[] =
1073 -"git cherry [-v] <upstream> [<head>] [<limit>]";
1074 +"git cherry [-v] [<upstream>] [<head>] [<limit>]";
1075 int cmd_cherry(int argc, const char **argv, const char *prefix)
1076 {
1077 struct rev_info revs;
1078 struct patch_ids ids;
1079 struct commit *commit;
1080 struct commit_list *list = NULL;
1081 + struct branch *current_branch;
1082 const char *upstream;
1083 const char *head = "HEAD";
1084 const char *limit = NULL;
@@ -1099,7 +1101,17 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
1101 upstream = argv[1];
1102 break;
1103 default:
1102 - usage(cherry_usage);
1104 + current_branch = branch_get(NULL);
1105 + if (!current_branch || !current_branch->merge
1106 + || !current_branch->merge[0]
1107 + || !current_branch->merge[0]->dst) {
1108 + fprintf(stderr, "Could not find a tracked"
1109 + " remote branch, please"
1110 + " specify <upstream> manually.\n");
1111 + usage(cherry_usage);
1112 + }
1113 +
1114 + upstream = current_branch->merge[0]->dst;
1115 }
1116
1117 init_revisions(&revs, prefix);