Skip to content

Commit 279bb9f

Browse files
committed
Merge branch 'ra/rebase-i-more-options' into pu
"git rebase -i" learned a few options that are known by "git rebase" proper. * ra/rebase-i-more-options: SQUASH??? rebase: add --author-date-is-committer-date rebase -i: support --ignore-date sequencer: rename amend_author to author_to_rename rebase -i: support --committer-date-is-author-date sequencer: add NULL checks under read_author_script rebase -i: add --ignore-whitespace flag
2 parents a0a2922 + 3c20705 commit 279bb9f

File tree

6 files changed

+276
-29
lines changed

6 files changed

+276
-29
lines changed

Documentation/git-rebase.txt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,16 +393,26 @@ 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+
This flag is either passed to the 'git apply' program
397+
(see linkgit:git-apply[1]), or to 'git merge' program
398+
(see linkgit:git-merge[1]) as `-Xignore-space-change`,
399+
depending on which backend is selected by other options.
400+
396401
--whitespace=<option>::
397-
These flag are passed to the 'git apply' program
402+
This flag is passed to the 'git apply' program
398403
(see linkgit:git-apply[1]) that applies the patch.
399404
+
400405
See also INCOMPATIBLE OPTIONS below.
401406

402407
--committer-date-is-author-date::
408+
Instead of recording the time the rebased commits are
409+
created as the committer date, reuse the author date
410+
as the committer date. This implies --force-rebase.
411+
403412
--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]).
413+
--author-date-is-committer-date::
414+
Lie about the author date by re-setting it to the value
415+
same as committer (current) date. This implies --force-rebase.
406416
+
407417
See also INCOMPATIBLE OPTIONS below.
408418

@@ -539,10 +549,7 @@ INCOMPATIBLE OPTIONS
539549

540550
The following options:
541551

542-
* --committer-date-is-author-date
543-
* --ignore-date
544552
* --whitespace
545-
* --ignore-whitespace
546553
* -C
547554

548555
are incompatible with the following options:
@@ -565,8 +572,12 @@ In addition, the following pairs of options are incompatible:
565572
* --preserve-merges and --interactive
566573
* --preserve-merges and --signoff
567574
* --preserve-merges and --rebase-merges
575+
* --preserve-merges and --ignore-whitespace
576+
* --preserve-merges and --committer-date-is-author-date
577+
* --preserve-merges and --ignore-date
568578
* --keep-base and --onto
569579
* --keep-base and --root
580+
* --rebase-merges and --ignore-whitespace
570581

571582
BEHAVIORAL DIFFERENCES
572583
-----------------------

builtin/rebase.c

Lines changed: 50 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;
@@ -97,7 +100,7 @@ struct rebase_options {
97100
.git_format_patch_opt = STRBUF_INIT \
98101
}
99102

100-
static struct replay_opts get_replay_opts(const struct rebase_options *opts)
103+
static struct replay_opts get_replay_opts(struct rebase_options *opts)
101104
{
102105
struct replay_opts replay = REPLAY_OPTS_INIT;
103106

@@ -112,8 +115,22 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
112115
replay.allow_empty_message = opts->allow_empty_message;
113116
replay.verbose = opts->flags & REBASE_VERBOSE;
114117
replay.reschedule_failed_exec = opts->reschedule_failed_exec;
118+
replay.committer_date_is_author_date =
119+
opts->committer_date_is_author_date;
120+
replay.ignore_date = opts->ignore_date;
115121
replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
116122
replay.strategy = opts->strategy;
123+
124+
if (opts->ignore_whitespace) {
125+
struct strbuf buf = STRBUF_INIT;
126+
127+
if (opts->strategy_opts)
128+
strbuf_addstr(&buf, opts->strategy_opts);
129+
130+
strbuf_addstr(&buf, " --ignore-space-change");
131+
free(opts->strategy_opts);
132+
opts->strategy_opts = strbuf_detach(&buf, NULL);
133+
}
117134
if (opts->strategy_opts)
118135
parse_strategy_opts(&replay, opts->strategy_opts);
119136

@@ -512,13 +529,19 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
512529
argc = parse_options(argc, argv, prefix, options,
513530
builtin_rebase_interactive_usage, PARSE_OPT_KEEP_ARGV0);
514531

532+
opts.strategy_opts = xstrdup_or_null(opts.strategy_opts);
533+
515534
if (!is_null_oid(&squash_onto))
516535
opts.squash_onto = &squash_onto;
517536

518537
if (opts.rebase_cousins >= 0 && !opts.rebase_merges)
519538
warning(_("--[no-]rebase-cousins has no effect without "
520539
"--rebase-merges"));
521540

541+
if (opts.committer_date_is_author_date ||
542+
opts.ignore_date)
543+
opts.flags |= REBASE_FORCE;
544+
522545
return !!run_rebase_interactive(&opts, command);
523546
}
524547

@@ -965,6 +988,12 @@ static int run_am(struct rebase_options *opts)
965988
am.git_cmd = 1;
966989
argv_array_push(&am.args, "am");
967990

991+
if (opts->ignore_whitespace)
992+
argv_array_push(&am.args, "--ignore-whitespace");
993+
if (opts->committer_date_is_author_date)
994+
argv_array_push(&opts->git_am_opts, "--committer-date-is-author-date");
995+
if (opts->ignore_date)
996+
argv_array_push(&opts->git_am_opts, "--ignore-date");
968997
if (opts->action && !strcmp("continue", opts->action)) {
969998
argv_array_push(&am.args, "--resolved");
970999
argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
@@ -1432,16 +1461,17 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
14321461
PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT },
14331462
OPT_BOOL(0, "signoff", &options.signoff,
14341463
N_("add a Signed-off-by: line to each commit")),
1435-
OPT_PASSTHRU_ARGV(0, "ignore-whitespace", &options.git_am_opts,
1436-
NULL, N_("passed to 'git am'"),
1437-
PARSE_OPT_NOARG),
1438-
OPT_PASSTHRU_ARGV(0, "committer-date-is-author-date",
1439-
&options.git_am_opts, NULL,
1440-
N_("passed to 'git am'"), PARSE_OPT_NOARG),
1441-
OPT_PASSTHRU_ARGV(0, "ignore-date", &options.git_am_opts, NULL,
1442-
N_("passed to 'git am'"), PARSE_OPT_NOARG),
1464+
OPT_BOOL(0, "committer-date-is-author-date",
1465+
&options.committer_date_is_author_date,
1466+
N_("make committer date match author date")),
1467+
OPT_BOOL(0, "author-date-is-committer-date", &options.ignore_date,
1468+
"ignore author date and use current date"),
1469+
OPT_BOOL(0, "ignore-date", &options.ignore_date,
1470+
"ignore author date and use current date"),
14431471
OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
14441472
N_("passed to 'git apply'"), 0),
1473+
OPT_BOOL(0, "ignore-whitespace", &options.ignore_whitespace,
1474+
N_("ignore changes in whitespace")),
14451475
OPT_PASSTHRU_ARGV(0, "whitespace", &options.git_am_opts,
14461476
N_("action"), N_("passed to 'git apply'"), 0),
14471477
OPT_BIT('f', "force-rebase", &options.flags,
@@ -1709,11 +1739,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
17091739
state_dir_base, cmd_live_rebase, buf.buf);
17101740
}
17111741

1742+
if (options.committer_date_is_author_date ||
1743+
options.ignore_date)
1744+
options.flags |= REBASE_FORCE;
1745+
17121746
for (i = 0; i < options.git_am_opts.argc; i++) {
17131747
const char *option = options.git_am_opts.argv[i], *p;
1714-
if (!strcmp(option, "--committer-date-is-author-date") ||
1715-
!strcmp(option, "--ignore-date") ||
1716-
!strcmp(option, "--whitespace=fix") ||
1748+
if (!strcmp(option, "--whitespace=fix") ||
17171749
!strcmp(option, "--whitespace=strip"))
17181750
options.flags |= REBASE_FORCE;
17191751
else if (skip_prefix(option, "-C", &p)) {
@@ -1861,6 +1893,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
18611893
"'--reschedule-failed-exec'"));
18621894
}
18631895

1896+
if (options.rebase_merges) {
1897+
if (options.ignore_whitespace)
1898+
die(_("cannot combine '--rebase-merges' with "
1899+
"'--ignore-whitespace'"));
1900+
}
1901+
18641902
if (!options.root) {
18651903
if (argc < 1) {
18661904
struct branch *branch;

0 commit comments

Comments
 (0)