sequencer: fix "rebase -i --root" corrupting author header timezone
[gitweb.git] / sequencer.c
index cca968043ea86c4515e6af1b4fe9251a0140c0a3..2b66b85373a46bfaf6a3b0b5bc1af145b4fa98b8 100644 (file)
@@ -651,6 +651,7 @@ static int write_author_script(const char *message)
                        strbuf_addch(&buf, *(message++));
                else
                        strbuf_addf(&buf, "'\\\\%c'", *(message++));
+       strbuf_addch(&buf, '\'');
        res = write_message(buf.buf, buf.len, rebase_path_author_script(), 1);
        strbuf_release(&buf);
        return res;
@@ -721,7 +722,11 @@ static const char *read_author_ident(struct strbuf *buf)
 
                eol = strchrnul(in, '\n');
                *eol = '\0';
-               sq_dequote(in);
+               if (!sq_dequote(in)) {
+                       warning(_("bad quoting on %s value in '%s'"),
+                               keys[i], rebase_path_author_script());
+                       return NULL;
+               }
                len = strlen(in);
 
                if (i > 0) /* separate values by spaces */
@@ -741,7 +746,7 @@ static const char *read_author_ident(struct strbuf *buf)
                return NULL;
        }
 
-       buf->len = out - buf->buf;
+       strbuf_setlen(buf, out - buf->buf);
        return buf->buf;
 }
 
@@ -784,7 +789,7 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
        struct child_process cmd = CHILD_PROCESS_INIT;
        const char *value;
 
-       if (flags & CREATE_ROOT_COMMIT) {
+       if ((flags & CREATE_ROOT_COMMIT) && !(flags & AMEND_MSG)) {
                struct strbuf msg = STRBUF_INIT, script = STRBUF_INIT;
                const char *author = is_rebase_i(opts) ?
                        read_author_ident(&script) : NULL;