Skip to content

Commit 4611884

Browse files
derrickstoleegitster
authored andcommitted
sequencer: notify user of --update-refs activity
When the user runs 'git rebase -i --update-refs', the end message still says only Successfully rebased and updated <HEAD-ref>. Update the sequencer to collect the successful (and unsuccessful) ref updates due to the --update-refs option, so the end message now says Successfully rebased and updated <HEAD-ref>. Updated the following refs with --update-refs: refs/heads/first refs/heads/third Failed to update the following refs with --update-refs: refs/heads/second To test this output, we need to be very careful to format the expected error to drop the leading tab characters. Also, we need to be aware that the verbose output from 'git rebase' is writing progress lines which don't use traditional newlines but clear the line after every progress item is complete. When opening the error file in an editor, these lines are visible, but when looking at the diff in a terminal those lines disappear because of the characters that delete the previous characters. Use 'sed' to clear those progress lines and clear the tabs so we can get an exact match on our expected output. Reported-by: Elijah Newren <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aa37f3e commit 4611884

File tree

2 files changed

+67
-10
lines changed

2 files changed

+67
-10
lines changed

sequencer.c

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4286,26 +4286,54 @@ static int do_update_ref(struct repository *r, const char *refname)
42864286
return 0;
42874287
}
42884288

4289-
static int do_update_refs(struct repository *r)
4289+
static int do_update_refs(struct repository *r, int quiet)
42904290
{
42914291
int res = 0;
42924292
struct string_list_item *item;
42934293
struct string_list refs_to_oids = STRING_LIST_INIT_DUP;
42944294
struct ref_store *refs = get_main_ref_store(r);
4295+
struct strbuf update_msg = STRBUF_INIT;
4296+
struct strbuf error_msg = STRBUF_INIT;
42954297

42964298
if ((res = sequencer_get_update_refs_state(r->gitdir, &refs_to_oids)))
42974299
return res;
42984300

42994301
for_each_string_list_item(item, &refs_to_oids) {
43004302
struct update_ref_record *rec = item->util;
4303+
int loop_res;
43014304

4302-
res |= refs_update_ref(refs, "rewritten during rebase",
4303-
item->string,
4304-
&rec->after, &rec->before,
4305-
0, UPDATE_REFS_MSG_ON_ERR);
4305+
loop_res = refs_update_ref(refs, "rewritten during rebase",
4306+
item->string,
4307+
&rec->after, &rec->before,
4308+
0, UPDATE_REFS_MSG_ON_ERR);
4309+
res |= loop_res;
4310+
4311+
if (quiet)
4312+
continue;
4313+
4314+
if (loop_res)
4315+
strbuf_addf(&error_msg, "\t%s\n", item->string);
4316+
else
4317+
strbuf_addf(&update_msg, "\t%s\n", item->string);
4318+
}
4319+
4320+
if (!quiet &&
4321+
(update_msg.len || error_msg.len)) {
4322+
fprintf(stderr,
4323+
_("Updated the following refs with %s:\n%s"),
4324+
"--update-refs",
4325+
update_msg.buf);
4326+
4327+
if (res)
4328+
fprintf(stderr,
4329+
_("Failed to update the following refs with %s:\n%s"),
4330+
"--update-refs",
4331+
error_msg.buf);
43064332
}
43074333

43084334
string_list_clear(&refs_to_oids, 1);
4335+
strbuf_release(&update_msg);
4336+
strbuf_release(&error_msg);
43094337
return res;
43104338
}
43114339

@@ -4826,7 +4854,7 @@ static int pick_commits(struct repository *r,
48264854
strbuf_release(&buf);
48274855
strbuf_release(&head_ref);
48284856

4829-
if (do_update_refs(r))
4857+
if (do_update_refs(r, opts->quiet))
48304858
return -1;
48314859
}
48324860

t/t3404-rebase-interactive.sh

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,12 +1840,26 @@ test_expect_success '--update-refs updates refs correctly' '
18401840
test_commit extra2 fileX &&
18411841
git commit --amend --fixup=L &&
18421842
1843-
git rebase -i --autosquash --update-refs primary &&
1843+
git rebase -i --autosquash --update-refs primary 2>err &&
18441844
18451845
test_cmp_rev HEAD~3 refs/heads/first &&
18461846
test_cmp_rev HEAD~3 refs/heads/second &&
18471847
test_cmp_rev HEAD~1 refs/heads/third &&
1848-
test_cmp_rev HEAD refs/heads/no-conflict-branch
1848+
test_cmp_rev HEAD refs/heads/no-conflict-branch &&
1849+
1850+
cat >expect <<-\EOF &&
1851+
Successfully rebased and updated refs/heads/update-refs.
1852+
Updated the following refs with --update-refs:
1853+
refs/heads/first
1854+
refs/heads/no-conflict-branch
1855+
refs/heads/second
1856+
refs/heads/third
1857+
EOF
1858+
1859+
# Clear "Rebasing (X/Y)" progress lines and drop leading tabs.
1860+
sed -e "s/Rebasing.*Successfully/Successfully/g" -e "s/^\t//g" \
1861+
<err >err.trimmed &&
1862+
test_cmp expect err.trimmed
18491863
'
18501864

18511865
test_expect_success 'respect user edits to update-ref steps' '
@@ -1983,8 +1997,23 @@ test_expect_success '--update-refs: check failed ref update' '
19831997
# the lock in the update-refs file.
19841998
git rev-parse third >.git/refs/heads/second &&
19851999
1986-
git rebase --continue 2>err &&
1987-
grep "update_ref failed for ref '\''refs/heads/second'\''" err
2000+
test_must_fail git rebase --continue 2>err &&
2001+
grep "update_ref failed for ref '\''refs/heads/second'\''" err &&
2002+
2003+
cat >expect <<-\EOF &&
2004+
Updated the following refs with --update-refs:
2005+
refs/heads/first
2006+
refs/heads/no-conflict-branch
2007+
refs/heads/third
2008+
Failed to update the following refs with --update-refs:
2009+
refs/heads/second
2010+
EOF
2011+
2012+
# Clear "Rebasing (X/Y)" progress lines and drop leading tabs.
2013+
tail -n 6 err >err.last &&
2014+
sed -e "s/Rebasing.*Successfully/Successfully/g" -e "s/^\t//g" \
2015+
<err.last >err.trimmed &&
2016+
test_cmp expect err.trimmed
19882017
'
19892018

19902019
# This must be the last test in this file

0 commit comments

Comments
 (0)