Skip to content

Commit 1bc505b

Browse files
committed
Merge branch 'es/rebase-i-author-script-fix'
The "author-script" file "git rebase -i" creates got broken when we started to move the command away from shell script, which is getting fixed now. * es/rebase-i-author-script-fix: sequencer: don't die() on bogus user-edited timestamp sequencer: fix "rebase -i --root" corrupting author header timestamp sequencer: fix "rebase -i --root" corrupting author header timezone sequencer: fix "rebase -i --root" corrupting author header
2 parents f8ca718 + 5522bba commit 1bc505b

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

sequencer.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ static int write_author_script(const char *message)
654654
strbuf_addch(&buf, *(message++));
655655
else
656656
strbuf_addf(&buf, "'\\\\%c'", *(message++));
657+
strbuf_addch(&buf, '\'');
657658
res = write_message(buf.buf, buf.len, rebase_path_author_script(), 1);
658659
strbuf_release(&buf);
659660
return res;
@@ -708,14 +709,16 @@ static const char *read_author_ident(struct strbuf *buf)
708709
const char *keys[] = {
709710
"GIT_AUTHOR_NAME=", "GIT_AUTHOR_EMAIL=", "GIT_AUTHOR_DATE="
710711
};
711-
char *in, *out, *eol;
712-
int i = 0, len;
712+
struct strbuf out = STRBUF_INIT;
713+
char *in, *eol;
714+
const char *val[3];
715+
int i = 0;
713716

714717
if (strbuf_read_file(buf, rebase_path_author_script(), 256) <= 0)
715718
return NULL;
716719

717720
/* dequote values and construct ident line in-place */
718-
for (in = out = buf->buf; i < 3 && in - buf->buf < buf->len; i++) {
721+
for (in = buf->buf; i < 3 && in - buf->buf < buf->len; i++) {
719722
if (!skip_prefix(in, keys[i], (const char **)&in)) {
720723
warning(_("could not parse '%s' (looking for '%s'"),
721724
rebase_path_author_script(), keys[i]);
@@ -724,17 +727,12 @@ static const char *read_author_ident(struct strbuf *buf)
724727

725728
eol = strchrnul(in, '\n');
726729
*eol = '\0';
727-
sq_dequote(in);
728-
len = strlen(in);
729-
730-
if (i > 0) /* separate values by spaces */
731-
*(out++) = ' ';
732-
if (i == 1) /* email needs to be surrounded by <...> */
733-
*(out++) = '<';
734-
memmove(out, in, len);
735-
out += len;
736-
if (i == 1) /* email needs to be surrounded by <...> */
737-
*(out++) = '>';
730+
if (!sq_dequote(in)) {
731+
warning(_("bad quoting on %s value in '%s'"),
732+
keys[i], rebase_path_author_script());
733+
return NULL;
734+
}
735+
val[i] = in;
738736
in = eol + 1;
739737
}
740738

@@ -744,7 +742,18 @@ static const char *read_author_ident(struct strbuf *buf)
744742
return NULL;
745743
}
746744

747-
buf->len = out - buf->buf;
745+
/* validate date since fmt_ident() will die() on bad value */
746+
if (parse_date(val[2], &out)){
747+
warning(_("invalid date format '%s' in '%s'"),
748+
val[2], rebase_path_author_script());
749+
strbuf_release(&out);
750+
return NULL;
751+
}
752+
753+
strbuf_reset(&out);
754+
strbuf_addstr(&out, fmt_ident(val[0], val[1], val[2], 0));
755+
strbuf_swap(buf, &out);
756+
strbuf_release(&out);
748757
return buf->buf;
749758
}
750759

t/t3404-rebase-interactive.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ rebase_setup_and_clean () {
12471247
test_might_fail git branch -D $1 &&
12481248
test_might_fail git rebase --abort
12491249
" &&
1250-
git checkout -b $1 master
1250+
git checkout -b $1 ${2:-master}
12511251
}
12521252

12531253
test_expect_success 'drop' '
@@ -1424,4 +1424,12 @@ test_expect_success 'rebase -i --gpg-sign=<key-id> overrides commit.gpgSign' '
14241424
test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
14251425
'
14261426

1427+
test_expect_success 'valid author header after --root swap' '
1428+
rebase_setup_and_clean author-header no-conflict-branch &&
1429+
set_fake_editor &&
1430+
FAKE_LINES="2 1" git rebase -i --root &&
1431+
git cat-file commit HEAD^ >out &&
1432+
grep "^author ..*> [0-9][0-9]* [-+][0-9][0-9][0-9][0-9]$" out
1433+
'
1434+
14271435
test_done

0 commit comments

Comments
 (0)