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 <jrnieder@gmail.com> Helped-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ramkumar Ramachandra committed
Aug 4, 2011 at 16:09 UTC
6f0322633b2659d26d1c7b20d4af1fba33978690
2 files changed
+60
-2
builtin/revert.c
+33
@@ -64,6 +64,7 @@ struct replay_opts {
64
#define SEQ_DIR "sequencer"
65
#define SEQ_HEAD_FILE "sequencer/head"
66
#define SEQ_TODO_FILE "sequencer/todo"
67
+#define SEQ_OPTS_FILE "sequencer/opts"
68
69
static const char *action_name(const struct replay_opts *opts)
70
{
@@ -695,6 +696,37 @@ static void save_todo(struct commit_list *todo_list, struct replay_opts *opts)
696
strbuf_release(&buf);
697
}
698
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
+
730
static int pick_commits(struct replay_opts *opts)
731
{
732
struct commit_list *todo_list = NULL;
@@ -717,6 +749,7 @@ static int pick_commits(struct replay_opts *opts)
749
die(_("Can't cherry-pick into empty head"));
750
}
751
save_head(sha1_to_hex(sha1));
752
+ save_opts(opts);
753
754
for (cur = todo_list; cur; cur = cur->next) {
755
save_todo(cur, opts);
t/t3510-cherry-pick-sequence.sh
+27
-2
@@ -33,10 +33,35 @@ test_expect_success setup '
33
34
test_expect_success 'cherry-pick persists data on failure' '
35
pristine_detach initial &&
36
- test_must_fail git cherry-pick base..anotherpick &&
36
+ test_must_fail git cherry-pick -s base..anotherpick &&
37
test_path_is_dir .git/sequencer &&
38
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
65
'
66
67
test_expect_success 'cherry-pick cleans up sequencer state upon success' '