{"thread":{"id":"66956","subject":"[PATCH 0/4] rebase: support --whitespace=fix with --interactive","startedAt":"2026-11-30T00:01:21Z","lastAt":"2026-11-30T00:01:25Z","messageCount":5,"participants":["Alessio Attilio via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"559661","messageId":"pull.2511.git.git.1795996885.gitgitgadget@gmail.com","threadId":"66956","inReplyTo":null,"subject":"[PATCH 0/4] rebase: support --whitespace=fix with --interactive","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-30T00:01:21Z","receivedAt":"2026-11-30T00:01:21Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"The apply backend implements --whitespace=fix through git apply, which\nprevents users from combining it with interactive rebases and other\nmerge-backend features. Teach merge replay to compare whitespace-normalized\nrecords, then fix only lines introduced by replay using the path's\nwhitespace rules. Keep other whitespace actions on the apply backend.\n\nTests cover interactive replay, attributes, existing whitespace, added\nfiles, end-of-file handling, and unsupported actions.\n\nCloses gitgitgadget/git#1472\n\nAlessio Attilio (4):\n  xdiff: support transformed records in merge matching\n  merge-ort: fix whitespace in replayed changes\n  rebase: route whitespace fixes through the selected backend\n  rebase: test whitespace fixes with the merge backend\n\n Documentation/git-rebase.adoc          |   6 +-\n builtin/rebase.c                       |  55 +++++++-\n contrib/completion/git-completion.bash |   2 +-\n merge-ll.c                             | 182 ++++++++++++++++++++++++-\n merge-ll.h                             |   5 +\n merge-ort.c                            |  52 +++++++\n merge-ort.h                            |   1 +\n t/t3417-rebase-whitespace-fix.sh       | 163 ++++++++++++++++++++++\n t/t3422-rebase-incompatible-options.sh |  17 ++-\n xdiff/xdiff.h                          |   4 +\n xdiff/xmerge.c                         |  16 +--\n xdiff/xprepare.c                       |  57 ++++++--\n xdiff/xtypes.h                         |   2 +\n xdiff/xutils.c                         |  14 ++\n xdiff/xutils.h                         |   2 +\n 15 files changed, 547 insertions(+), 31 deletions(-)\n\n\nbase-commit: acba8bf9753134d9bde89f94369f775838a8c5fe\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2511%2Fkairosci%2Fds%2Frebase-whitespace-fix-merge-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2511/kairosci/ds/rebase-whitespace-fix-merge-v1\nPull-Request: https://github.com/git/git/pull/2511\n-- \ngitgitgadget\n\n"},{"id":"559662","messageId":"279ec378886f3ffce3690f7fcd3a8d5e3916d62a.1795996885.git.gitgitgadget@gmail.com","threadId":"66956","inReplyTo":"pull.2511.git.git.1795996885.gitgitgadget@gmail.com","subject":"[PATCH 1/4] xdiff: support transformed records in merge matching","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-30T00:01:22Z","receivedAt":"2026-11-30T00:01:22Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"From: Alessio Attilio <attilio.alessio@protonmail.com>\n\nThe merge backend compares lines from both sides before deciding whether\nchanges overlap.  Whitespace fixes can make otherwise identical lines\ndiffer, so let xdiff compare transformed records while retaining the\noriginal records for output.\n\nAdd an optional line transformation to xdiff's record preparation and use\nthe transformed bytes for hashing and matching.  Keeping transformation\nseparate from the source records lets callers normalize only for matching\nwithout changing unchanged text in the result.\n\nSigned-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n---\n xdiff/xdiff.h    |  4 ++++\n xdiff/xmerge.c   | 16 ++++++--------\n xdiff/xprepare.c | 57 +++++++++++++++++++++++++++++++++++++++---------\n xdiff/xtypes.h   |  2 ++\n xdiff/xutils.c   | 14 ++++++++++++\n xdiff/xutils.h   |  2 ++\n 6 files changed, 76 insertions(+), 19 deletions(-)\n\ndiff --git a/xdiff/xdiff.h b/xdiff/xdiff.h\nindex 8fa513fc4e..07c15c630e 100644\n--- a/xdiff/xdiff.h\n+++ b/xdiff/xdiff.h\n@@ -73,6 +73,8 @@ typedef struct s_mmfile {\n \tsize_t size;\n } mmfile_t;\n \n+typedef int (*xdl_line_transform_fn)(const char *, long, int, char **, long *, void *);\n+\n typedef struct s_xpparam {\n \tunsigned long flags;\n \n@@ -83,6 +85,8 @@ typedef struct s_xpparam {\n \t/* See Documentation/diff-options.adoc. */\n \tchar **anchors;\n \tsize_t anchors_nr;\n+\txdl_line_transform_fn line_transform;\n+\tvoid *line_transform_data;\n } xpparam_t;\n \n typedef struct s_xdemitcb {\ndiff --git a/xdiff/xmerge.c b/xdiff/xmerge.c\nindex 5a78b88fad..0e335e2658 100644\n--- a/xdiff/xmerge.c\n+++ b/xdiff/xmerge.c\n@@ -94,15 +94,14 @@ static int xdl_cleanup_merge(xdmerge_t *c)\n }\n \n static int xdl_merge_cmp_lines(xdfenv_t *xe1, int i1, xdfenv_t *xe2, int i2,\n-\t\tint line_count, long flags)\n+\t\tint line_count, xpparam_t const *xpp)\n {\n \tint i;\n \txrecord_t *rec1 = xe1->xdf2.recs + i1;\n \txrecord_t *rec2 = xe2->xdf2.recs + i2;\n \n \tfor (i = 0; i < line_count; i++) {\n-\t\tint result = xdl_recmatch((const char *)rec1[i].ptr, (long)rec1[i].size,\n-\t\t\t(const char *)rec2[i].ptr, (long)rec2[i].size, flags);\n+\t\tint result = xdl_recmatch_records(&rec1[i], &rec2[i], xpp);\n \t\tif (!result)\n \t\t\treturn -1;\n \t}\n@@ -323,10 +322,9 @@ static size_t xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,\n \treturn size;\n }\n \n-static int recmatch(xrecord_t *rec1, xrecord_t *rec2, unsigned long flags)\n+static int recmatch(xrecord_t *rec1, xrecord_t *rec2, xpparam_t const *xpp)\n {\n-\treturn xdl_recmatch((const char *)rec1->ptr, (long)rec1->size,\n-\t\t\t    (const char *)rec2->ptr, (long)rec2->size, flags);\n+\treturn xdl_recmatch_records(rec1, rec2, xpp);\n }\n \n /*\n@@ -342,7 +340,7 @@ static void xdl_refine_zdiff3_conflicts(xdfenv_t *xe1, xdfenv_t *xe2, xdmerge_t\n \t\t\tcontinue;\n \n \t\twhile(m->chg1 && m->chg2 &&\n-\t\t      recmatch(&rec1[m->i1], &rec2[m->i2], xpp->flags)) {\n+\t\t      recmatch(&rec1[m->i1], &rec2[m->i2], xpp)) {\n \t\t\tm->chg1--;\n \t\t\tm->chg2--;\n \t\t\tm->i1++;\n@@ -350,7 +348,7 @@ static void xdl_refine_zdiff3_conflicts(xdfenv_t *xe1, xdfenv_t *xe2, xdmerge_t\n \t\t}\n \t\twhile (m->chg1 && m->chg2 &&\n \t\t       recmatch(&rec1[m->i1 + m->chg1 - 1],\n-\t\t\t\t&rec2[m->i2 + m->chg2 - 1], xpp->flags)) {\n+\t\t\t\t&rec2[m->i2 + m->chg2 - 1], xpp)) {\n \t\t\tm->chg1--;\n \t\t\tm->chg2--;\n \t\t}\n@@ -581,7 +579,7 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1,\n \t\t\t\txscr1->chg2 != xscr2->chg2 ||\n \t\t\t\txdl_merge_cmp_lines(xe1, xscr1->i2,\n \t\t\t\t\txe2, xscr2->i2,\n-\t\t\t\t\txscr1->chg2, xpp->flags)) {\n+\t\t\t\t\txscr1->chg2, xpp)) {\n \t\t\t/* conflict */\n \t\t\tint off = xscr1->i1 - xscr2->i1;\n \t\t\tint ffo = off + xscr1->chg1 - xscr2->chg1;\ndiff --git a/xdiff/xprepare.c b/xdiff/xprepare.c\nindex 11bada2608..3d6df505c3 100644\n--- a/xdiff/xprepare.c\n+++ b/xdiff/xprepare.c\n@@ -56,8 +56,9 @@ typedef struct s_xdlclassifier {\n \n \n \n-static int xdl_init_classifier(xdlclassifier_t *cf, long size, long flags) {\n-\tcf->flags = flags;\n+static int xdl_init_classifier(xdlclassifier_t *cf, long size,\n+\t\t\t       xpparam_t const *xpp) {\n+\tcf->flags = xpp->flags;\n \n \tcf->hbits = xdl_hashbits((unsigned int) size);\n \tcf->hsize = 1 << cf->hbits;\n@@ -98,12 +99,15 @@ static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t\n \t\t\t       uint64_t line_hash) {\n \tsize_t hi;\n \txdlclass_t *rcrec;\n+\tconst uint8_t *ptr = rec->match_ptr ? (uint8_t *)rec->match_ptr : rec->ptr;\n+\tsize_t size = rec->match_ptr ? rec->match_size : rec->size;\n \n \thi = XDL_HASHLONG(line_hash, cf->hbits);\n \tfor (rcrec = cf->rchash[hi]; rcrec; rcrec = rcrec->next)\n \t\tif (rcrec->line_hash == line_hash &&\n-\t\t\t\txdl_recmatch((const char *)rcrec->ptr, (long)rcrec->size,\n-\t\t\t\t\t(const char *)rec->ptr, (long)rec->size, cf->flags))\n+\t\t\t\txdl_recmatch((const char *)rcrec->ptr,\n+\t\t\t\t\t(long)rcrec->size, (const char *)ptr,\n+\t\t\t\t\t(long)size, cf->flags))\n \t\t\tbreak;\n \n \tif (!rcrec) {\n@@ -116,8 +120,8 @@ static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t\n \t\t\t\treturn -1;\n \t\tcf->rcrecs[rcrec->idx] = rcrec;\n \t\trcrec->line_hash = line_hash;\n-\t\trcrec->ptr = rec->ptr;\n-\t\trcrec->size = rec->size;\n+\t\trcrec->ptr = ptr;\n+\t\trcrec->size = size;\n \t\trcrec->len1 = rcrec->len2 = 0;\n \t\trcrec->next = cf->rchash[hi];\n \t\tcf->rchash[hi] = rcrec;\n@@ -133,6 +137,9 @@ static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t\n \n static void xdl_free_ctx(xdfile_t *xdf)\n {\n+\tsize_t i;\n+\tfor (i = 0; i < xdf->nrec; i++)\n+\t\tfree(xdf->recs[i].match_ptr);\n \txdl_free(xdf->reference_index);\n \txdl_free(xdf->changed - 1);\n \txdl_free(xdf->recs);\n@@ -142,13 +149,14 @@ static void xdl_free_ctx(xdfile_t *xdf)\n static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_t const *xpp,\n \t\t\t   xdlclassifier_t *cf, xdfile_t *xdf) {\n \tlong bsize;\n-\tuint64_t hav;\n+\tuint64_t hav = 0;\n \tuint8_t const *blk, *cur, *top, *prev;\n \txrecord_t *crec;\n \n \txdf->reference_index = NULL;\n \txdf->changed = NULL;\n \txdf->recs = NULL;\n+\txdf->nrec = 0;\n \n \tif (!XDL_ALLOC_ARRAY(xdf->recs, narec))\n \t\tgoto abort;\n@@ -156,13 +164,42 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_\n \txdf->nrec = 0;\n \tif ((cur = blk = xdl_mmfile_first(mf, &bsize))) {\n \t\tfor (top = blk + bsize; cur < top; ) {\n+\t\t\tlong line_size;\n+\t\t\tint is_eof;\n+\t\t\tchar *transformed = NULL;\n+\t\t\tlong transformed_size = 0;\n+\t\t\tuint8_t const *transformed_ptr;\n+\n \t\t\tprev = cur;\n-\t\t\thav = xdl_hash_record(&cur, top, xpp->flags);\n+\t\t\tif (xpp->line_transform) {\n+\t\t\t\tconst uint8_t *line_end = memchr(cur, '\\n', top - cur);\n+\t\t\t\tline_size = line_end ? line_end + 1 - cur : top - cur;\n+\t\t\t\tis_eof = cur + line_size == top;\n+\t\t\t\tcur += line_size;\n+\t\t\t} else {\n+\t\t\t\thav = xdl_hash_record(&cur, top, xpp->flags);\n+\t\t\t\tline_size = cur - prev;\n+\t\t\t\tis_eof = cur == top;\n+\t\t\t}\n \t\t\tif (XDL_ALLOC_GROW(xdf->recs, (long)xdf->nrec + 1, narec))\n \t\t\t\tgoto abort;\n \t\t\tcrec = &xdf->recs[xdf->nrec++];\n \t\t\tcrec->ptr = prev;\n-\t\t\tcrec->size = cur - prev;\n+\t\t\tcrec->size = line_size;\n+\t\t\tcrec->match_ptr = NULL;\n+\t\t\tcrec->match_size = 0;\n+\t\t\tif (xpp->line_transform) {\n+\t\t\t\tif (xpp->line_transform((const char *)prev, line_size,\n+\t\t\t\t\t\tis_eof, &transformed,\n+\t\t\t\t\t\t&transformed_size,\n+\t\t\t\t\t\txpp->line_transform_data) < 0)\n+\t\t\t\t\tgoto abort;\n+\t\t\t\tcrec->match_ptr = transformed;\n+\t\t\t\tcrec->match_size = (size_t)transformed_size;\n+\t\t\t\ttransformed_ptr = (uint8_t *)transformed;\n+\t\t\t\thav = xdl_hash_record_verbatim(&transformed_ptr,\n+\t\t\t\t\ttransformed_ptr + transformed_size);\n+\t\t\t}\n \t\t\tif (xdl_classify_record(pass, cf, crec, hav) < 0)\n \t\t\t\tgoto abort;\n \t\t}\n@@ -442,7 +479,7 @@ int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,\n \tenl1 = xdl_guess_lines(mf1, sample) + 1;\n \tenl2 = xdl_guess_lines(mf2, sample) + 1;\n \n-\tif (xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0)\n+\tif (xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp) < 0)\n \t\treturn -1;\n \n \tif (xdl_prepare_ctx(1, mf1, enl1, xpp, &cf, &xe->xdf1) < 0) {\ndiff --git a/xdiff/xtypes.h b/xdiff/xtypes.h\nindex 50aee779be..714153a86e 100644\n--- a/xdiff/xtypes.h\n+++ b/xdiff/xtypes.h\n@@ -42,6 +42,8 @@ typedef struct s_xrecord {\n \tuint8_t const *ptr;\n \tsize_t size;\n \tsize_t minimal_perfect_hash;\n+\tchar *match_ptr;\n+\tsize_t match_size;\n } xrecord_t;\n \n typedef struct s_xdfile {\ndiff --git a/xdiff/xutils.c b/xdiff/xutils.c\nindex 4215f646c5..5b1c0edc3d 100644\n--- a/xdiff/xutils.c\n+++ b/xdiff/xutils.c\n@@ -249,6 +249,20 @@ int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags)\n \treturn 1;\n }\n \n+int xdl_recmatch_records(xrecord_t *rec1, xrecord_t *rec2,\n+\t\t\t xpparam_t const *xpp)\n+{\n+\tconst char *line1 = rec1->match_ptr ? rec1->match_ptr :\n+\t\t(const char *)rec1->ptr;\n+\tconst char *line2 = rec2->match_ptr ? rec2->match_ptr :\n+\t\t(const char *)rec2->ptr;\n+\tsize_t size1 = rec1->match_ptr ? rec1->match_size : rec1->size;\n+\tsize_t size2 = rec2->match_ptr ? rec2->match_size : rec2->size;\n+\n+\treturn xdl_recmatch(line1, (long)size1, line2, (long)size2,\n+\t\t\t    xpp->flags);\n+}\n+\n uint64_t xdl_hash_record_with_whitespace(uint8_t const **data,\n \t\tuint8_t const *top, uint64_t flags) {\n \tuint64_t ha = 5381;\ndiff --git a/xdiff/xutils.h b/xdiff/xutils.h\nindex 58f9d74cda..51217d99c6 100644\n--- a/xdiff/xutils.h\n+++ b/xdiff/xutils.h\n@@ -34,6 +34,8 @@ void *xdl_cha_alloc(chastore_t *cha);\n long xdl_guess_lines(mmfile_t *mf, long sample);\n int xdl_blankline(const char *line, long size, long flags);\n int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags);\n+int xdl_recmatch_records(xrecord_t *rec1, xrecord_t *rec2,\n+\t\t\t xpparam_t const *xpp);\n uint64_t xdl_hash_record_verbatim(uint8_t const **data, uint8_t const *top);\n uint64_t xdl_hash_record_with_whitespace(uint8_t const **data, uint8_t const *top, uint64_t flags);\n static inline uint64_t xdl_hash_record(uint8_t const **data, uint8_t const *top, uint64_t flags)\n-- \ngitgitgadget\n\n\n"},{"id":"559663","messageId":"5ddfdca00e646bdc87b0dd09ffbee2c9398f9b1e.1795996885.git.gitgitgadget@gmail.com","threadId":"66956","inReplyTo":"pull.2511.git.git.1795996885.gitgitgadget@gmail.com","subject":"[PATCH 2/4] merge-ort: fix whitespace in replayed changes","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-30T00:01:23Z","receivedAt":"2026-11-30T00:01:23Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"From: Alessio Attilio <attilio.alessio@protonmail.com>\n\nThe apply backend passes --whitespace=fix to git apply, which fixes\nintroduced lines while applying each commit.  The merge backend instead\nreplays commits through a three-way merge, so it needs to identify the\nresulting changes and fix them after merging.\n\nUse the path's whitespace rules to compare and repair changed lines in\nthe merge result.  Leave lines inherited from our side untouched, and\nhandle files added by the replayed commit as having an empty base.\n\nSigned-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n---\n merge-ll.c  | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++-\n merge-ll.h  |   5 ++\n merge-ort.c |  52 +++++++++++++++\n merge-ort.h |   1 +\n 4 files changed, 239 insertions(+), 1 deletion(-)\n\ndiff --git a/merge-ll.c b/merge-ll.c\nindex 996a38113f..a47aa7cb24 100644\n--- a/merge-ll.c\n+++ b/merge-ll.c\n@@ -18,6 +18,7 @@\n #include \"strbuf.h\"\n #include \"gettext.h\"\n #include \"tempfile.h\"\n+#include \"ws.h\"\n \n struct ll_merge_driver;\n \n@@ -101,6 +102,152 @@ static enum ll_merge_result ll_binary_merge(const struct ll_merge_driver *drv UN\n \treturn ret;\n }\n \n+struct whitespace_fix_data {\n+\tunsigned char *changed;\n+\tint line_nr;\n+};\n+\n+struct whitespace_transform_data {\n+\tunsigned ws_rule;\n+};\n+\n+static int transform_whitespace_record(const char *line, long len, int is_eof,\n+\t\t\t\t       char **transformed,\n+\t\t\t\t       long *transformed_len, void *data)\n+{\n+\tstruct whitespace_transform_data *transform = data;\n+\tstruct strbuf fixed = STRBUF_INIT;\n+\tsize_t size;\n+\n+\tif (is_eof && (transform->ws_rule & WS_BLANK_AT_EOF) &&\n+\t    ws_blank_line(line, len)) {\n+\t\t*transformed = xstrdup(\"\");\n+\t\t*transformed_len = 0;\n+\t\treturn 0;\n+\t}\n+\tws_fix_copy(&fixed, line, len,\n+\t\t    transform->ws_rule & ~WS_BLANK_AT_EOF, NULL);\n+\t*transformed = strbuf_detach(&fixed, &size);\n+\t*transformed_len = size;\n+\treturn 0;\n+}\n+\n+static int mark_whitespace_fix_hunk(void *data_, long old_begin UNUSED,\n+\t\t\t\t    long old_nr UNUSED, long new_begin,\n+\t\t\t\t    long new_nr, const char *func UNUSED,\n+\t\t\t\t    long funclen UNUSED)\n+{\n+\tstruct whitespace_fix_data *data = data_;\n+\tlong start = new_nr ? new_begin - 1 : new_begin;\n+\tlong i;\n+\n+\tfor (i = start; i < start + new_nr && i < data->line_nr; i++)\n+\t\tif (data->changed && i >= 0)\n+\t\t\tdata->changed[i] = 1;\n+\treturn 0;\n+}\n+\n+static int no_op_diff_line(void *data UNUSED, mmfile_t *mb UNUSED,\n+\t\t\t   int nbuf UNUSED)\n+{\n+\treturn 0;\n+}\n+\n+static size_t trim_blank_lines_at_eof(mmfile_t *file)\n+{\n+\tsize_t end = file->size;\n+\n+\twhile (end) {\n+\t\tsize_t start = end;\n+\t\tif (file->ptr[start - 1] == '\\n')\n+\t\t\tstart--;\n+\t\twhile (start && file->ptr[start - 1] != '\\n')\n+\t\t\tstart--;\n+\t\tif (!ws_blank_line(file->ptr + start, end - start))\n+\t\t\tbreak;\n+\t\tend = start;\n+\t}\n+\treturn end;\n+}\n+\n+static mmfile_t *trimmed_copy(mmfile_t *file, size_t size, mmfile_t *copy)\n+{\n+\tif (size == file->size)\n+\t\treturn file;\n+\tcopy->ptr = xmalloc(size ? size : 1);\n+\tmemcpy(copy->ptr, file->ptr, size);\n+\tcopy->size = size;\n+\treturn copy;\n+}\n+\n+int ll_merge_fix_whitespace(mmfile_t *result, mmfile_t *ours,\n+\t\t\t    unsigned ws_rule)\n+{\n+\tstruct whitespace_fix_data data = { 0 };\n+\tstruct strbuf fixed = STRBUF_INIT;\n+\txpparam_t xpp = { 0 };\n+\txdemitconf_t xecfg = { .ctxlen = 0 };\n+\txdemitcb_t ecb = {\n+\t\t.out_hunk = mark_whitespace_fix_hunk,\n+\t\t.out_line = no_op_diff_line,\n+\t\t.priv = &data,\n+\t};\n+\tsize_t pos = 0, cut = result->size;\n+\tint ret = -1, i = 0;\n+\n+\tfor (pos = 0; pos < result->size; pos++)\n+\t\tif (result->ptr[pos] == '\\n')\n+\t\t\ti++;\n+\tif (result->size && result->ptr[result->size - 1] != '\\n')\n+\t\ti++;\n+\tdata.line_nr = i;\n+\tCALLOC_ARRAY(data.changed, data.line_nr);\n+\tif (xdi_diff(ours, result, &xpp, &xecfg, &ecb))\n+\t\tgoto out;\n+\n+\tif (ws_rule & WS_BLANK_AT_EOF) {\n+\t\tint line = data.line_nr;\n+\t\tpos = result->size;\n+\t\twhile (line > 0 && data.changed[line - 1]) {\n+\t\t\tsize_t start = pos;\n+\t\t\tif (start > 0 && result->ptr[start - 1] == '\\n')\n+\t\t\t\tstart--;\n+\t\t\twhile (start > 0 && result->ptr[start - 1] != '\\n')\n+\t\t\t\tstart--;\n+\t\t\tif (!ws_blank_line(result->ptr + start, pos - start))\n+\t\t\t\tbreak;\n+\t\t\tcut = start;\n+\t\t\tpos = start;\n+\t\t\tline--;\n+\t\t}\n+\t}\n+\n+\tstrbuf_init(&fixed, result->size);\n+\tpos = 0;\n+\tfor (i = 0; i < data.line_nr; i++) {\n+\t\tsize_t end = pos;\n+\t\twhile (end < cut && result->ptr[end] != '\\n')\n+\t\t\tend++;\n+\t\tif (end < cut)\n+\t\t\tend++;\n+\t\tif (data.changed[i])\n+\t\t\tws_fix_copy(&fixed, result->ptr + pos, end - pos,\n+\t\t\t\t    ws_rule, NULL);\n+\t\telse\n+\t\t\tstrbuf_add(&fixed, result->ptr + pos, end - pos);\n+\t\tpos = end;\n+\t}\n+\tif (pos < cut)\n+\t\tstrbuf_add(&fixed, result->ptr + pos, cut - pos);\n+\tfree(result->ptr);\n+\tresult->ptr = strbuf_detach(&fixed, &result->size);\n+\tret = 0;\n+out:\n+\tstrbuf_release(&fixed);\n+\tfree(data.changed);\n+\treturn ret;\n+}\n+\n static enum ll_merge_result ll_xdl_merge(const struct ll_merge_driver *drv_unused,\n \t\t\tmmfile_t *result,\n \t\t\tconst char *path,\n@@ -112,8 +259,14 @@ static enum ll_merge_result ll_xdl_merge(const struct ll_merge_driver *drv_unuse\n {\n \tenum ll_merge_result ret;\n \txmparam_t xmp;\n+\tmmfile_t orig_copy = { 0 }, src1_copy = { 0 }, src2_copy = { 0 };\n+\tmmfile_t *merge_orig = orig, *merge_src1 = src1, *merge_src2 = src2;\n+\tsize_t src1_size;\n \tint status;\n+\tstruct whitespace_transform_data transform_data;\n \tassert(opts);\n+\tsrc1_size = src1->size;\n+\ttransform_data.ws_rule = opts->whitespace_rule;\n \n \tif (orig->size > MAX_XDIFF_SIZE ||\n \t    src1->size > MAX_XDIFF_SIZE ||\n@@ -133,6 +286,19 @@ static enum ll_merge_result ll_xdl_merge(const struct ll_merge_driver *drv_unuse\n \txmp.level = XDL_MERGE_ZEALOUS;\n \txmp.favor = opts->variant;\n \txmp.xpp.flags = opts->xdl_opts;\n+\tif (opts->whitespace_fix) {\n+\t\txmp.xpp.line_transform = transform_whitespace_record;\n+\t\txmp.xpp.line_transform_data = &transform_data;\n+\t\tif (opts->whitespace_rule & WS_BLANK_AT_EOF) {\n+\t\t\tmerge_orig = trimmed_copy(orig,\n+\t\t\t\ttrim_blank_lines_at_eof(orig), &orig_copy);\n+\t\t\tmerge_src1 = trimmed_copy(src1,\n+\t\t\t\ttrim_blank_lines_at_eof(src1), &src1_copy);\n+\t\t\tmerge_src2 = trimmed_copy(src2,\n+\t\t\t\ttrim_blank_lines_at_eof(src2), &src2_copy);\n+\t\t\tsrc1_size = merge_src1->size;\n+\t\t}\n+\t}\n \tif (opts->conflict_style >= 0)\n \t\txmp.style = opts->conflict_style;\n \telse if (git_xmerge_style >= 0)\n@@ -142,8 +308,22 @@ static enum ll_merge_result ll_xdl_merge(const struct ll_merge_driver *drv_unuse\n \txmp.ancestor = orig_name;\n \txmp.file1 = name1;\n \txmp.file2 = name2;\n-\tstatus = xdl_merge(orig, src1, src2, &xmp, result);\n+\tstatus = xdl_merge(merge_orig, merge_src1, merge_src2, &xmp, result);\n \tret = (status > 0) ? LL_MERGE_CONFLICT : status;\n+\tif (opts->whitespace_fix && status >= 0) {\n+\t\tif (src1_size < src1->size) {\n+\t\t\tsize_t suffix_size = src1->size - src1_size;\n+\t\t\tresult->ptr = xrealloc(result->ptr, result->size + suffix_size);\n+\t\t\tmemcpy(result->ptr + result->size,\n+\t\t\t       src1->ptr + src1_size, suffix_size);\n+\t\t\tresult->size += suffix_size;\n+\t\t}\n+\t\tif (ll_merge_fix_whitespace(result, src1, opts->whitespace_rule))\n+\t\t\tret = LL_MERGE_ERROR;\n+\t}\n+\tfree(orig_copy.ptr);\n+\tfree(src1_copy.ptr);\n+\tfree(src2_copy.ptr);\n \treturn ret;\n }\n \ndiff --git a/merge-ll.h b/merge-ll.h\nindex f95332c682..5a81aa2d65 100644\n--- a/merge-ll.h\n+++ b/merge-ll.h\n@@ -83,6 +83,8 @@ struct ll_merge_options {\n \n \t/* Extra xpparam_t flags as defined in xdiff/xdiff.h. */\n \tlong xdl_opts;\n+\tunsigned whitespace_fix : 1;\n+\tunsigned whitespace_rule;\n };\n \n #define LL_MERGE_OPTIONS_INIT { .conflict_style = -1 }\n@@ -108,6 +110,9 @@ enum ll_merge_result ll_merge(mmfile_t *result_buf,\n \t     struct index_state *istate,\n \t     const struct ll_merge_options *opts);\n \n+int ll_merge_fix_whitespace(mmfile_t *result, mmfile_t *ours,\n+\t\t\t    unsigned ws_rule);\n+\n int ll_merge_marker_size(struct index_state *istate, const char *path);\n int is_conflict_marker_line(const char *line, unsigned long len, int marker_size);\n int has_conflict_markers(struct index_state *istate, const char *path);\ndiff --git a/merge-ort.c b/merge-ort.c\nindex 1383f7b256..912df3cb9e 100644\n--- a/merge-ort.c\n+++ b/merge-ort.c\n@@ -52,6 +52,7 @@\n #include \"trace2.h\"\n #include \"tree.h\"\n #include \"unpack-trees.h\"\n+#include \"ws.h\"\n #include \"xdiff-interface.h\"\n \n /*\n@@ -1260,6 +1261,11 @@ static void collect_rename_info(struct merge_options *opt,\n \t}\n }\n \n+static int fix_blob_whitespace(struct merge_options *opt,\n+\t\t\t       const struct object_id *base_oid,\n+\t\t\t       struct object_id *result_oid,\n+\t\t\t       const char *path);\n+\n static int collect_merge_info_callback(int n,\n \t\t\t\t       unsigned long mask,\n \t\t\t\t       unsigned long dirmask,\n@@ -1385,6 +1391,11 @@ static int collect_merge_info_callback(int n,\n \t * destinations within side2.\n \t */\n \tif (side1_matches_mbase && filemask == 0x07) {\n+\t\tif (opt->whitespace_fix && S_ISREG(names[2].mode)) {\n+\t\t\tif (fix_blob_whitespace(opt, &names[0].oid, &names[2].oid,\n+\t\t\t\t\t\tfullpath))\n+\t\t\t\treturn -1;\n+\t\t}\n \t\t/* use side2 version as resolution */\n \t\tif (setup_path_info(opt, &pi, dirname, info->pathlen, fullpath,\n \t\t\t\t    names, names+2, side2_null, 0,\n@@ -2128,6 +2139,10 @@ static int merge_3way(struct merge_options *opt,\n \tll_opts.renormalize = opt->renormalize;\n \tll_opts.extra_marker_size = extra_marker_size;\n \tll_opts.xdl_opts = opt->xdl_opts;\n+\tll_opts.whitespace_fix = opt->whitespace_fix;\n+\tif (ll_opts.whitespace_fix)\n+\t\tll_opts.whitespace_rule = whitespace_rule(opt->repo->index,\n+\t\t\t\t\t\t\t  path);\n \tll_opts.conflict_style = opt->conflict_style;\n \n \tif (opt->priv->call_depth) {\n@@ -2180,6 +2195,30 @@ static int merge_3way(struct merge_options *opt,\n \treturn merge_status;\n }\n \n+static int fix_blob_whitespace(struct merge_options *opt,\n+\t\t\t       const struct object_id *base_oid,\n+\t\t\t       struct object_id *result_oid,\n+\t\t\t       const char *path)\n+{\n+\tmmfile_t base = { 0 }, result;\n+\tstruct object_id fixed_oid;\n+\tint ret;\n+\n+\tif (!is_null_oid(base_oid))\n+\t\tread_mmblob(&base, opt->repo->objects, base_oid);\n+\tread_mmblob(&result, opt->repo->objects, result_oid);\n+\tret = ll_merge_fix_whitespace(&result, &base,\n+\t\t\t\t      whitespace_rule(opt->repo->index, path));\n+\tif (!ret)\n+\t\tret = odb_write_object(opt->repo->objects, result.ptr, result.size,\n+\t\t\t\t\tOBJ_BLOB, &fixed_oid);\n+\tif (!ret)\n+\t\toidcpy(result_oid, &fixed_oid);\n+\tfree(base.ptr);\n+\tfree(result.ptr);\n+\treturn ret;\n+}\n+\n static int handle_content_merge(struct merge_options *opt,\n \t\t\t\tconst char *path,\n \t\t\t\tconst struct version_info *o,\n@@ -4222,6 +4261,12 @@ static int process_entry(struct merge_options *opt,\n \t\t\tif (ci->merged.is_null)\n \t\t\t\tci->merged.clean = 1;\n \t\t\toidcpy(&ci->merged.result.oid, &ci->stages[side].oid);\n+\t\t\tif (side == 2 && opt->whitespace_fix &&\n+\t\t\t    S_ISREG(ci->merged.result.mode)) {\n+\t\t\t\tif (fix_blob_whitespace(opt, &ci->stages[0].oid,\n+\t\t\t\t\t\t\t&ci->merged.result.oid, path))\n+\t\t\t\t\treturn -1;\n+\t\t\t}\n \n \t\t\tassert(othermask == 2 || othermask == 4);\n \t\t\tassert(ci->merged.is_null ==\n@@ -4428,6 +4473,11 @@ static int process_entry(struct merge_options *opt,\n \t\tint side = (ci->filemask == 4) ? 2 : 1;\n \t\tci->merged.result.mode = ci->stages[side].mode;\n \t\toidcpy(&ci->merged.result.oid, &ci->stages[side].oid);\n+\t\tif (side == 2 && opt->whitespace_fix &&\n+\t\t    S_ISREG(ci->merged.result.mode) &&\n+\t\t    fix_blob_whitespace(opt, null_oid(opt->repo->hash_algo),\n+\t\t\t\t\t&ci->merged.result.oid, path))\n+\t\t\treturn -1;\n \t\tci->merged.clean = !ci->df_conflict && !ci->path_conflict;\n \t} else if (ci->filemask == 1) {\n \t\t/* Deleted on both sides */\n@@ -5598,6 +5648,8 @@ int parse_merge_opt(struct merge_options *opt, const char *s)\n \t\tDIFF_XDL_SET(opt, IGNORE_WHITESPACE_AT_EOL);\n \telse if (!strcmp(s, \"ignore-cr-at-eol\"))\n \t\tDIFF_XDL_SET(opt, IGNORE_CR_AT_EOL);\n+\telse if (!strcmp(s, \"whitespace=fix\"))\n+\t\topt->whitespace_fix = 1;\n \telse if (!strcmp(s, \"renormalize\"))\n \t\topt->renormalize = 1;\n \telse if (!strcmp(s, \"no-renormalize\"))\ndiff --git a/merge-ort.h b/merge-ort.h\nindex 6045579825..e446600fee 100644\n--- a/merge-ort.h\n+++ b/merge-ort.h\n@@ -67,6 +67,7 @@ struct merge_options {\n \n \t/* xdiff-related options (patience, ignore whitespace, ours/theirs) */\n \tlong xdl_opts;\n+\tunsigned whitespace_fix : 1;\n \tint conflict_style;\n \tenum {\n \t\tMERGE_VARIANT_NORMAL = 0,\n-- \ngitgitgadget\n\n\n"},{"id":"559664","messageId":"46631ec7de84667a7047fc4401b2f156ed64b2cb.1795996885.git.gitgitgadget@gmail.com","threadId":"66956","inReplyTo":"pull.2511.git.git.1795996885.gitgitgadget@gmail.com","subject":"[PATCH 3/4] rebase: route whitespace fixes through the selected backend","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-30T00:01:24Z","receivedAt":"2026-11-30T00:01:24Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"From: Alessio Attilio <attilio.alessio@protonmail.com>\n\n--whitespace has historically implied the apply backend because its\nvalue was forwarded directly to git apply.  With whitespace=fix\navailable in the merge backend, keep apply-specific actions on that\nbackend while allowing fix to reach merge and interactive rebases.\n\nValidate the action before selecting a backend, pass fix to the merge\nstrategy when needed, and document the backend-specific behavior.  Keep\nother whitespace actions unsupported with the merge backend.  Update\nthe incompatibility tests so the newly supported combinations are\nexpected to succeed.\n\nSigned-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n---\n Documentation/git-rebase.adoc          |  6 +--\n builtin/rebase.c                       | 55 +++++++++++++++++++++++---\n contrib/completion/git-completion.bash |  2 +-\n t/t3422-rebase-incompatible-options.sh | 17 +++++++-\n 4 files changed, 69 insertions(+), 11 deletions(-)\n\ndiff --git a/Documentation/git-rebase.adoc b/Documentation/git-rebase.adoc\nindex 2f0c6fbbd1..1d4c729e3f 100644\n--- a/Documentation/git-rebase.adoc\n+++ b/Documentation/git-rebase.adoc\n@@ -466,9 +466,9 @@ merge backend;;\n \tother side had no changes that conflicted.\n \n --whitespace=<option>::\n-\tThis flag is passed to the `git apply` program\n-\t(see linkgit:git-apply[1]) that applies the patch.\n-\tImplies `--apply`.\n+\tIn the apply backend, this flag is passed to the `git apply` program\n+\t(see linkgit:git-apply[1]) that applies the patch and implies `--apply`.\n+\tThe merge backend supports only `fix`.\n +\n See also <<INCOMPATIBLE_OPTIONS,INCOMPATIBLE OPTIONS>> below.\n \ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 535db60181..3512fe2e14 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -405,6 +405,30 @@ static int is_merge(struct rebase_options *opts)\n \treturn opts->type == REBASE_MERGE;\n }\n \n+static int rebase_whitespace_uses_apply_backend(\n+\tconst struct rebase_options *opts, const char *strategy_opt)\n+{\n+\tif (opts->type == REBASE_APPLY)\n+\t\treturn 1;\n+\tif (opts->type != REBASE_UNSPECIFIED)\n+\t\treturn 0;\n+\treturn !strcmp(opts->default_backend, \"apply\") &&\n+\t\t!(opts->flags & REBASE_INTERACTIVE_EXPLICIT) &&\n+\t\t!(opts->root && !opts->onto_name) &&\n+\t\topts->rebase_merges != 1 &&\n+\t\topts->config_rebase_merges != 1 &&\n+\t\t!opts->strategy &&\n+\t\t!strategy_opt &&\n+\t\t!opts->strategy_opts.nr &&\n+\t\t!opts->exec.nr &&\n+\t\topts->empty == EMPTY_UNSPECIFIED &&\n+\t\topts->autosquash != 1 &&\n+\t\topts->update_refs != 1 &&\n+\t\topts->config_update_refs != 1 &&\n+\t\t!opts->trailer_args.nr &&\n+\t\topts->reapply_cherry_picks != 1;\n+}\n+\n static void imply_merge(struct rebase_options *opts, const char *option)\n {\n \tswitch (opts->type) {\n@@ -1119,6 +1143,8 @@ int cmd_rebase(int argc,\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct object_id branch_base;\n \tint ignore_whitespace = 0;\n+\tint whitespace_uses_apply_backend = 0;\n+\tconst char *whitespace = NULL;\n \tconst char *gpg_sign = NULL;\n \tstruct object_id squash_onto;\n \tchar *squash_onto_name = NULL;\n@@ -1166,8 +1192,8 @@ int cmd_rebase(int argc,\n \t\t\t\t  N_(\"passed to 'git apply'\"), 0),\n \t\tOPT_BOOL(0, \"ignore-whitespace\", &ignore_whitespace,\n \t\t\t N_(\"ignore changes in whitespace\")),\n-\t\tOPT_PASSTHRU_ARGV(0, \"whitespace\", &options.git_am_opts,\n-\t\t\t\t  N_(\"action\"), N_(\"passed to 'git apply'\"), 0),\n+\t\tOPT_STRING(0, \"whitespace\", &whitespace, N_(\"action\"),\n+\t\t\t   N_(\"specify how to handle whitespace errors\")),\n \t\tOPT_BIT('f', \"force-rebase\", &options.flags,\n \t\t\tN_(\"cherry-pick all commits, even if unchanged\"),\n \t\t\tREBASE_FORCE),\n@@ -1488,6 +1514,16 @@ int cmd_rebase(int argc,\n \t}\n \tif (options.committer_date_is_author_date || options.ignore_date)\n \t\toptions.flags |= REBASE_FORCE;\n+\tif (whitespace) {\n+\t\tif (strcmp(whitespace, \"fix\") && strcmp(whitespace, \"warn\") &&\n+\t\t    strcmp(whitespace, \"nowarn\") &&\n+\t\t    strcmp(whitespace, \"error\") && strcmp(whitespace, \"error-all\"))\n+\t\t\tdie(\"Invalid whitespace option: '%s'\", whitespace);\n+\t\tif (!strcmp(whitespace, \"fix\")) {\n+\t\t\tallow_preemptive_ff = 0;\n+\t\t\toptions.flags |= REBASE_FORCE;\n+\t\t}\n+\t}\n \n \tfor (i = 0; i < options.git_am_opts.nr; i++) {\n \t\tconst char *option = options.git_am_opts.v[i], *p;\n@@ -1499,10 +1535,6 @@ int cmd_rebase(int argc,\n \t\t\t\tif (!isdigit(*(p++)))\n \t\t\t\t\tdie(_(\"switch `C' expects a \"\n \t\t\t\t\t      \"numerical value\"));\n-\t\t} else if (skip_prefix(option, \"--whitespace=\", &p)) {\n-\t\t\tif (*p && strcmp(p, \"warn\") && strcmp(p, \"nowarn\") &&\n-\t\t\t    strcmp(p, \"error\") && strcmp(p, \"error-all\"))\n-\t\t\t\tdie(\"Invalid whitespace option: '%s'\", p);\n \t\t}\n \t}\n \n@@ -1544,6 +1576,11 @@ int cmd_rebase(int argc,\n \tif (options.exec.nr)\n \t\timply_merge(&options, \"--exec\");\n \n+\twhitespace_uses_apply_backend =\n+\t\trebase_whitespace_uses_apply_backend(&options, strategy_opt);\n+\tif (whitespace && whitespace_uses_apply_backend)\n+\t\tstrvec_pushf(&options.git_am_opts, \"--whitespace=%s\", whitespace);\n+\n \tif (options.type == REBASE_APPLY) {\n \t\tif (ignore_whitespace)\n \t\t\tstrvec_push(&options.git_am_opts,\n@@ -1555,6 +1592,12 @@ int cmd_rebase(int argc,\n \t\t\tstrvec_push(&options.git_am_opts, \"--ignore-date\");\n \t} else {\n \t\t/* REBASE_MERGE */\n+\t\tif (whitespace && !whitespace_uses_apply_backend &&\n+\t\t    !strcmp(whitespace, \"fix\"))\n+\t\t\tstring_list_append(&options.strategy_opts, \"whitespace=fix\");\n+\t\telse if (whitespace && !whitespace_uses_apply_backend)\n+\t\t\tdie(_(\"--whitespace=%s is not supported with the merge backend\"),\n+\t\t\t    whitespace);\n \t\tif (ignore_whitespace) {\n \t\t\tstring_list_append(&options.strategy_opts,\n \t\t\t\t\t   \"ignore-space-change\");\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex a7f1da040a..187de33708 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1091,7 +1091,7 @@ __git_compute_merge_strategies ()\n __git_merge_strategy_options=\"ours theirs subtree subtree= patience\n \thistogram diff-algorithm= ignore-space-change ignore-all-space\n \tignore-space-at-eol renormalize no-renormalize no-renames\n-\tfind-renames find-renames= rename-threshold=\"\n+\tfind-renames find-renames= rename-threshold= whitespace=fix\"\n \n __git_complete_revlist_file ()\n {\ndiff --git a/t/t3422-rebase-incompatible-options.sh b/t/t3422-rebase-incompatible-options.sh\nindex d6830b82e0..f955309ce8 100755\n--- a/t/t3422-rebase-incompatible-options.sh\n+++ b/t/t3422-rebase-incompatible-options.sh\n@@ -125,7 +125,22 @@ test_rebase_am_only () {\n }\n \n # Check options which imply --apply\n-test_rebase_am_only --whitespace=fix\n+test_expect_success '--whitespace=fix works with --merge' '\n+\tgit checkout B^0 &&\n+\tgit rebase --whitespace=fix --merge A &&\n+\ttest_seq 1 9 >expect &&\n+\techo \"q qfoo();\" >>expect &&\n+\ttest_cmp expect foo\n+'\n+\n+test_expect_success '--whitespace=fix works with --interactive' '\n+\tgit checkout B^0 &&\n+\tGIT_SEQUENCE_EDITOR=: git rebase --whitespace=fix --interactive A &&\n+\ttest_seq 1 9 >expect &&\n+\techo \"q qfoo();\" >>expect &&\n+\ttest_cmp expect foo\n+'\n+\n test_rebase_am_only -C4\n # Also check an explicit --apply\n test_rebase_am_only --apply\n-- \ngitgitgadget\n\n\n"},{"id":"559665","messageId":"e462455723a5bb021093bae98603ab32e5cf49c8.1795996885.git.gitgitgadget@gmail.com","threadId":"66956","inReplyTo":"pull.2511.git.git.1795996885.gitgitgadget@gmail.com","subject":"[PATCH 4/4] rebase: test whitespace fixes with the merge backend","fromName":"Alessio Attilio via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-30T00:01:25Z","receivedAt":"2026-11-30T00:01:25Z","isPatch":true,"sender":{"key":"name:Alessio Attilio","avatar":null},"body":"From: Alessio Attilio <attilio.alessio@protonmail.com>\n\nExercise whitespace=fix while replaying commits with the merge backend,\nincluding interactive use, attribute rules, existing whitespace in the\nbase, added files, and whitespace at end of file.  Also check that the\noption remains rejected with the merge backend for actions it does not\nsupport.\n\nThese tests cover the user-visible behavior across both backend\nselection and merge replay, guarding against fixing unchanged context or\nregressing the apply backend.\n\nSigned-off-by: Alessio Attilio <attilio.alessio@protonmail.com>\n---\n t/t3417-rebase-whitespace-fix.sh | 163 +++++++++++++++++++++++++++++++\n 1 file changed, 163 insertions(+)\n\ndiff --git a/t/t3417-rebase-whitespace-fix.sh b/t/t3417-rebase-whitespace-fix.sh\nindex 96f2cf22fa..c65b5c1e37 100755\n--- a/t/t3417-rebase-whitespace-fix.sh\n+++ b/t/t3417-rebase-whitespace-fix.sh\n@@ -94,6 +94,169 @@ test_expect_success 'same, but do not remove trailing spaces' '\n \ttest_cmp file third\n '\n \n+test_expect_success 'interactive rebase fixes whitespace' '\n+\tgit config core.whitespace blank-at-eol &&\n+\tgit checkout -b interactive-whitespace HEAD^ &&\n+\ttest_write_lines \"clean\" >file &&\n+\tgit commit -am clean &&\n+\ttest_write_lines \"trailing \" >>file &&\n+\tgit commit -am \"add whitespace errors\" &&\n+\twrite_script sequence-editor <<-\\EOF &&\n+\tsed -e \"s/^pick/pick/\" \"$1\" >\"$1.tmp\" &&\n+\tmv \"$1.tmp\" \"$1\"\n+\tEOF\n+\tGIT_SEQUENCE_EDITOR=./sequence-editor git rebase -i --whitespace=fix HEAD^^ &&\n+\ttest_write_lines clean \"trailing\" >expect &&\n+\ttest_cmp expect file\n+'\n+\n+test_expect_success 'interactive rebase fixes whitespace in upstream context' '\n+\ttest_create_repo context &&\n+\t(\n+\t\tcd context &&\n+\t\ttest_write_lines one \"two \" three >file &&\n+\t\tgit add file && git commit -m base &&\n+\t\tgit checkout -b topic &&\n+\t\ttest_write_lines one two THREE >file &&\n+\t\tgit commit -am topic &&\n+\t\tgit checkout -b upstream HEAD^ &&\n+\t\ttest_write_lines one two three >file &&\n+\t\tgit commit -am whitespace &&\n+\t\tgit checkout topic &&\n+\t\twrite_script sequence-editor <<-\\EOF &&\n+\t\tsed -e \"s/^pick/pick/\" \"$1\" >\"$1.tmp\" &&\n+\t\tmv \"$1.tmp\" \"$1\"\n+\t\tEOF\n+\t\tGIT_SEQUENCE_EDITOR=./sequence-editor \\\n+\t\t\tgit rebase -i --whitespace=fix upstream &&\n+\t\ttest_write_lines one two THREE >expect &&\n+\t\ttest_cmp expect file\n+\t)\n+'\n+\n+test_expect_success 'interactive rebase preserves other whitespace changes' '\n+\ttest_create_repo preserve &&\n+\t(\n+\t\tcd preserve &&\n+\t\tgit config core.whitespace blank-at-eol &&\n+\t\ttest_write_lines one \"two \" three >file &&\n+\t\tgit add file && git commit -m base &&\n+\t\tgit checkout -b topic &&\n+\t\tprintf \" one\\ntwo \\nthree \\n\" >file &&\n+\t\tgit commit -am topic &&\n+\t\tgit checkout -b upstream HEAD^ &&\n+\t\tprintf \"one\\ntwo\\nthree\\n\" >file &&\n+\t\tgit commit -am whitespace &&\n+\t\tgit checkout topic &&\n+\t\twrite_script sequence-editor <<-\\EOF &&\n+\t\tsed -e \"s/^pick/pick/\" \"$1\" >\"$1.tmp\" &&\n+\t\tmv \"$1.tmp\" \"$1\"\n+\t\tEOF\n+\t\tGIT_SEQUENCE_EDITOR=./sequence-editor \\\n+\t\t\tgit rebase -i --whitespace=fix upstream &&\n+\t\tprintf \" one\\ntwo\\nthree\\n\" >expect &&\n+\t\ttest_cmp expect file\n+\t)\n+'\n+\n+test_expect_success 'interactive rebase rejects unsupported whitespace actions' '\n+\ttest_create_repo unsupported &&\n+\t(\n+\t\tcd unsupported &&\n+\t\ttest_write_lines base >file &&\n+\t\tgit add file && git commit -m base &&\n+\t\ttest_write_lines change >>file &&\n+\t\tgit commit -am change &&\n+\t\ttest_must_fail env GIT_SEQUENCE_EDITOR=: \\\n+\t\t\tgit rebase -i --whitespace=warn HEAD^\n+\t)\n+'\n+\n+test_expect_success 'interactive rebase fixes blank-at-eof' '\n+\ttest_create_repo eof &&\n+\t(\n+\t\tcd eof &&\n+\t\ttest_write_lines one >file &&\n+\t\tgit add file && git commit -m base &&\n+\t\ttest_write_lines one two >file &&\n+\t\tprintf \"\\n\\n\" >>file &&\n+\t\tgit commit -am whitespace &&\n+\t\twrite_script sequence-editor <<-\\EOF &&\n+\t\tsed -e \"s/^pick/pick/\" \"$1\" >\"$1.tmp\" &&\n+\t\tmv \"$1.tmp\" \"$1\"\n+\t\tEOF\n+\t\tGIT_SEQUENCE_EDITOR=./sequence-editor \\\n+\t\t\tgit rebase -i --whitespace=fix HEAD^ &&\n+\t\ttest_write_lines one two >expect &&\n+\t\ttest_cmp expect file\n+\t)\n+'\n+\n+test_expect_success 'interactive rebase handles upstream blank-at-eof fixes' '\n+\ttest_create_repo eof-context &&\n+\t(\n+\t\tcd eof-context &&\n+\t\ttest_write_lines one >file &&\n+\t\tprintf \"\\n\\n\" >>file &&\n+\t\tgit add file && git commit -m base &&\n+\t\tgit checkout -b topic &&\n+\t\ttest_write_lines one two >file &&\n+\t\tprintf \"\\n\\n\" >>file &&\n+\t\tgit commit -am topic &&\n+\t\tgit checkout -b upstream HEAD^ &&\n+\t\ttest_write_lines one >file &&\n+\t\tgit commit -am whitespace &&\n+\t\tgit checkout topic &&\n+\t\twrite_script sequence-editor <<-\\EOF &&\n+\t\tsed -e \"s/^pick/pick/\" \"$1\" >\"$1.tmp\" &&\n+\t\tmv \"$1.tmp\" \"$1\"\n+\t\tEOF\n+\t\tGIT_SEQUENCE_EDITOR=./sequence-editor \\\n+\t\t\tgit rebase -i --whitespace=fix upstream &&\n+\t\ttest_write_lines one two >expect &&\n+\t\ttest_cmp expect file\n+\t)\n+'\n+\n+test_expect_success 'interactive rebase honors path whitespace rules' '\n+\ttest_create_repo attr &&\n+\t(\n+\t\tcd attr &&\n+\t\techo \"file whitespace=-blank-at-eol\" >.gitattributes &&\n+\t\ttest_write_lines one >file &&\n+\t\tgit add .gitattributes file && git commit -m base &&\n+\t\tprintf \"one \\n\" >file &&\n+\t\tgit commit -am whitespace &&\n+\t\twrite_script sequence-editor <<-\\EOF &&\n+\t\tsed -e \"s/^pick/pick/\" \"$1\" >\"$1.tmp\" &&\n+\t\tmv \"$1.tmp\" \"$1\"\n+\t\tEOF\n+\t\tGIT_SEQUENCE_EDITOR=./sequence-editor \\\n+\t\t\tgit rebase -i --whitespace=fix HEAD^ &&\n+\t\tprintf \"one \\n\" >expect &&\n+\t\ttest_cmp expect file\n+\t)\n+'\n+\n+test_expect_success 'interactive rebase fixes whitespace in added files' '\n+\ttest_create_repo added &&\n+\t(\n+\t\tcd added &&\n+\t\ttest_write_lines base >file &&\n+\t\tgit add file && git commit -m base &&\n+\t\tprintf \"new file with whitespace \\n\" >new-file &&\n+\t\tgit add new-file && git commit -m add &&\n+\t\twrite_script sequence-editor <<-\\EOF &&\n+\t\tsed -e \"s/^pick/pick/\" \"$1\" >\"$1.tmp\" &&\n+\t\tmv \"$1.tmp\" \"$1\"\n+\t\tEOF\n+\t\tGIT_SEQUENCE_EDITOR=./sequence-editor \\\n+\t\t\tgit rebase -i --whitespace=fix HEAD^ &&\n+\t\tprintf \"new file with whitespace\\n\" >expect &&\n+\t\ttest_cmp expect new-file\n+\t)\n+'\n+\n sed -e's/Z//' >beginning <<EOF\n a\n \t\t    Z\n-- \ngitgitgadget\n\n"}]}