Skip to content

Commit 6d5b93f

Browse files
Clemens Buchachergitster
authored andcommitted
cherry-pick: do not expect file arguments
If a commit-ish passed to cherry-pick or revert happens to have a file of the same name, git complains that the argument is ambiguous and advises to use '--'. To make things worse, the '--' argument is removed by parse_options, und so passing '--' has no effect. Instead, always interpret cherry-pick/revert arguments as revisions. Signed-off-by: Clemens Buchacher <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e8dde3e commit 6d5b93f

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

builtin/revert.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,15 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
181181
if (opts->subcommand != REPLAY_NONE) {
182182
opts->revs = NULL;
183183
} else {
184+
struct setup_revision_opt s_r_opt;
184185
opts->revs = xmalloc(sizeof(*opts->revs));
185186
init_revisions(opts->revs, NULL);
186187
opts->revs->no_walk = 1;
187188
if (argc < 2)
188189
usage_with_options(usage_str, options);
189-
argc = setup_revisions(argc, argv, opts->revs, NULL);
190+
memset(&s_r_opt, 0, sizeof(s_r_opt));
191+
s_r_opt.assume_dashdash = 1;
192+
argc = setup_revisions(argc, argv, opts->revs, &s_r_opt);
190193
}
191194

192195
if (argc > 1)

revision.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,17 +1715,21 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
17151715
submodule = opt->submodule;
17161716

17171717
/* First, search for "--" */
1718-
seen_dashdash = 0;
1719-
for (i = 1; i < argc; i++) {
1720-
const char *arg = argv[i];
1721-
if (strcmp(arg, "--"))
1722-
continue;
1723-
argv[i] = NULL;
1724-
argc = i;
1725-
if (argv[i + 1])
1726-
append_prune_data(&prune_data, argv + i + 1);
1718+
if (opt && opt->assume_dashdash) {
17271719
seen_dashdash = 1;
1728-
break;
1720+
} else {
1721+
seen_dashdash = 0;
1722+
for (i = 1; i < argc; i++) {
1723+
const char *arg = argv[i];
1724+
if (strcmp(arg, "--"))
1725+
continue;
1726+
argv[i] = NULL;
1727+
argc = i;
1728+
if (argv[i + 1])
1729+
append_prune_data(&prune_data, argv + i + 1);
1730+
seen_dashdash = 1;
1731+
break;
1732+
}
17291733
}
17301734

17311735
/* Second, deal with arguments and options */

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ struct setup_revision_opt {
183183
const char *def;
184184
void (*tweak)(struct rev_info *, struct setup_revision_opt *);
185185
const char *submodule;
186+
int assume_dashdash;
186187
};
187188

188189
extern void init_revisions(struct rev_info *revs, const char *prefix);

0 commit comments

Comments
 (0)