#define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
+static void fatal(const char *advice, ...)
+{
+ va_list params;
+
+ va_start(params, advice);
+ vreportf("fatal: ", advice, params);
+ va_end(params);
+}
+
static const char *action_name(const struct replay_opts *opts)
{
return opts->action == REVERT ? "revert" : "cherry-pick";
next = commit_list_append(commit, next);
}
-static void create_seq_dir(void)
+static int create_seq_dir(void)
{
const char *seq_dir = git_path(SEQ_DIR);
- if (!(file_exists(seq_dir) && is_directory(seq_dir))
- && mkdir(seq_dir, 0777) < 0)
+ if (file_exists(seq_dir))
+ return error(_("%s already exists."), seq_dir);
+ else if (mkdir(seq_dir, 0777) < 0)
die_errno(_("Could not create sequencer directory '%s'."), seq_dir);
+ return 0;
}
static void save_head(const char *head)
remove_sequencer_state(1);
return 0;
} else {
- /* Start a new cherry-pick/ revert sequence */
+ /*
+ * Start a new cherry-pick/ revert sequence; but
+ * first, make sure that an existing one isn't in
+ * progress
+ */
+
walk_revs_populate_todo(&todo_list, opts);
- create_seq_dir();
+ if (create_seq_dir() < 0) {
+ fatal(_("A cherry-pick or revert is in progress."));
+ advise(_("Use --reset to forget about it"));
+ exit(128);
+ }
if (get_sha1("HEAD", sha1)) {
if (opts->action == REVERT)
die(_("Can't revert as initial commit"));
test_cmp expect actual
'
+test_expect_success 'cherry-pick does not implicitly stomp an existing operation' '
+ pristine_detach initial &&
+ test_must_fail git cherry-pick base..anotherpick &&
+ test-chmtime -v +0 .git/sequencer >expect &&
+ test_must_fail git cherry-pick unrelatedpick &&
+ test-chmtime -v +0 .git/sequencer >actual &&
+ test_cmp expect actual
+'
+
test_done