Skip to content

Commit

Permalink
fixup! builtin rebase: call git am directly
Browse files Browse the repository at this point in the history
This fixes the reflog messages, as expected by t3406 in v2.20.0-rc2, as
well as fixing a compiler warning about "" being an invalid
printf()-style format. Also, while at it, ensure that
.git/rebased-patches is truncated if it already exists.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Dec 4, 2018
1 parent fb6ad24 commit 9688986
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions builtin/rebase.c
Expand Up @@ -253,7 +253,7 @@ static int write_basic_state(struct rebase_options *opts)
write_file(state_dir_path("quiet", opts), "%s", write_file(state_dir_path("quiet", opts), "%s",
opts->flags & REBASE_NO_QUIET ? "" : "t"); opts->flags & REBASE_NO_QUIET ? "" : "t");
if (opts->flags & REBASE_VERBOSE) if (opts->flags & REBASE_VERBOSE)
write_file(state_dir_path("verbose", opts), ""); write_file(state_dir_path("verbose", opts), "%s", "");
if (opts->strategy) if (opts->strategy)
write_file(state_dir_path("strategy", opts), "%s", write_file(state_dir_path("strategy", opts), "%s",
opts->strategy); opts->strategy);
Expand Down Expand Up @@ -481,17 +481,24 @@ static int reset_head(struct object_id *oid, const char *action,


static int move_to_original_branch(struct rebase_options *opts) static int move_to_original_branch(struct rebase_options *opts)
{ {
struct strbuf buf = STRBUF_INIT; struct strbuf orig_head_reflog = STRBUF_INIT, head_reflog = STRBUF_INIT;
int ret; int ret;


if (opts->head_name && opts->onto) if (!opts->head_name)
strbuf_addf(&buf, "rebase finished: %s onto %s", return 0; /* nothing to move back to */
opts->head_name,
oid_to_hex(&opts->onto->object.oid)); if (!opts->onto)
BUG("move_to_original_branch without onto");

strbuf_addf(&orig_head_reflog, "rebase finished: %s onto %s",
opts->head_name, oid_to_hex(&opts->onto->object.oid));
strbuf_addf(&head_reflog, "rebase finished: returning to %s",
opts->head_name);
ret = reset_head(NULL, "checkout", opts->head_name, 0, ret = reset_head(NULL, "checkout", opts->head_name, 0,
"HEAD", buf.buf); orig_head_reflog.buf, head_reflog.buf);


strbuf_release(&buf); strbuf_release(&orig_head_reflog);
strbuf_release(&head_reflog);
return ret; return ret;
} }


Expand Down Expand Up @@ -548,7 +555,8 @@ static int run_am(struct rebase_options *opts)
oid_to_hex(&opts->orig_head)); oid_to_hex(&opts->orig_head));


rebased_patches = xstrdup(git_path("rebased-patches")); rebased_patches = xstrdup(git_path("rebased-patches"));
format_patch.out = open(rebased_patches, O_WRONLY | O_CREAT, 0666); format_patch.out = open(rebased_patches,
O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (format_patch.out < 0) { if (format_patch.out < 0) {
status = error_errno(_("could not write '%s'"), status = error_errno(_("could not write '%s'"),
rebased_patches); rebased_patches);
Expand Down

0 comments on commit 9688986

Please sign in to comment.