Skip to content

Commit 6f03226

Browse files
artagnongitster
authored andcommitted
revert: Save command-line options for continuing operation
In the same spirit as ".git/sequencer/head" and ".git/sequencer/todo", introduce ".git/sequencer/opts" to persist the replay_opts structure for continuing after a conflict resolution. Use the gitconfig format for this file so that it looks like: [options] signoff = true record-origin = true mainline = 1 strategy = recursive strategy-option = patience strategy-option = ours Helped-by: Jonathan Nieder <[email protected]> Helped-by: Christian Couder <[email protected]> Signed-off-by: Ramkumar Ramachandra <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 04d3d3c commit 6f03226

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

builtin/revert.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct replay_opts {
6464
#define SEQ_DIR "sequencer"
6565
#define SEQ_HEAD_FILE "sequencer/head"
6666
#define SEQ_TODO_FILE "sequencer/todo"
67+
#define SEQ_OPTS_FILE "sequencer/opts"
6768

6869
static const char *action_name(const struct replay_opts *opts)
6970
{
@@ -695,6 +696,37 @@ static void save_todo(struct commit_list *todo_list, struct replay_opts *opts)
695696
strbuf_release(&buf);
696697
}
697698

699+
static void save_opts(struct replay_opts *opts)
700+
{
701+
const char *opts_file = git_path(SEQ_OPTS_FILE);
702+
703+
if (opts->no_commit)
704+
git_config_set_in_file(opts_file, "options.no-commit", "true");
705+
if (opts->edit)
706+
git_config_set_in_file(opts_file, "options.edit", "true");
707+
if (opts->signoff)
708+
git_config_set_in_file(opts_file, "options.signoff", "true");
709+
if (opts->record_origin)
710+
git_config_set_in_file(opts_file, "options.record-origin", "true");
711+
if (opts->allow_ff)
712+
git_config_set_in_file(opts_file, "options.allow-ff", "true");
713+
if (opts->mainline) {
714+
struct strbuf buf = STRBUF_INIT;
715+
strbuf_addf(&buf, "%d", opts->mainline);
716+
git_config_set_in_file(opts_file, "options.mainline", buf.buf);
717+
strbuf_release(&buf);
718+
}
719+
if (opts->strategy)
720+
git_config_set_in_file(opts_file, "options.strategy", opts->strategy);
721+
if (opts->xopts) {
722+
int i;
723+
for (i = 0; i < opts->xopts_nr; i++)
724+
git_config_set_multivar_in_file(opts_file,
725+
"options.strategy-option",
726+
opts->xopts[i], "^$", 0);
727+
}
728+
}
729+
698730
static int pick_commits(struct replay_opts *opts)
699731
{
700732
struct commit_list *todo_list = NULL;
@@ -717,6 +749,7 @@ static int pick_commits(struct replay_opts *opts)
717749
die(_("Can't cherry-pick into empty head"));
718750
}
719751
save_head(sha1_to_hex(sha1));
752+
save_opts(opts);
720753

721754
for (cur = todo_list; cur; cur = cur->next) {
722755
save_todo(cur, opts);

t/t3510-cherry-pick-sequence.sh

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,35 @@ test_expect_success setup '
3333

3434
test_expect_success 'cherry-pick persists data on failure' '
3535
pristine_detach initial &&
36-
test_must_fail git cherry-pick base..anotherpick &&
36+
test_must_fail git cherry-pick -s base..anotherpick &&
3737
test_path_is_dir .git/sequencer &&
3838
test_path_is_file .git/sequencer/head &&
39-
test_path_is_file .git/sequencer/todo
39+
test_path_is_file .git/sequencer/todo &&
40+
test_path_is_file .git/sequencer/opts
41+
'
42+
43+
test_expect_success 'cherry-pick persists opts correctly' '
44+
pristine_detach initial &&
45+
test_must_fail git cherry-pick -s -m 1 --strategy=recursive -X patience -X ours base..anotherpick &&
46+
test_path_is_dir .git/sequencer &&
47+
test_path_is_file .git/sequencer/head &&
48+
test_path_is_file .git/sequencer/todo &&
49+
test_path_is_file .git/sequencer/opts &&
50+
echo "true" >expect &&
51+
git config --file=.git/sequencer/opts --get-all options.signoff >actual &&
52+
test_cmp expect actual &&
53+
echo "1" >expect &&
54+
git config --file=.git/sequencer/opts --get-all options.mainline >actual &&
55+
test_cmp expect actual &&
56+
echo "recursive" >expect &&
57+
git config --file=.git/sequencer/opts --get-all options.strategy >actual &&
58+
test_cmp expect actual &&
59+
cat >expect <<-\EOF &&
60+
patience
61+
ours
62+
EOF
63+
git config --file=.git/sequencer/opts --get-all options.strategy-option >actual &&
64+
test_cmp expect actual
4065
'
4166

4267
test_expect_success 'cherry-pick cleans up sequencer state upon success' '

0 commit comments

Comments
 (0)