Skip to content
Permalink
Browse files

rebase -i: add --ignore-whitespace flag

There are two backends available for rebasing, viz, the am and the
interactive. Naturally, there shall be some features that are
implemented in one but not in the other. One such flag is
--ignore-whitespace which indicates merge mechanism to treat lines
with only whitespace changes as unchanged.

am's --ignore-space-change (also aliased --ignore-whitespace; see
git-apply's description) not only share the same name with diff's
--ignore-space-change and merge's -Xignore-space-change, but the
similarity in naming appears to have been intentional with am's
--ignore-space-change being designed to have the same functionality
(see e.g. the commit messages for f008cef ("Merge branch
'jc/apply-ignore-whitespace'", 2014-06-04) and 4e5dd04
("merge-recursive: options to ignore whitespace chagnes", 2010-08-26)).

For the most part, these options do provide the same behaviour. However,
there are some edge cases where both apply's --ignore-space-change and
merge's -Xignore-space-change fall short of optimal behaviour, and that
too in different ways. Fixing these differences in edge cases is left
for future work; this patch simply wires the interactive rebase to
also understand the --ignore-whitespace flag by translating it to
-Xignore-space-change.

Signed-off-by: Rohit Ashiwal <rohit.ashiwal265@gmail.com>
  • Loading branch information...
r1walz committed Jun 4, 2019
1 parent 97f1b20 commit 41514b313352151fa7bc4c066ea0e2e43d76c5ad
Showing with 36 additions and 6 deletions.
  1. +7 −2 Documentation/git-rebase.txt
  2. +22 −3 builtin/rebase.c
  3. +1 −0 sequencer.h
  4. +0 −1 t/t3422-rebase-incompatible-options.sh
  5. +6 −0 t/t3431-rebase-ignore-ws.sh
@@ -371,8 +371,13 @@ If either <upstream> or --root is given on the command line, then the
default is `--no-fork-point`, otherwise the default is `--fork-point`.

--ignore-whitespace::
This flag is either passed to the 'git apply' program
(see linkgit:git-apply[1]), or to 'git merge' program
(see linkgit:git-merge[1]) as `-Xignore-space-change`,
depending on which backend is selected by other options.

--whitespace=<option>::
These flag 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.
+
See also INCOMPATIBLE OPTIONS below.
@@ -520,7 +525,6 @@ The following options:
* --committer-date-is-author-date
* --ignore-date
* --whitespace
* --ignore-whitespace
* -C

are incompatible with the following options:
@@ -543,6 +547,7 @@ In addition, the following pairs of options are incompatible:
* --preserve-merges and --interactive
* --preserve-merges and --signoff
* --preserve-merges and --rebase-merges
* --rebase-merges and --ignore-whitespace
* --rebase-merges and --strategy
* --rebase-merges and --strategy-option

@@ -79,6 +79,7 @@ struct rebase_options {
int allow_rerere_autoupdate;
int keep_empty;
int autosquash;
int ignore_whitespace;
char *gpg_sign_opt;
int autostash;
char *cmd;
@@ -376,6 +377,17 @@ static int run_rebase_interactive(struct rebase_options *opts,
flags |= opts->rebase_cousins > 0 ? TODO_LIST_REBASE_COUSINS : 0;
flags |= command == ACTION_SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0;

if (opts->ignore_whitespace) {
struct strbuf buf = STRBUF_INIT;

if (opts->strategy_opts)
strbuf_addstr(&buf, opts->strategy_opts);

strbuf_addstr(&buf, " --ignore-space-change");
free(opts->strategy_opts);
opts->strategy_opts = strbuf_detach(&buf, NULL);
}

switch (command) {
case ACTION_NONE: {
if (!opts->onto && !opts->upstream)
@@ -489,6 +501,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
{ OPTION_STRING, 'S', "gpg-sign", &opts.gpg_sign_opt, N_("key-id"),
N_("GPG-sign commits"),
PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
OPT_BOOL(0, "ignore-whitespace", &opts.ignore_whitespace,
N_("ignore changes in whitespace")),
OPT_STRING(0, "strategy", &opts.strategy, N_("strategy"),
N_("rebase strategy")),
OPT_STRING(0, "strategy-opts", &opts.strategy_opts, N_("strategy-opts"),
@@ -954,6 +968,9 @@ static int run_am(struct rebase_options *opts)
am.git_cmd = 1;
argv_array_push(&am.args, "am");

if (opts->ignore_whitespace)
argv_array_push(&am.args, "--ignore-whitespace");

if (opts->action && !strcmp("continue", opts->action)) {
argv_array_push(&am.args, "--resolved");
argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
@@ -1401,16 +1418,15 @@ 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_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"),
N_("passed to 'git apply'"), 0),
OPT_BOOL(0, "ignore-whitespace", &options.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,
@@ -1821,6 +1837,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
}

if (options.rebase_merges) {
if (options.ignore_whitespace)
die(_("cannot combine '--rebase-merges' with "
"'--ignore-whitespace'"));
if (strategy_options.nr)
die(_("cannot combine '--rebase-merges' with "
"'--strategy-option'"));
@@ -43,6 +43,7 @@ struct replay_opts {
int verbose;
int quiet;
int reschedule_failed_exec;
int ignore_whitespace;

int mainline;

@@ -61,7 +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

@@ -44,4 +44,10 @@ test_expect_success '--ignore-whitespace works with am backend' '
git rebase --ignore-whitespace main side
'

test_expect_success '--ignore-whitespace works with interactive backend' '
test_must_fail git rebase --merge main side &&
git rebase --abort &&
git rebase --merge --ignore-whitespace main side
'

test_done

0 comments on commit 41514b3

Please sign in to comment.
You can’t perform that action at this time.