debian: new upstream point release
[git/debian.git] / debian / patches / 0001-sequencer-honor-GIT_REFLOG_ACTION.diff
blob9fcc19e6d7991d893f7fdefb5421ac79df779c62
1 From 0329acb1aa4444da4ee1007674c469c2e63dcf48 Mon Sep 17 00:00:00 2001
2 From: Elijah Newren <newren@gmail.com>
3 Date: Tue, 7 Apr 2020 16:59:23 +0000
4 Subject: sequencer: honor GIT_REFLOG_ACTION
6 commit 1f6965f994f8fe2fca80e17b5dbb293d05716be9 upstream.
8 There is a lot of code to honor GIT_REFLOG_ACTION throughout git,
9 including some in sequencer.c; unfortunately, reflog_message() and its
10 callers ignored it. Instruct reflog_message() to check the existing
11 environment variable, and use it when present as an override to
12 action_name().
14 Also restructure pick_commits() to only temporarily modify
15 GIT_REFLOG_ACTION for a short duration and then restore the old value,
16 so that when we do this setting within a loop we do not keep adding "
17 (pick)" substrings and end up with a reflog message of the form
18 rebase (pick) (pick) (pick) (finish): returning to refs/heads/master
20 Signed-off-by: Elijah Newren <newren@gmail.com>
21 Signed-off-by: Junio C Hamano <gitster@pobox.com>
22 Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
23 ---
24 sequencer.c | 10 ++++++++--
25 t/t3406-rebase-message.sh | 16 ++++++++--------
26 2 files changed, 16 insertions(+), 10 deletions(-)
28 diff --git a/sequencer.c b/sequencer.c
29 index e528225e787..24a62d5aa5d 100644
30 --- a/sequencer.c
31 +++ b/sequencer.c
32 @@ -3708,10 +3708,11 @@ static const char *reflog_message(struct replay_opts *opts,
34 va_list ap;
35 static struct strbuf buf = STRBUF_INIT;
36 + char *reflog_action = getenv(GIT_REFLOG_ACTION);
38 va_start(ap, fmt);
39 strbuf_reset(&buf);
40 - strbuf_addstr(&buf, action_name(opts));
41 + strbuf_addstr(&buf, reflog_action ? reflog_action : action_name(opts));
42 if (sub_action)
43 strbuf_addf(&buf, " (%s)", sub_action);
44 if (fmt) {
45 @@ -3799,8 +3800,11 @@ static int pick_commits(struct repository *r,
46 struct replay_opts *opts)
48 int res = 0, reschedule = 0;
49 + char *prev_reflog_action;
51 + /* Note that 0 for 3rd parameter of setenv means set only if not set */
52 setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
53 + prev_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
54 if (opts->allow_ff)
55 assert(!(opts->signoff || opts->no_commit ||
56 opts->record_origin || opts->edit));
57 @@ -3845,12 +3849,14 @@ static int pick_commits(struct repository *r,
59 if (item->command <= TODO_SQUASH) {
60 if (is_rebase_i(opts))
61 - setenv("GIT_REFLOG_ACTION", reflog_message(opts,
62 + setenv(GIT_REFLOG_ACTION, reflog_message(opts,
63 command_to_string(item->command), NULL),
64 1);
65 res = do_pick_commit(r, item->command, item->commit,
66 opts, is_final_fixup(todo_list),
67 &check_todo);
68 + if (is_rebase_i(opts))
69 + setenv(GIT_REFLOG_ACTION, prev_reflog_action, 1);
70 if (is_rebase_i(opts) && res < 0) {
71 /* Reschedule */
72 advise(_(rescheduled_advice),
73 diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh
74 index 61b76f33019..927a4f4a4e4 100755
75 --- a/t/t3406-rebase-message.sh
76 +++ b/t/t3406-rebase-message.sh
77 @@ -89,22 +89,22 @@ test_expect_success 'GIT_REFLOG_ACTION' '
78 git checkout -b reflog-topic start &&
79 test_commit reflog-to-rebase &&
81 - git rebase --apply reflog-onto &&
82 + git rebase reflog-onto &&
83 git log -g --format=%gs -3 >actual &&
84 cat >expect <<-\EOF &&
85 - rebase finished: returning to refs/heads/reflog-topic
86 - rebase: reflog-to-rebase
87 - rebase: checkout reflog-onto
88 + rebase (finish): returning to refs/heads/reflog-topic
89 + rebase (pick): reflog-to-rebase
90 + rebase (start): checkout reflog-onto
91 EOF
92 test_cmp expect actual &&
94 git checkout -b reflog-prefix reflog-to-rebase &&
95 - GIT_REFLOG_ACTION=change-the-reflog git rebase --apply reflog-onto &&
96 + GIT_REFLOG_ACTION=change-the-reflog git rebase reflog-onto &&
97 git log -g --format=%gs -3 >actual &&
98 cat >expect <<-\EOF &&
99 - rebase finished: returning to refs/heads/reflog-prefix
100 - change-the-reflog: reflog-to-rebase
101 - change-the-reflog: checkout reflog-onto
102 + change-the-reflog (finish): returning to refs/heads/reflog-prefix
103 + change-the-reflog (pick): reflog-to-rebase
104 + change-the-reflog (start): checkout reflog-onto
106 test_cmp expect actual
109 2.26.0.110.g2183baf09c