char *msg;
size_t msg_len;
+ /* when --rebasing, records the original commit the patch came from */
+ unsigned char orig_commit[GIT_SHA1_RAWSZ];
+
/* number of digits in patch filename */
int prec;
int scissors; /* enum scissors_type */
struct argv_array git_apply_opts;
const char *resolvemsg;
+ int committer_date_is_author_date;
+ int ignore_date;
+ const char *sign_commit;
int rebasing;
};
*/
static void am_state_init(struct am_state *state, const char *dir)
{
+ int gpgsign;
+
memset(state, 0, sizeof(*state));
assert(dir);
state->scissors = SCISSORS_UNSET;
argv_array_init(&state->git_apply_opts);
+
+ if (!git_config_get_bool("commit.gpgsign", &gpgsign))
+ state->sign_commit = gpgsign ? "" : NULL;
}
/**
read_commit_msg(state);
+ if (read_state_file(&sb, state, "original-commit", 1) < 0)
+ hashclr(state->orig_commit);
+ else if (get_sha1_hex(sb.buf, state->orig_commit) < 0)
+ die(_("could not parse %s"), am_path(state, "original-commit"));
+
read_state_file(&sb, state, "threeway", 1);
state->threeway = !strcmp(sb.buf, "t");
strbuf_release(&sb);
}
+/**
+ * Runs post-rewrite hook. Returns it exit code.
+ */
+static int run_post_rewrite_hook(const struct am_state *state)
+{
+ struct child_process cp = CHILD_PROCESS_INIT;
+ const char *hook = find_hook("post-rewrite");
+ int ret;
+
+ if (!hook)
+ return 0;
+
+ argv_array_push(&cp.args, hook);
+ argv_array_push(&cp.args, "rebase");
+
+ cp.in = xopen(am_path(state, "rewritten"), O_RDONLY);
+ cp.stdout_to_stderr = 1;
+
+ ret = run_command(&cp);
+
+ close(cp.in);
+ return ret;
+}
+
/**
* Determines if the file looks like a piece of RFC2822 mail by grabbing all
* non-indented lines and checking if they look like they begin with valid
unlink(am_path(state, "author-script"));
unlink(am_path(state, "final-commit"));
+ hashclr(state->orig_commit);
+ unlink(am_path(state, "original-commit"));
+
if (!get_sha1("HEAD", head))
write_file(am_path(state, "abort-safety"), 1, "%s", sha1_to_hex(head));
else
* directly. This is used in --rebasing mode to bypass git-mailinfo's munging
* of patches.
*
+ * state->orig_commit will be set to the original commit ID.
+ *
* Will always return 0 as the patch should never be skipped.
*/
static int parse_mail_rebase(struct am_state *state, const char *mail)
write_commit_patch(state, commit);
+ hashcpy(state->orig_commit, commit_sha1);
+ write_file(am_path(state, "original-commit"), 1, "%s",
+ sha1_to_hex(commit_sha1));
+
return 0;
}
}
author = fmt_ident(state->author_name, state->author_email,
- state->author_date, IDENT_STRICT);
+ state->ignore_date ? NULL : state->author_date,
+ IDENT_STRICT);
+
+ if (state->committer_date_is_author_date)
+ setenv("GIT_COMMITTER_DATE",
+ state->ignore_date ? "" : state->author_date, 1);
if (commit_tree(state->msg, state->msg_len, tree, parents, commit,
- author, NULL))
+ author, state->sign_commit))
die(_("failed to write commit object"));
reflog_msg = getenv("GIT_REFLOG_ACTION");
update_ref(sb.buf, "HEAD", commit, ptr, 0, UPDATE_REFS_DIE_ON_ERR);
+ if (state->rebasing) {
+ FILE *fp = xfopen(am_path(state, "rewritten"), "a");
+
+ assert(!is_null_sha1(state->orig_commit));
+ fprintf(fp, "%s ", sha1_to_hex(state->orig_commit));
+ fprintf(fp, "%s\n", sha1_to_hex(commit));
+ fclose(fp);
+ }
+
strbuf_release(&sb);
}
am_next(state);
}
+ if (!is_empty_file(am_path(state, "rewritten"))) {
+ assert(state->rebasing);
+ run_post_rewrite_hook(state);
+ }
+
/*
* In rebasing mode, it's up to the caller to take care of
* housekeeping.
OPT_CMDMODE(0, "abort", &resume,
N_("restore the original branch and abort the patching operation."),
RESUME_ABORT),
+ OPT_BOOL(0, "committer-date-is-author-date",
+ &state.committer_date_is_author_date,
+ N_("lie about committer date")),
+ OPT_BOOL(0, "ignore-date", &state.ignore_date,
+ N_("use current timestamp for author date")),
+ { OPTION_STRING, 'S', "gpg-sign", &state.sign_commit, N_("key-id"),
+ N_("GPG-sign commits"),
+ PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
OPT_HIDDEN_BOOL(0, "rebasing", &state.rebasing,
N_("(internal use for git-rebase)")),
OPT_END()