Skip to content

Commit 5d9324e

Browse files
committed
Merge branch 'ra/rebase-i-more-options'
"git rebase -i" learned a few options that are known by "git rebase" proper. * ra/rebase-i-more-options: rebase -i: finishing touches to --reset-author-date rebase: add --reset-author-date rebase -i: support --ignore-date sequencer: rename amend_author to author_to_rename rebase -i: support --committer-date-is-author-date sequencer: allow callers of read_author_script() to ignore fields rebase -i: add --ignore-whitespace flag
2 parents c58ae96 + d82dfa7 commit 5d9324e

File tree

6 files changed

+323
-28
lines changed

6 files changed

+323
-28
lines changed

Documentation/git-rebase.txt

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,16 +393,31 @@ your branch contains commits which were dropped, this option can be used
393393
with `--keep-base` in order to drop those commits from your branch.
394394

395395
--ignore-whitespace::
396+
Behaves differently depending on which backend is selected.
397+
+
398+
'am' backend: When applying a patch, ignore changes in whitespace in
399+
context lines if necessary.
400+
+
401+
'interactive' backend: Treat lines with only whitespace changes as
402+
unchanged for the sake of a three-way merge.
403+
396404
--whitespace=<option>::
397-
These flag are passed to the 'git apply' program
405+
This flag is passed to the 'git apply' program
398406
(see linkgit:git-apply[1]) that applies the patch.
399407
+
400408
See also INCOMPATIBLE OPTIONS below.
401409

402410
--committer-date-is-author-date::
411+
Instead of recording the time the rebased commits are
412+
created as the committer date, reuse the author date
413+
as the committer date. This implies --force-rebase.
414+
403415
--ignore-date::
404-
These flags are passed to 'git am' to easily change the dates
405-
of the rebased commits (see linkgit:git-am[1]).
416+
--reset-author-date::
417+
By default, the author date of the original commit is used
418+
as the author date for the resulting commit. This option
419+
tells Git to use the current timestamp instead and implies
420+
`--force-rebase`.
406421
+
407422
See also INCOMPATIBLE OPTIONS below.
408423

@@ -539,10 +554,7 @@ INCOMPATIBLE OPTIONS
539554

540555
The following options:
541556

542-
* --committer-date-is-author-date
543-
* --ignore-date
544557
* --whitespace
545-
* --ignore-whitespace
546558
* -C
547559

548560
are incompatible with the following options:
@@ -565,6 +577,9 @@ In addition, the following pairs of options are incompatible:
565577
* --preserve-merges and --interactive
566578
* --preserve-merges and --signoff
567579
* --preserve-merges and --rebase-merges
580+
* --preserve-merges and --ignore-whitespace
581+
* --preserve-merges and --committer-date-is-author-date
582+
* --preserve-merges and --ignore-date
568583
* --keep-base and --onto
569584
* --keep-base and --root
570585

builtin/rebase.c

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,11 @@ struct rebase_options {
7979
int allow_rerere_autoupdate;
8080
int keep_empty;
8181
int autosquash;
82+
int ignore_whitespace;
8283
char *gpg_sign_opt;
8384
int autostash;
85+
int committer_date_is_author_date;
86+
int ignore_date;
8487
char *cmd;
8588
int allow_empty_message;
8689
int rebase_merges, rebase_cousins;
@@ -99,6 +102,7 @@ struct rebase_options {
99102

100103
static struct replay_opts get_replay_opts(const struct rebase_options *opts)
101104
{
105+
struct strbuf strategy_buf = STRBUF_INIT;
102106
struct replay_opts replay = REPLAY_OPTS_INIT;
103107

104108
replay.action = REPLAY_INTERACTIVE_REBASE;
@@ -112,11 +116,20 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
112116
replay.allow_empty_message = opts->allow_empty_message;
113117
replay.verbose = opts->flags & REBASE_VERBOSE;
114118
replay.reschedule_failed_exec = opts->reschedule_failed_exec;
119+
replay.committer_date_is_author_date =
120+
opts->committer_date_is_author_date;
121+
replay.ignore_date = opts->ignore_date;
115122
replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
116123
replay.strategy = opts->strategy;
124+
117125
if (opts->strategy_opts)
118-
parse_strategy_opts(&replay, opts->strategy_opts);
126+
strbuf_addstr(&strategy_buf, opts->strategy_opts);
127+
if (opts->ignore_whitespace)
128+
strbuf_addstr(&strategy_buf, " --ignore-space-change");
129+
if (strategy_buf.len)
130+
parse_strategy_opts(&replay, strategy_buf.buf);
119131

132+
strbuf_release(&strategy_buf);
120133
return replay;
121134
}
122135

@@ -512,6 +525,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
512525
argc = parse_options(argc, argv, prefix, options,
513526
builtin_rebase_interactive_usage, PARSE_OPT_KEEP_ARGV0);
514527

528+
opts.strategy_opts = xstrdup_or_null(opts.strategy_opts);
529+
515530
if (!is_null_oid(&squash_onto))
516531
opts.squash_onto = &squash_onto;
517532

@@ -965,6 +980,12 @@ static int run_am(struct rebase_options *opts)
965980
am.git_cmd = 1;
966981
argv_array_push(&am.args, "am");
967982

983+
if (opts->ignore_whitespace)
984+
argv_array_push(&am.args, "--ignore-whitespace");
985+
if (opts->committer_date_is_author_date)
986+
argv_array_push(&opts->git_am_opts, "--committer-date-is-author-date");
987+
if (opts->ignore_date)
988+
argv_array_push(&opts->git_am_opts, "--ignore-date");
968989
if (opts->action && !strcmp("continue", opts->action)) {
969990
argv_array_push(&am.args, "--resolved");
970991
argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
@@ -1431,16 +1452,17 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
14311452
PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },
14321453
OPT_BOOL(0, "signoff", &options.signoff,
14331454
N_("add a Signed-off-by: line to each commit")),
1434-
OPT_PASSTHRU_ARGV(0, "ignore-whitespace", &options.git_am_opts,
1435-
NULL, N_("passed to 'git am'"),
1436-
PARSE_OPT_NOARG),
1437-
OPT_PASSTHRU_ARGV(0, "committer-date-is-author-date",
1438-
&options.git_am_opts, NULL,
1439-
N_("passed to 'git am'"), PARSE_OPT_NOARG),
1440-
OPT_PASSTHRU_ARGV(0, "ignore-date", &options.git_am_opts, NULL,
1441-
N_("passed to 'git am'"), PARSE_OPT_NOARG),
1455+
OPT_BOOL(0, "committer-date-is-author-date",
1456+
&options.committer_date_is_author_date,
1457+
N_("make committer date match author date")),
1458+
OPT_BOOL(0, "reset-author-date", &options.ignore_date,
1459+
N_("ignore author date and use current date")),
1460+
OPT_HIDDEN_BOOL(0, "ignore-date", &options.ignore_date,
1461+
N_("synonym of --reset-author-date")),
14421462
OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
14431463
N_("passed to 'git apply'"), 0),
1464+
OPT_BOOL(0, "ignore-whitespace", &options.ignore_whitespace,
1465+
N_("ignore changes in whitespace")),
14441466
OPT_PASSTHRU_ARGV(0, "whitespace", &options.git_am_opts,
14451467
N_("action"), N_("passed to 'git apply'"), 0),
14461468
OPT_BIT('f', "force-rebase", &options.flags,
@@ -1713,11 +1735,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
17131735
state_dir_base, cmd_live_rebase, buf.buf);
17141736
}
17151737

1738+
if (options.committer_date_is_author_date ||
1739+
options.ignore_date)
1740+
options.flags |= REBASE_FORCE;
1741+
17161742
for (i = 0; i < options.git_am_opts.argc; i++) {
17171743
const char *option = options.git_am_opts.argv[i], *p;
1718-
if (!strcmp(option, "--committer-date-is-author-date") ||
1719-
!strcmp(option, "--ignore-date") ||
1720-
!strcmp(option, "--whitespace=fix") ||
1744+
if (!strcmp(option, "--whitespace=fix") ||
17211745
!strcmp(option, "--whitespace=strip"))
17221746
options.flags |= REBASE_FORCE;
17231747
else if (skip_prefix(option, "-C", &p)) {

0 commit comments

Comments
 (0)