Skip to content

Commit f296802

Browse files
marcowsgitster
authored andcommitted
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>
1 parent 8104ebf commit f296802

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Documentation/git-cherry.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ git-cherry - Find commits not merged upstream
77

88
SYNOPSIS
99
--------
10-
'git cherry' [-v] <upstream> [<head>] [<limit>]
10+
'git cherry' [-v] [<upstream>] [<head>] [<limit>]
1111

1212
DESCRIPTION
1313
-----------
@@ -51,6 +51,7 @@ OPTIONS
5151

5252
<upstream>::
5353
Upstream branch to compare against.
54+
Defaults to the first tracked remote branch, if available.
5455

5556
<head>::
5657
Working branch; defaults to HEAD.

builtin-log.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "patch-ids.h"
1717
#include "run-command.h"
1818
#include "shortlog.h"
19+
#include "remote.h"
1920

2021
/* Set a default date-time format for git log ("log.date" config variable) */
2122
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)
10701071
}
10711072

10721073
static const char cherry_usage[] =
1073-
"git cherry [-v] <upstream> [<head>] [<limit>]";
1074+
"git cherry [-v] [<upstream>] [<head>] [<limit>]";
10741075
int cmd_cherry(int argc, const char **argv, const char *prefix)
10751076
{
10761077
struct rev_info revs;
10771078
struct patch_ids ids;
10781079
struct commit *commit;
10791080
struct commit_list *list = NULL;
1081+
struct branch *current_branch;
10801082
const char *upstream;
10811083
const char *head = "HEAD";
10821084
const char *limit = NULL;
@@ -1099,7 +1101,17 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
10991101
upstream = argv[1];
11001102
break;
11011103
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;
11031115
}
11041116

11051117
init_revisions(&revs, prefix);

0 commit comments

Comments
 (0)