зеркало из https://github.com/microsoft/git.git
Merge branch 'pw/rebase-i-more-options'
"git rebase -i" learns a bit more options. * pw/rebase-i-more-options: t3436: do not run git-merge-recursive in dashed form rebase: add --reset-author-date rebase -i: support --ignore-date rebase -i: support --committer-date-is-author-date am: stop exporting GIT_COMMITTER_DATE rebase -i: add --ignore-whitespace flag
This commit is contained in:
Коммит
9c31b19dd0
|
@ -459,17 +459,38 @@ with `--keep-base` in order to drop those commits from your branch.
|
|||
See also INCOMPATIBLE OPTIONS below.
|
||||
|
||||
--ignore-whitespace::
|
||||
Ignore whitespace differences when trying to reconcile
|
||||
differences. Currently, each backend implements an approximation of
|
||||
this behavior:
|
||||
+
|
||||
apply backend: When applying a patch, ignore changes in whitespace in
|
||||
context lines. Unfortunately, this means that if the "old" lines being
|
||||
replaced by the patch differ only in whitespace from the existing
|
||||
file, you will get a merge conflict instead of a successful patch
|
||||
application.
|
||||
+
|
||||
merge backend: Treat lines with only whitespace changes as unchanged
|
||||
when merging. Unfortunately, this means that any patch hunks that were
|
||||
intended to modify whitespace and nothing else will be dropped, even
|
||||
if the other side had no changes that conflicted.
|
||||
|
||||
--whitespace=<option>::
|
||||
These flags are passed to the 'git apply' program
|
||||
This flag is passed to the 'git apply' program
|
||||
(see linkgit:git-apply[1]) that applies the patch.
|
||||
Implies --apply.
|
||||
+
|
||||
See also INCOMPATIBLE OPTIONS below.
|
||||
|
||||
--committer-date-is-author-date::
|
||||
Instead of using the current time as the committer date, use
|
||||
the author date of the commit being rebased as the committer
|
||||
date. This option implies `--force-rebase`.
|
||||
|
||||
--ignore-date::
|
||||
These flags are passed to 'git am' to easily change the dates
|
||||
of the rebased commits (see linkgit:git-am[1]).
|
||||
--reset-author-date::
|
||||
Instead of using the author date of the original commit, use
|
||||
the current time as the author date of the rebased commit. This
|
||||
option implies `--force-rebase`.
|
||||
+
|
||||
See also INCOMPATIBLE OPTIONS below.
|
||||
|
||||
|
@ -607,9 +628,6 @@ INCOMPATIBLE OPTIONS
|
|||
The following options:
|
||||
|
||||
* --apply
|
||||
* --committer-date-is-author-date
|
||||
* --ignore-date
|
||||
* --ignore-whitespace
|
||||
* --whitespace
|
||||
* -C
|
||||
|
||||
|
@ -636,6 +654,9 @@ In addition, the following pairs of options are incompatible:
|
|||
* --preserve-merges and --signoff
|
||||
* --preserve-merges and --rebase-merges
|
||||
* --preserve-merges and --empty=
|
||||
* --preserve-merges and --ignore-whitespace
|
||||
* --preserve-merges and --committer-date-is-author-date
|
||||
* --preserve-merges and --ignore-date
|
||||
* --keep-base and --onto
|
||||
* --keep-base and --root
|
||||
* --fork-point and --root
|
||||
|
|
28
builtin/am.c
28
builtin/am.c
|
@ -98,6 +98,8 @@ struct am_state {
|
|||
char *author_name;
|
||||
char *author_email;
|
||||
char *author_date;
|
||||
char *committer_name;
|
||||
char *committer_email;
|
||||
char *msg;
|
||||
size_t msg_len;
|
||||
|
||||
|
@ -130,6 +132,8 @@ struct am_state {
|
|||
*/
|
||||
static void am_state_init(struct am_state *state)
|
||||
{
|
||||
const char *committer;
|
||||
struct ident_split id;
|
||||
int gpgsign;
|
||||
|
||||
memset(state, 0, sizeof(*state));
|
||||
|
@ -150,6 +154,14 @@ static void am_state_init(struct am_state *state)
|
|||
|
||||
if (!git_config_get_bool("commit.gpgsign", &gpgsign))
|
||||
state->sign_commit = gpgsign ? "" : NULL;
|
||||
|
||||
committer = git_committer_info(IDENT_STRICT);
|
||||
if (split_ident_line(&id, committer, strlen(committer)) < 0)
|
||||
die(_("invalid committer: %s"), committer);
|
||||
state->committer_name =
|
||||
xmemdupz(id.name_begin, id.name_end - id.name_begin);
|
||||
state->committer_email =
|
||||
xmemdupz(id.mail_begin, id.mail_end - id.mail_end);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,6 +173,8 @@ static void am_state_release(struct am_state *state)
|
|||
free(state->author_name);
|
||||
free(state->author_email);
|
||||
free(state->author_date);
|
||||
free(state->committer_name);
|
||||
free(state->committer_email);
|
||||
free(state->msg);
|
||||
strvec_clear(&state->git_apply_opts);
|
||||
}
|
||||
|
@ -1556,7 +1570,7 @@ static void do_commit(const struct am_state *state)
|
|||
struct object_id tree, parent, commit;
|
||||
const struct object_id *old_oid;
|
||||
struct commit_list *parents = NULL;
|
||||
const char *reflog_msg, *author;
|
||||
const char *reflog_msg, *author, *committer = NULL;
|
||||
struct strbuf sb = STRBUF_INIT;
|
||||
|
||||
if (run_hook_le(NULL, "pre-applypatch", NULL))
|
||||
|
@ -1580,11 +1594,15 @@ static void do_commit(const struct am_state *state)
|
|||
IDENT_STRICT);
|
||||
|
||||
if (state->committer_date_is_author_date)
|
||||
setenv("GIT_COMMITTER_DATE",
|
||||
state->ignore_date ? "" : state->author_date, 1);
|
||||
committer = fmt_ident(state->committer_name,
|
||||
state->author_email, WANT_COMMITTER_IDENT,
|
||||
state->ignore_date ? NULL
|
||||
: state->author_date,
|
||||
IDENT_STRICT);
|
||||
|
||||
if (commit_tree(state->msg, state->msg_len, &tree, parents, &commit,
|
||||
author, state->sign_commit))
|
||||
if (commit_tree_extended(state->msg, state->msg_len, &tree, parents,
|
||||
&commit, author, committer, state->sign_commit,
|
||||
NULL))
|
||||
die(_("failed to write commit object"));
|
||||
|
||||
reflog_msg = getenv("GIT_REFLOG_ACTION");
|
||||
|
|
|
@ -1672,8 +1672,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
|
|||
}
|
||||
|
||||
if (commit_tree_extended(sb.buf, sb.len, &active_cache_tree->oid,
|
||||
parents, &oid, author_ident.buf, sign_commit,
|
||||
extra)) {
|
||||
parents, &oid, author_ident.buf, NULL,
|
||||
sign_commit, extra)) {
|
||||
rollback_index_files();
|
||||
die(_("failed to write commit object"));
|
||||
}
|
||||
|
|
|
@ -92,6 +92,8 @@ struct rebase_options {
|
|||
int autosquash;
|
||||
char *gpg_sign_opt;
|
||||
int autostash;
|
||||
int committer_date_is_author_date;
|
||||
int ignore_date;
|
||||
char *cmd;
|
||||
int allow_empty_message;
|
||||
int rebase_merges, rebase_cousins;
|
||||
|
@ -130,8 +132,12 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
|
|||
replay.quiet = !(opts->flags & REBASE_NO_QUIET);
|
||||
replay.verbose = opts->flags & REBASE_VERBOSE;
|
||||
replay.reschedule_failed_exec = opts->reschedule_failed_exec;
|
||||
replay.committer_date_is_author_date =
|
||||
opts->committer_date_is_author_date;
|
||||
replay.ignore_date = opts->ignore_date;
|
||||
replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
|
||||
replay.strategy = opts->strategy;
|
||||
|
||||
if (opts->strategy_opts)
|
||||
parse_strategy_opts(&replay, opts->strategy_opts);
|
||||
|
||||
|
@ -1289,6 +1295,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||
struct strbuf revisions = STRBUF_INIT;
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
struct object_id merge_base;
|
||||
int ignore_whitespace = 0;
|
||||
enum action action = ACTION_NONE;
|
||||
const char *gpg_sign = NULL;
|
||||
struct string_list exec = STRING_LIST_INIT_NODUP;
|
||||
|
@ -1318,16 +1325,17 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||
PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },
|
||||
OPT_BOOL(0, "signoff", &options.signoff,
|
||||
N_("add a Signed-off-by: line to each commit")),
|
||||
OPT_PASSTHRU_ARGV(0, "ignore-whitespace", &options.git_am_opts,
|
||||
NULL, N_("passed to 'git am'"),
|
||||
PARSE_OPT_NOARG),
|
||||
OPT_PASSTHRU_ARGV(0, "committer-date-is-author-date",
|
||||
&options.git_am_opts, NULL,
|
||||
N_("passed to 'git am'"), PARSE_OPT_NOARG),
|
||||
OPT_PASSTHRU_ARGV(0, "ignore-date", &options.git_am_opts, NULL,
|
||||
N_("passed to 'git am'"), PARSE_OPT_NOARG),
|
||||
OPT_BOOL(0, "committer-date-is-author-date",
|
||||
&options.committer_date_is_author_date,
|
||||
N_("make committer date match author date")),
|
||||
OPT_BOOL(0, "reset-author-date", &options.ignore_date,
|
||||
N_("ignore author date and use current date")),
|
||||
OPT_HIDDEN_BOOL(0, "ignore-date", &options.ignore_date,
|
||||
N_("synonym of --reset-author-date")),
|
||||
OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
|
||||
N_("passed to 'git apply'"), 0),
|
||||
OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace,
|
||||
N_("ignore changes in whitespace")),
|
||||
OPT_PASSTHRU_ARGV(0, "whitespace", &options.git_am_opts,
|
||||
N_("action"), N_("passed to 'git apply'"), 0),
|
||||
OPT_BIT('f', "force-rebase", &options.flags,
|
||||
|
@ -1624,12 +1632,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||
options.autosquash) {
|
||||
allow_preemptive_ff = 0;
|
||||
}
|
||||
if (options.committer_date_is_author_date || options.ignore_date)
|
||||
options.flags |= REBASE_FORCE;
|
||||
|
||||
for (i = 0; i < options.git_am_opts.nr; i++) {
|
||||
const char *option = options.git_am_opts.v[i], *p;
|
||||
if (!strcmp(option, "--committer-date-is-author-date") ||
|
||||
!strcmp(option, "--ignore-date") ||
|
||||
!strcmp(option, "--whitespace=fix") ||
|
||||
if (!strcmp(option, "--whitespace=fix") ||
|
||||
!strcmp(option, "--whitespace=strip"))
|
||||
allow_preemptive_ff = 0;
|
||||
else if (skip_prefix(option, "-C", &p)) {
|
||||
|
@ -1682,6 +1690,23 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
|
|||
imply_merge(&options, "--rebase-merges");
|
||||
}
|
||||
|
||||
if (options.type == REBASE_APPLY) {
|
||||
if (ignore_whitespace)
|
||||
strvec_push(&options.git_am_opts,
|
||||
"--ignore-whitespace");
|
||||
if (options.committer_date_is_author_date)
|
||||
strvec_push(&options.git_am_opts,
|
||||
"--committer-date-is-author-date");
|
||||
if (options.ignore_date)
|
||||
strvec_push(&options.git_am_opts, "--ignore-date");
|
||||
} else {
|
||||
/* REBASE_MERGE and PRESERVE_MERGES */
|
||||
if (ignore_whitespace) {
|
||||
string_list_append(&strategy_options,
|
||||
"ignore-space-change");
|
||||
}
|
||||
}
|
||||
|
||||
if (strategy_options.nr) {
|
||||
int i;
|
||||
|
||||
|
|
11
commit.c
11
commit.c
|
@ -1316,8 +1316,8 @@ int commit_tree(const char *msg, size_t msg_len, const struct object_id *tree,
|
|||
int result;
|
||||
|
||||
append_merge_tag_headers(parents, &tail);
|
||||
result = commit_tree_extended(msg, msg_len, tree, parents, ret,
|
||||
author, sign_commit, extra);
|
||||
result = commit_tree_extended(msg, msg_len, tree, parents, ret, author,
|
||||
NULL, sign_commit, extra);
|
||||
free_commit_extra_headers(extra);
|
||||
return result;
|
||||
}
|
||||
|
@ -1440,7 +1440,8 @@ N_("Warning: commit message did not conform to UTF-8.\n"
|
|||
int commit_tree_extended(const char *msg, size_t msg_len,
|
||||
const struct object_id *tree,
|
||||
struct commit_list *parents, struct object_id *ret,
|
||||
const char *author, const char *sign_commit,
|
||||
const char *author, const char *committer,
|
||||
const char *sign_commit,
|
||||
struct commit_extra_header *extra)
|
||||
{
|
||||
int result;
|
||||
|
@ -1473,7 +1474,9 @@ int commit_tree_extended(const char *msg, size_t msg_len,
|
|||
if (!author)
|
||||
author = git_author_info(IDENT_STRICT);
|
||||
strbuf_addf(&buffer, "author %s\n", author);
|
||||
strbuf_addf(&buffer, "committer %s\n", git_committer_info(IDENT_STRICT));
|
||||
if (!committer)
|
||||
committer = git_committer_info(IDENT_STRICT);
|
||||
strbuf_addf(&buffer, "committer %s\n", committer);
|
||||
if (!encoding_is_utf8)
|
||||
strbuf_addf(&buffer, "encoding %s\n", git_commit_encoding);
|
||||
|
||||
|
|
7
commit.h
7
commit.h
|
@ -270,10 +270,9 @@ int commit_tree(const char *msg, size_t msg_len,
|
|||
|
||||
int commit_tree_extended(const char *msg, size_t msg_len,
|
||||
const struct object_id *tree,
|
||||
struct commit_list *parents,
|
||||
struct object_id *ret, const char *author,
|
||||
const char *sign_commit,
|
||||
struct commit_extra_header *);
|
||||
struct commit_list *parents, struct object_id *ret,
|
||||
const char *author, const char *committer,
|
||||
const char *sign_commit, struct commit_extra_header *);
|
||||
|
||||
struct commit_extra_header *read_commit_extra_headers(struct commit *, const char **);
|
||||
|
||||
|
|
24
ident.c
24
ident.c
|
@ -375,11 +375,15 @@ static void ident_env_hint(enum want_ident whose_ident)
|
|||
const char *fmt_ident(const char *name, const char *email,
|
||||
enum want_ident whose_ident, const char *date_str, int flag)
|
||||
{
|
||||
static struct strbuf ident = STRBUF_INIT;
|
||||
static int index;
|
||||
static struct strbuf ident_pool[2] = { STRBUF_INIT, STRBUF_INIT };
|
||||
int strict = (flag & IDENT_STRICT);
|
||||
int want_date = !(flag & IDENT_NO_DATE);
|
||||
int want_name = !(flag & IDENT_NO_NAME);
|
||||
|
||||
struct strbuf *ident = &ident_pool[index];
|
||||
index = (index + 1) % ARRAY_SIZE(ident_pool);
|
||||
|
||||
if (!email) {
|
||||
if (whose_ident == WANT_AUTHOR_IDENT && git_author_email.len)
|
||||
email = git_author_email.buf;
|
||||
|
@ -435,25 +439,25 @@ const char *fmt_ident(const char *name, const char *email,
|
|||
die(_("name consists only of disallowed characters: %s"), name);
|
||||
}
|
||||
|
||||
strbuf_reset(&ident);
|
||||
strbuf_reset(ident);
|
||||
if (want_name) {
|
||||
strbuf_addstr_without_crud(&ident, name);
|
||||
strbuf_addstr(&ident, " <");
|
||||
strbuf_addstr_without_crud(ident, name);
|
||||
strbuf_addstr(ident, " <");
|
||||
}
|
||||
strbuf_addstr_without_crud(&ident, email);
|
||||
strbuf_addstr_without_crud(ident, email);
|
||||
if (want_name)
|
||||
strbuf_addch(&ident, '>');
|
||||
strbuf_addch(ident, '>');
|
||||
if (want_date) {
|
||||
strbuf_addch(&ident, ' ');
|
||||
strbuf_addch(ident, ' ');
|
||||
if (date_str && date_str[0]) {
|
||||
if (parse_date(date_str, &ident) < 0)
|
||||
if (parse_date(date_str, ident) < 0)
|
||||
die(_("invalid date format: %s"), date_str);
|
||||
}
|
||||
else
|
||||
strbuf_addstr(&ident, ident_default_date());
|
||||
strbuf_addstr(ident, ident_default_date());
|
||||
}
|
||||
|
||||
return ident.buf;
|
||||
return ident->buf;
|
||||
}
|
||||
|
||||
const char *fmt_name(enum want_ident whose_ident)
|
||||
|
|
130
sequencer.c
130
sequencer.c
|
@ -150,6 +150,8 @@ static GIT_PATH_FUNC(rebase_path_refs_to_delete, "rebase-merge/refs-to-delete")
|
|||
* command-line.
|
||||
*/
|
||||
static GIT_PATH_FUNC(rebase_path_gpg_sign_opt, "rebase-merge/gpg_sign_opt")
|
||||
static GIT_PATH_FUNC(rebase_path_cdate_is_adate, "rebase-merge/cdate_is_adate")
|
||||
static GIT_PATH_FUNC(rebase_path_ignore_date, "rebase-merge/ignore_date")
|
||||
static GIT_PATH_FUNC(rebase_path_orig_head, "rebase-merge/orig-head")
|
||||
static GIT_PATH_FUNC(rebase_path_verbose, "rebase-merge/verbose")
|
||||
static GIT_PATH_FUNC(rebase_path_quiet, "rebase-merge/quiet")
|
||||
|
@ -303,6 +305,8 @@ int sequencer_remove_state(struct replay_opts *opts)
|
|||
}
|
||||
}
|
||||
|
||||
free(opts->committer_name);
|
||||
free(opts->committer_email);
|
||||
free(opts->gpg_sign);
|
||||
free(opts->strategy);
|
||||
for (i = 0; i < opts->xopts_nr; i++)
|
||||
|
@ -864,6 +868,22 @@ static char *get_author(const char *message)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static const char *author_date_from_env_array(const struct strvec *env)
|
||||
{
|
||||
int i;
|
||||
const char *date;
|
||||
|
||||
for (i = 0; i < env->nr; i++)
|
||||
if (skip_prefix(env->v[i],
|
||||
"GIT_AUTHOR_DATE=", &date))
|
||||
return date;
|
||||
/*
|
||||
* If GIT_AUTHOR_DATE is missing we should have already errored out when
|
||||
* reading the script
|
||||
*/
|
||||
BUG("GIT_AUTHOR_DATE missing from author script");
|
||||
}
|
||||
|
||||
static const char staged_changes_advice[] =
|
||||
N_("you have staged changes in your working tree\n"
|
||||
"If these changes are meant to be squashed into the previous commit, run:\n"
|
||||
|
@ -930,6 +950,14 @@ static int run_git_commit(struct repository *r,
|
|||
gpg_opt, gpg_opt);
|
||||
}
|
||||
|
||||
if (opts->committer_date_is_author_date)
|
||||
strvec_pushf(&cmd.env_array, "GIT_COMMITTER_DATE=%s",
|
||||
opts->ignore_date ?
|
||||
"" :
|
||||
author_date_from_env_array(&cmd.env_array));
|
||||
if (opts->ignore_date)
|
||||
strvec_push(&cmd.env_array, "GIT_AUTHOR_DATE=");
|
||||
|
||||
strvec_push(&cmd.args, "commit");
|
||||
|
||||
if (!(flags & VERIFY_MSG))
|
||||
|
@ -1309,6 +1337,7 @@ static int try_to_commit(struct repository *r,
|
|||
struct strbuf err = STRBUF_INIT;
|
||||
struct strbuf commit_msg = STRBUF_INIT;
|
||||
char *amend_author = NULL;
|
||||
const char *committer = NULL;
|
||||
const char *hook_commit = NULL;
|
||||
enum commit_msg_cleanup_mode cleanup;
|
||||
int res = 0;
|
||||
|
@ -1400,10 +1429,57 @@ static int try_to_commit(struct repository *r,
|
|||
goto out;
|
||||
}
|
||||
|
||||
reset_ident_date();
|
||||
if (opts->committer_date_is_author_date) {
|
||||
struct ident_split id;
|
||||
struct strbuf date = STRBUF_INIT;
|
||||
|
||||
if (commit_tree_extended(msg->buf, msg->len, &tree, parents,
|
||||
oid, author, opts->gpg_sign, extra)) {
|
||||
if (!opts->ignore_date) {
|
||||
if (split_ident_line(&id, author, (int)strlen(author)) < 0) {
|
||||
res = error(_("invalid author identity '%s'"),
|
||||
author);
|
||||
goto out;
|
||||
}
|
||||
if (!id.date_begin) {
|
||||
res = error(_(
|
||||
"corrupt author: missing date information"));
|
||||
goto out;
|
||||
}
|
||||
strbuf_addf(&date, "@%.*s %.*s",
|
||||
(int)(id.date_end - id.date_begin),
|
||||
id.date_begin,
|
||||
(int)(id.tz_end - id.tz_begin),
|
||||
id.tz_begin);
|
||||
} else {
|
||||
reset_ident_date();
|
||||
}
|
||||
committer = fmt_ident(opts->committer_name,
|
||||
opts->committer_email,
|
||||
WANT_COMMITTER_IDENT,
|
||||
opts->ignore_date ? NULL : date.buf,
|
||||
IDENT_STRICT);
|
||||
strbuf_release(&date);
|
||||
} else {
|
||||
reset_ident_date();
|
||||
}
|
||||
|
||||
if (opts->ignore_date) {
|
||||
struct ident_split id;
|
||||
char *name, *email;
|
||||
|
||||
if (split_ident_line(&id, author, strlen(author)) < 0) {
|
||||
error(_("invalid author identity '%s'"), author);
|
||||
goto out;
|
||||
}
|
||||
name = xmemdupz(id.name_begin, id.name_end - id.name_begin);
|
||||
email = xmemdupz(id.mail_begin, id.mail_end - id.mail_begin);
|
||||
author = fmt_ident(name, email, WANT_AUTHOR_IDENT, NULL,
|
||||
IDENT_STRICT);
|
||||
free(name);
|
||||
free(email);
|
||||
}
|
||||
|
||||
if (commit_tree_extended(msg->buf, msg->len, &tree, parents, oid,
|
||||
author, committer, opts->gpg_sign, extra)) {
|
||||
res = error(_("failed to write commit object"));
|
||||
goto out;
|
||||
}
|
||||
|
@ -2535,6 +2611,16 @@ static int read_populate_opts(struct replay_opts *opts)
|
|||
opts->signoff = 1;
|
||||
}
|
||||
|
||||
if (file_exists(rebase_path_cdate_is_adate())) {
|
||||
opts->allow_ff = 0;
|
||||
opts->committer_date_is_author_date = 1;
|
||||
}
|
||||
|
||||
if (file_exists(rebase_path_ignore_date())) {
|
||||
opts->allow_ff = 0;
|
||||
opts->ignore_date = 1;
|
||||
}
|
||||
|
||||
if (file_exists(rebase_path_reschedule_failed_exec()))
|
||||
opts->reschedule_failed_exec = 1;
|
||||
|
||||
|
@ -2630,6 +2716,10 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
|
|||
write_file(rebase_path_drop_redundant_commits(), "%s", "");
|
||||
if (opts->keep_redundant_commits)
|
||||
write_file(rebase_path_keep_redundant_commits(), "%s", "");
|
||||
if (opts->committer_date_is_author_date)
|
||||
write_file(rebase_path_cdate_is_adate(), "%s", "");
|
||||
if (opts->ignore_date)
|
||||
write_file(rebase_path_ignore_date(), "%s", "");
|
||||
if (opts->reschedule_failed_exec)
|
||||
write_file(rebase_path_reschedule_failed_exec(), "%s", "");
|
||||
|
||||
|
@ -3552,6 +3642,14 @@ static int do_merge(struct repository *r,
|
|||
goto leave_merge;
|
||||
}
|
||||
|
||||
if (opts->committer_date_is_author_date)
|
||||
strvec_pushf(&cmd.env_array, "GIT_COMMITTER_DATE=%s",
|
||||
opts->ignore_date ?
|
||||
"" :
|
||||
author_date_from_env_array(&cmd.env_array));
|
||||
if (opts->ignore_date)
|
||||
strvec_push(&cmd.env_array, "GIT_AUTHOR_DATE=");
|
||||
|
||||
cmd.git_cmd = 1;
|
||||
strvec_push(&cmd.args, "merge");
|
||||
strvec_push(&cmd.args, "-s");
|
||||
|
@ -3916,7 +4014,9 @@ static int pick_commits(struct repository *r,
|
|||
prev_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
|
||||
if (opts->allow_ff)
|
||||
assert(!(opts->signoff || opts->no_commit ||
|
||||
opts->record_origin || opts->edit));
|
||||
opts->record_origin || opts->edit ||
|
||||
opts->committer_date_is_author_date ||
|
||||
opts->ignore_date));
|
||||
if (read_and_refresh_cache(r, opts))
|
||||
return -1;
|
||||
|
||||
|
@ -4358,6 +4458,22 @@ static int commit_staged_changes(struct repository *r,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int init_committer(struct replay_opts *opts)
|
||||
{
|
||||
struct ident_split id;
|
||||
const char *committer;
|
||||
|
||||
committer = git_committer_info(IDENT_STRICT);
|
||||
if (split_ident_line(&id, committer, strlen(committer)) < 0)
|
||||
return error(_("invalid committer '%s'"), committer);
|
||||
opts->committer_name =
|
||||
xmemdupz(id.name_begin, id.name_end - id.name_begin);
|
||||
opts->committer_email =
|
||||
xmemdupz(id.mail_begin, id.mail_end - id.mail_end);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sequencer_continue(struct repository *r, struct replay_opts *opts)
|
||||
{
|
||||
struct todo_list todo_list = TODO_LIST_INIT;
|
||||
|
@ -4369,6 +4485,9 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
|
|||
if (read_populate_opts(opts))
|
||||
return -1;
|
||||
if (is_rebase_i(opts)) {
|
||||
if (opts->committer_date_is_author_date && init_committer(opts))
|
||||
return -1;
|
||||
|
||||
if ((res = read_populate_todo(r, &todo_list, opts)))
|
||||
goto release_todo_list;
|
||||
|
||||
|
@ -5263,6 +5382,9 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
|
|||
|
||||
res = -1;
|
||||
|
||||
if (opts->committer_date_is_author_date && init_committer(opts))
|
||||
goto cleanup;
|
||||
|
||||
if (checkout_onto(r, opts, onto_name, &oid, orig_head))
|
||||
goto cleanup;
|
||||
|
||||
|
|
|
@ -45,9 +45,13 @@ struct replay_opts {
|
|||
int verbose;
|
||||
int quiet;
|
||||
int reschedule_failed_exec;
|
||||
int committer_date_is_author_date;
|
||||
int ignore_date;
|
||||
|
||||
int mainline;
|
||||
|
||||
char *committer_name;
|
||||
char *committer_email;
|
||||
char *gpg_sign;
|
||||
enum commit_msg_cleanup_mode default_msg_cleanup;
|
||||
int explicit_cleanup;
|
||||
|
|
|
@ -61,8 +61,6 @@ test_rebase_am_only () {
|
|||
}
|
||||
|
||||
test_rebase_am_only --whitespace=fix
|
||||
test_rebase_am_only --ignore-whitespace
|
||||
test_rebase_am_only --committer-date-is-author-date
|
||||
test_rebase_am_only -C4
|
||||
|
||||
test_expect_success REBASE_P '--preserve-merges incompatible with --signoff' '
|
||||
|
|
|
@ -0,0 +1,180 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2019 Rohit Ashiwal
|
||||
#
|
||||
|
||||
test_description='tests to ensure compatibility between am and interactive backends'
|
||||
|
||||
. ./test-lib.sh
|
||||
|
||||
. "$TEST_DIRECTORY"/lib-rebase.sh
|
||||
|
||||
GIT_AUTHOR_DATE="1999-04-02T08:03:20+05:30"
|
||||
export GIT_AUTHOR_DATE
|
||||
|
||||
# This is a special case in which both am and interactive backends
|
||||
# provide the same output. It was done intentionally because
|
||||
# both the backends fall short of optimal behaviour.
|
||||
test_expect_success 'setup' '
|
||||
git checkout -b topic &&
|
||||
test_write_lines "line 1" " line 2" "line 3" >file &&
|
||||
git add file &&
|
||||
git commit -m "add file" &&
|
||||
|
||||
test_write_lines "line 1" "new line 2" "line 3" >file &&
|
||||
git commit -am "update file" &&
|
||||
git tag side &&
|
||||
test_commit commit1 foo foo1 &&
|
||||
test_commit commit2 foo foo2 &&
|
||||
test_commit commit3 foo foo3 &&
|
||||
|
||||
git checkout --orphan master &&
|
||||
rm foo &&
|
||||
test_write_lines "line 1" " line 2" "line 3" >file &&
|
||||
git commit -am "add file" &&
|
||||
git tag main &&
|
||||
|
||||
mkdir test-bin &&
|
||||
write_script test-bin/git-merge-test <<-\EOF
|
||||
exec git merge-recursive "$@"
|
||||
EOF
|
||||
'
|
||||
|
||||
test_expect_success '--ignore-whitespace works with apply backend' '
|
||||
test_must_fail git rebase --apply main side &&
|
||||
git rebase --abort &&
|
||||
git rebase --apply --ignore-whitespace main side &&
|
||||
git diff --exit-code side
|
||||
'
|
||||
|
||||
test_expect_success '--ignore-whitespace works with merge backend' '
|
||||
test_must_fail git rebase --merge main side &&
|
||||
git rebase --abort &&
|
||||
git rebase --merge --ignore-whitespace main side &&
|
||||
git diff --exit-code side
|
||||
'
|
||||
|
||||
test_expect_success '--ignore-whitespace is remembered when continuing' '
|
||||
(
|
||||
set_fake_editor &&
|
||||
FAKE_LINES="break 1" git rebase -i --ignore-whitespace \
|
||||
main side &&
|
||||
git rebase --continue
|
||||
) &&
|
||||
git diff --exit-code side
|
||||
'
|
||||
|
||||
test_ctime_is_atime () {
|
||||
git log $1 --format=%ai >authortime &&
|
||||
git log $1 --format=%ci >committertime &&
|
||||
test_cmp authortime committertime
|
||||
}
|
||||
|
||||
test_expect_success '--committer-date-is-author-date works with apply backend' '
|
||||
GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
|
||||
git rebase --apply --committer-date-is-author-date HEAD^ &&
|
||||
test_ctime_is_atime -1
|
||||
'
|
||||
|
||||
test_expect_success '--committer-date-is-author-date works with merge backend' '
|
||||
GIT_AUTHOR_DATE="@1234 +0300" git commit --amend --reset-author &&
|
||||
git rebase -m --committer-date-is-author-date HEAD^ &&
|
||||
test_ctime_is_atime -1
|
||||
'
|
||||
|
||||
test_expect_success '--committer-date-is-author-date works with rebase -r' '
|
||||
git checkout side &&
|
||||
GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
|
||||
git rebase -r --root --committer-date-is-author-date &&
|
||||
test_ctime_is_atime
|
||||
'
|
||||
|
||||
test_expect_success '--committer-date-is-author-date works when forking merge' '
|
||||
git checkout side &&
|
||||
GIT_AUTHOR_DATE="@1234 +0300" git merge --no-ff commit3 &&
|
||||
PATH="./test-bin:$PATH" git rebase -r --root --strategy=test \
|
||||
--committer-date-is-author-date &&
|
||||
test_ctime_is_atime
|
||||
'
|
||||
|
||||
test_expect_success '--committer-date-is-author-date works when committing conflict resolution' '
|
||||
git checkout commit2 &&
|
||||
GIT_AUTHOR_DATE="@1980 +0000" git commit --amend --only --reset-author &&
|
||||
test_must_fail git rebase -m --committer-date-is-author-date \
|
||||
--onto HEAD^^ HEAD^ &&
|
||||
echo resolved > foo &&
|
||||
git add foo &&
|
||||
git rebase --continue &&
|
||||
test_ctime_is_atime -1
|
||||
'
|
||||
|
||||
# Checking for +0000 in the author date is sufficient since the
|
||||
# default timezone is UTC but the timezone used while committing is
|
||||
# +0530. The inverted logic in the grep is necessary to check all the
|
||||
# author dates in the file.
|
||||
test_atime_is_ignored () {
|
||||
git log $1 --format=%ai >authortime &&
|
||||
! grep -v +0000 authortime
|
||||
}
|
||||
|
||||
test_expect_success '--reset-author-date works with apply backend' '
|
||||
git commit --amend --date="$GIT_AUTHOR_DATE" &&
|
||||
git rebase --apply --reset-author-date HEAD^ &&
|
||||
test_atime_is_ignored -1
|
||||
'
|
||||
|
||||
test_expect_success '--reset-author-date works with merge backend' '
|
||||
git commit --amend --date="$GIT_AUTHOR_DATE" &&
|
||||
git rebase --reset-author-date -m HEAD^ &&
|
||||
test_atime_is_ignored -1
|
||||
'
|
||||
|
||||
test_expect_success '--reset-author-date works after conflict resolution' '
|
||||
test_must_fail git rebase --reset-author-date -m \
|
||||
--onto commit2^^ commit2^ commit2 &&
|
||||
echo resolved >foo &&
|
||||
git add foo &&
|
||||
git rebase --continue &&
|
||||
test_atime_is_ignored -1
|
||||
'
|
||||
|
||||
test_expect_success '--reset-author-date works with rebase -r' '
|
||||
git checkout side &&
|
||||
git merge --no-ff commit3 &&
|
||||
git rebase -r --root --reset-author-date &&
|
||||
test_atime_is_ignored
|
||||
'
|
||||
|
||||
test_expect_success '--reset-author-date with --committer-date-is-author-date works' '
|
||||
test_must_fail git rebase -m --committer-date-is-author-date \
|
||||
--reset-author-date --onto commit2^^ commit2^ commit3 &&
|
||||
git checkout --theirs foo &&
|
||||
git add foo &&
|
||||
git rebase --continue &&
|
||||
test_ctime_is_atime -2 &&
|
||||
test_atime_is_ignored -2
|
||||
'
|
||||
|
||||
test_expect_success '--reset-author-date --committer-date-is-author-date works when forking merge' '
|
||||
GIT_SEQUENCE_EDITOR="echo \"merge -C $(git rev-parse HEAD) commit3\">" \
|
||||
PATH="./test-bin:$PATH" git rebase -i --strategy=test \
|
||||
--reset-author-date \
|
||||
--committer-date-is-author-date side side &&
|
||||
test_ctime_is_atime -1 &&
|
||||
test_atime_is_ignored -1
|
||||
'
|
||||
|
||||
test_expect_success '--ignore-date is an alias for --reset-author-date' '
|
||||
git commit --amend --date="$GIT_AUTHOR_DATE" &&
|
||||
git rebase --apply --ignore-date HEAD^ &&
|
||||
git commit --allow-empty -m empty --date="$GIT_AUTHOR_DATE" &&
|
||||
git rebase -m --ignore-date HEAD^ &&
|
||||
test_atime_is_ignored -2
|
||||
'
|
||||
|
||||
# This must be the last test in this file
|
||||
test_expect_success '$EDITOR and friends are unchanged' '
|
||||
test_editor_unchanged
|
||||
'
|
||||
|
||||
test_done
|
Загрузка…
Ссылка в новой задаче