Git development
 help / color / mirror / Atom feed
* [PATCH 0/4] rebase: support --whitespace=fix with --interactive
@ 2026-11-30  0:01 Alessio Attilio via GitGitGadget
  2026-11-30  0:01 ` [PATCH 1/4] xdiff: support transformed records in merge matching Alessio Attilio via GitGitGadget
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Alessio Attilio via GitGitGadget @ 2026-11-30  0:01 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin, Alessio Attilio

The apply backend implements --whitespace=fix through git apply, which
prevents users from combining it with interactive rebases and other
merge-backend features. Teach merge replay to compare whitespace-normalized
records, then fix only lines introduced by replay using the path's
whitespace rules. Keep other whitespace actions on the apply backend.

Tests cover interactive replay, attributes, existing whitespace, added
files, end-of-file handling, and unsupported actions.

Closes gitgitgadget/git#1472

Alessio Attilio (4):
  xdiff: support transformed records in merge matching
  merge-ort: fix whitespace in replayed changes
  rebase: route whitespace fixes through the selected backend
  rebase: test whitespace fixes with the merge backend

 Documentation/git-rebase.adoc          |   6 +-
 builtin/rebase.c                       |  55 +++++++-
 contrib/completion/git-completion.bash |   2 +-
 merge-ll.c                             | 182 ++++++++++++++++++++++++-
 merge-ll.h                             |   5 +
 merge-ort.c                            |  52 +++++++
 merge-ort.h                            |   1 +
 t/t3417-rebase-whitespace-fix.sh       | 163 ++++++++++++++++++++++
 t/t3422-rebase-incompatible-options.sh |  17 ++-
 xdiff/xdiff.h                          |   4 +
 xdiff/xmerge.c                         |  16 +--
 xdiff/xprepare.c                       |  57 ++++++--
 xdiff/xtypes.h                         |   2 +
 xdiff/xutils.c                         |  14 ++
 xdiff/xutils.h                         |   2 +
 15 files changed, 547 insertions(+), 31 deletions(-)


base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2511%2Fkairosci%2Fds%2Frebase-whitespace-fix-merge-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2511/kairosci/ds/rebase-whitespace-fix-merge-v1
Pull-Request: https://github.com/git/git/pull/2511
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] xdiff: support transformed records in merge matching
  2026-11-30  0:01 [PATCH 0/4] rebase: support --whitespace=fix with --interactive Alessio Attilio via GitGitGadget
@ 2026-11-30  0:01 ` Alessio Attilio via GitGitGadget
  2026-11-30  0:01 ` [PATCH 2/4] merge-ort: fix whitespace in replayed changes Alessio Attilio via GitGitGadget
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Alessio Attilio via GitGitGadget @ 2026-11-30  0:01 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin, Alessio Attilio, Alessio Attilio

From: Alessio Attilio <attilio.alessio@protonmail.com>

The merge backend compares lines from both sides before deciding whether
changes overlap.  Whitespace fixes can make otherwise identical lines
differ, so let xdiff compare transformed records while retaining the
original records for output.

Add an optional line transformation to xdiff's record preparation and use
the transformed bytes for hashing and matching.  Keeping transformation
separate from the source records lets callers normalize only for matching
without changing unchanged text in the result.

Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
---
 xdiff/xdiff.h    |  4 ++++
 xdiff/xmerge.c   | 16 ++++++--------
 xdiff/xprepare.c | 57 +++++++++++++++++++++++++++++++++++++++---------
 xdiff/xtypes.h   |  2 ++
 xdiff/xutils.c   | 14 ++++++++++++
 xdiff/xutils.h   |  2 ++
 6 files changed, 76 insertions(+), 19 deletions(-)

diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h
index 8fa513fc4e..07c15c630e 100644
--- a/xdiff/xdiff.h
+++ b/xdiff/xdiff.h
@@ -73,6 +73,8 @@ typedef struct s_mmfile {
 	size_t size;
 } mmfile_t;
 
+typedef int (*xdl_line_transform_fn)(const char *, long, int, char **, long *, void *);
+
 typedef struct s_xpparam {
 	unsigned long flags;
 
@@ -83,6 +85,8 @@ typedef struct s_xpparam {
 	/* See Documentation/diff-options.adoc. */
 	char **anchors;
 	size_t anchors_nr;
+	xdl_line_transform_fn line_transform;
+	void *line_transform_data;
 } xpparam_t;
 
 typedef struct s_xdemitcb {
diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c
index 5a78b88fad..0e335e2658 100644
--- a/xdiff/xmerge.c
+++ b/xdiff/xmerge.c
@@ -94,15 +94,14 @@ static int xdl_cleanup_merge(xdmerge_t *c)
 }
 
 static int xdl_merge_cmp_lines(xdfenv_t *xe1, int i1, xdfenv_t *xe2, int i2,
-		int line_count, long flags)
+		int line_count, xpparam_t const *xpp)
 {
 	int i;
 	xrecord_t *rec1 = xe1->xdf2.recs + i1;
 	xrecord_t *rec2 = xe2->xdf2.recs + i2;
 
 	for (i = 0; i < line_count; i++) {
-		int result = xdl_recmatch((const char *)rec1[i].ptr, (long)rec1[i].size,
-			(const char *)rec2[i].ptr, (long)rec2[i].size, flags);
+		int result = xdl_recmatch_records(&rec1[i], &rec2[i], xpp);
 		if (!result)
 			return -1;
 	}
@@ -323,10 +322,9 @@ static size_t xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,
 	return size;
 }
 
-static int recmatch(xrecord_t *rec1, xrecord_t *rec2, unsigned long flags)
+static int recmatch(xrecord_t *rec1, xrecord_t *rec2, xpparam_t const *xpp)
 {
-	return xdl_recmatch((const char *)rec1->ptr, (long)rec1->size,
-			    (const char *)rec2->ptr, (long)rec2->size, flags);
+	return xdl_recmatch_records(rec1, rec2, xpp);
 }
 
 /*
@@ -342,7 +340,7 @@ static void xdl_refine_zdiff3_conflicts(xdfenv_t *xe1, xdfenv_t *xe2, xdmerge_t
 			continue;
 
 		while(m->chg1 && m->chg2 &&
-		      recmatch(&rec1[m->i1], &rec2[m->i2], xpp->flags)) {
+		      recmatch(&rec1[m->i1], &rec2[m->i2], xpp)) {
 			m->chg1--;
 			m->chg2--;
 			m->i1++;
@@ -350,7 +348,7 @@ static void xdl_refine_zdiff3_conflicts(xdfenv_t *xe1, xdfenv_t *xe2, xdmerge_t
 		}
 		while (m->chg1 && m->chg2 &&
 		       recmatch(&rec1[m->i1 + m->chg1 - 1],
-				&rec2[m->i2 + m->chg2 - 1], xpp->flags)) {
+				&rec2[m->i2 + m->chg2 - 1], xpp)) {
 			m->chg1--;
 			m->chg2--;
 		}
@@ -581,7 +579,7 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1,
 				xscr1->chg2 != xscr2->chg2 ||
 				xdl_merge_cmp_lines(xe1, xscr1->i2,
 					xe2, xscr2->i2,
-					xscr1->chg2, xpp->flags)) {
+					xscr1->chg2, xpp)) {
 			/* conflict */
 			int off = xscr1->i1 - xscr2->i1;
 			int ffo = off + xscr1->chg1 - xscr2->chg1;
diff --git a/xdiff/xprepare.c b/xdiff/xprepare.c
index 11bada2608..3d6df505c3 100644
--- a/xdiff/xprepare.c
+++ b/xdiff/xprepare.c
@@ -56,8 +56,9 @@ typedef struct s_xdlclassifier {
 
 
 
-static int xdl_init_classifier(xdlclassifier_t *cf, long size, long flags) {
-	cf->flags = flags;
+static int xdl_init_classifier(xdlclassifier_t *cf, long size,
+			       xpparam_t const *xpp) {
+	cf->flags = xpp->flags;
 
 	cf->hbits = xdl_hashbits((unsigned int) size);
 	cf->hsize = 1 << cf->hbits;
@@ -98,12 +99,15 @@ static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t
 			       uint64_t line_hash) {
 	size_t hi;
 	xdlclass_t *rcrec;
+	const uint8_t *ptr = rec->match_ptr ? (uint8_t *)rec->match_ptr : rec->ptr;
+	size_t size = rec->match_ptr ? rec->match_size : rec->size;
 
 	hi = XDL_HASHLONG(line_hash, cf->hbits);
 	for (rcrec = cf->rchash[hi]; rcrec; rcrec = rcrec->next)
 		if (rcrec->line_hash == line_hash &&
-				xdl_recmatch((const char *)rcrec->ptr, (long)rcrec->size,
-					(const char *)rec->ptr, (long)rec->size, cf->flags))
+				xdl_recmatch((const char *)rcrec->ptr,
+					(long)rcrec->size, (const char *)ptr,
+					(long)size, cf->flags))
 			break;
 
 	if (!rcrec) {
@@ -116,8 +120,8 @@ static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t
 				return -1;
 		cf->rcrecs[rcrec->idx] = rcrec;
 		rcrec->line_hash = line_hash;
-		rcrec->ptr = rec->ptr;
-		rcrec->size = rec->size;
+		rcrec->ptr = ptr;
+		rcrec->size = size;
 		rcrec->len1 = rcrec->len2 = 0;
 		rcrec->next = cf->rchash[hi];
 		cf->rchash[hi] = rcrec;
@@ -133,6 +137,9 @@ static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t
 
 static void xdl_free_ctx(xdfile_t *xdf)
 {
+	size_t i;
+	for (i = 0; i < xdf->nrec; i++)
+		free(xdf->recs[i].match_ptr);
 	xdl_free(xdf->reference_index);
 	xdl_free(xdf->changed - 1);
 	xdl_free(xdf->recs);
@@ -142,13 +149,14 @@ static void xdl_free_ctx(xdfile_t *xdf)
 static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_t const *xpp,
 			   xdlclassifier_t *cf, xdfile_t *xdf) {
 	long bsize;
-	uint64_t hav;
+	uint64_t hav = 0;
 	uint8_t const *blk, *cur, *top, *prev;
 	xrecord_t *crec;
 
 	xdf->reference_index = NULL;
 	xdf->changed = NULL;
 	xdf->recs = NULL;
+	xdf->nrec = 0;
 
 	if (!XDL_ALLOC_ARRAY(xdf->recs, narec))
 		goto abort;
@@ -156,13 +164,42 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
 	xdf->nrec = 0;
 	if ((cur = blk = xdl_mmfile_first(mf, &bsize))) {
 		for (top = blk + bsize; cur < top; ) {
+			long line_size;
+			int is_eof;
+			char *transformed = NULL;
+			long transformed_size = 0;
+			uint8_t const *transformed_ptr;
+
 			prev = cur;
-			hav = xdl_hash_record(&cur, top, xpp->flags);
+			if (xpp->line_transform) {
+				const uint8_t *line_end = memchr(cur, '\n', top - cur);
+				line_size = line_end ? line_end + 1 - cur : top - cur;
+				is_eof = cur + line_size == top;
+				cur += line_size;
+			} else {
+				hav = xdl_hash_record(&cur, top, xpp->flags);
+				line_size = cur - prev;
+				is_eof = cur == top;
+			}
 			if (XDL_ALLOC_GROW(xdf->recs, (long)xdf->nrec + 1, narec))
 				goto abort;
 			crec = &xdf->recs[xdf->nrec++];
 			crec->ptr = prev;
-			crec->size = cur - prev;
+			crec->size = line_size;
+			crec->match_ptr = NULL;
+			crec->match_size = 0;
+			if (xpp->line_transform) {
+				if (xpp->line_transform((const char *)prev, line_size,
+						is_eof, &transformed,
+						&transformed_size,
+						xpp->line_transform_data) < 0)
+					goto abort;
+				crec->match_ptr = transformed;
+				crec->match_size = (size_t)transformed_size;
+				transformed_ptr = (uint8_t *)transformed;
+				hav = xdl_hash_record_verbatim(&transformed_ptr,
+					transformed_ptr + transformed_size);
+			}
 			if (xdl_classify_record(pass, cf, crec, hav) < 0)
 				goto abort;
 		}
@@ -442,7 +479,7 @@ int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
 	enl1 = xdl_guess_lines(mf1, sample) + 1;
 	enl2 = xdl_guess_lines(mf2, sample) + 1;
 
-	if (xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0)
+	if (xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp) < 0)
 		return -1;
 
 	if (xdl_prepare_ctx(1, mf1, enl1, xpp, &cf, &xe->xdf1) < 0) {
diff --git a/xdiff/xtypes.h b/xdiff/xtypes.h
index 50aee779be..714153a86e 100644
--- a/xdiff/xtypes.h
+++ b/xdiff/xtypes.h
@@ -42,6 +42,8 @@ typedef struct s_xrecord {
 	uint8_t const *ptr;
 	size_t size;
 	size_t minimal_perfect_hash;
+	char *match_ptr;
+	size_t match_size;
 } xrecord_t;
 
 typedef struct s_xdfile {
diff --git a/xdiff/xutils.c b/xdiff/xutils.c
index 4215f646c5..5b1c0edc3d 100644
--- a/xdiff/xutils.c
+++ b/xdiff/xutils.c
@@ -249,6 +249,20 @@ int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags)
 	return 1;
 }
 
+int xdl_recmatch_records(xrecord_t *rec1, xrecord_t *rec2,
+			 xpparam_t const *xpp)
+{
+	const char *line1 = rec1->match_ptr ? rec1->match_ptr :
+		(const char *)rec1->ptr;
+	const char *line2 = rec2->match_ptr ? rec2->match_ptr :
+		(const char *)rec2->ptr;
+	size_t size1 = rec1->match_ptr ? rec1->match_size : rec1->size;
+	size_t size2 = rec2->match_ptr ? rec2->match_size : rec2->size;
+
+	return xdl_recmatch(line1, (long)size1, line2, (long)size2,
+			    xpp->flags);
+}
+
 uint64_t xdl_hash_record_with_whitespace(uint8_t const **data,
 		uint8_t const *top, uint64_t flags) {
 	uint64_t ha = 5381;
diff --git a/xdiff/xutils.h b/xdiff/xutils.h
index 58f9d74cda..51217d99c6 100644
--- a/xdiff/xutils.h
+++ b/xdiff/xutils.h
@@ -34,6 +34,8 @@ void *xdl_cha_alloc(chastore_t *cha);
 long xdl_guess_lines(mmfile_t *mf, long sample);
 int xdl_blankline(const char *line, long size, long flags);
 int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags);
+int xdl_recmatch_records(xrecord_t *rec1, xrecord_t *rec2,
+			 xpparam_t const *xpp);
 uint64_t xdl_hash_record_verbatim(uint8_t const **data, uint8_t const *top);
 uint64_t xdl_hash_record_with_whitespace(uint8_t const **data, uint8_t const *top, uint64_t flags);
 static inline uint64_t xdl_hash_record(uint8_t const **data, uint8_t const *top, uint64_t flags)
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] merge-ort: fix whitespace in replayed changes
  2026-11-30  0:01 [PATCH 0/4] rebase: support --whitespace=fix with --interactive Alessio Attilio via GitGitGadget
  2026-11-30  0:01 ` [PATCH 1/4] xdiff: support transformed records in merge matching Alessio Attilio via GitGitGadget
@ 2026-11-30  0:01 ` Alessio Attilio via GitGitGadget
  2026-11-30  0:01 ` [PATCH 3/4] rebase: route whitespace fixes through the selected backend Alessio Attilio via GitGitGadget
  2026-11-30  0:01 ` [PATCH 4/4] rebase: test whitespace fixes with the merge backend Alessio Attilio via GitGitGadget
  3 siblings, 0 replies; 5+ messages in thread
From: Alessio Attilio via GitGitGadget @ 2026-11-30  0:01 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin, Alessio Attilio, Alessio Attilio

From: Alessio Attilio <attilio.alessio@protonmail.com>

The apply backend passes --whitespace=fix to git apply, which fixes
introduced lines while applying each commit.  The merge backend instead
replays commits through a three-way merge, so it needs to identify the
resulting changes and fix them after merging.

Use the path's whitespace rules to compare and repair changed lines in
the merge result.  Leave lines inherited from our side untouched, and
handle files added by the replayed commit as having an empty base.

Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
---
 merge-ll.c  | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 merge-ll.h  |   5 ++
 merge-ort.c |  52 +++++++++++++++
 merge-ort.h |   1 +
 4 files changed, 239 insertions(+), 1 deletion(-)

diff --git a/merge-ll.c b/merge-ll.c
index 996a38113f..a47aa7cb24 100644
--- a/merge-ll.c
+++ b/merge-ll.c
@@ -18,6 +18,7 @@
 #include "strbuf.h"
 #include "gettext.h"
 #include "tempfile.h"
+#include "ws.h"
 
 struct ll_merge_driver;
 
@@ -101,6 +102,152 @@ static enum ll_merge_result ll_binary_merge(const struct ll_merge_driver *drv UN
 	return ret;
 }
 
+struct whitespace_fix_data {
+	unsigned char *changed;
+	int line_nr;
+};
+
+struct whitespace_transform_data {
+	unsigned ws_rule;
+};
+
+static int transform_whitespace_record(const char *line, long len, int is_eof,
+				       char **transformed,
+				       long *transformed_len, void *data)
+{
+	struct whitespace_transform_data *transform = data;
+	struct strbuf fixed = STRBUF_INIT;
+	size_t size;
+
+	if (is_eof && (transform->ws_rule & WS_BLANK_AT_EOF) &&
+	    ws_blank_line(line, len)) {
+		*transformed = xstrdup("");
+		*transformed_len = 0;
+		return 0;
+	}
+	ws_fix_copy(&fixed, line, len,
+		    transform->ws_rule & ~WS_BLANK_AT_EOF, NULL);
+	*transformed = strbuf_detach(&fixed, &size);
+	*transformed_len = size;
+	return 0;
+}
+
+static int mark_whitespace_fix_hunk(void *data_, long old_begin UNUSED,
+				    long old_nr UNUSED, long new_begin,
+				    long new_nr, const char *func UNUSED,
+				    long funclen UNUSED)
+{
+	struct whitespace_fix_data *data = data_;
+	long start = new_nr ? new_begin - 1 : new_begin;
+	long i;
+
+	for (i = start; i < start + new_nr && i < data->line_nr; i++)
+		if (data->changed && i >= 0)
+			data->changed[i] = 1;
+	return 0;
+}
+
+static int no_op_diff_line(void *data UNUSED, mmfile_t *mb UNUSED,
+			   int nbuf UNUSED)
+{
+	return 0;
+}
+
+static size_t trim_blank_lines_at_eof(mmfile_t *file)
+{
+	size_t end = file->size;
+
+	while (end) {
+		size_t start = end;
+		if (file->ptr[start - 1] == '\n')
+			start--;
+		while (start && file->ptr[start - 1] != '\n')
+			start--;
+		if (!ws_blank_line(file->ptr + start, end - start))
+			break;
+		end = start;
+	}
+	return end;
+}
+
+static mmfile_t *trimmed_copy(mmfile_t *file, size_t size, mmfile_t *copy)
+{
+	if (size == file->size)
+		return file;
+	copy->ptr = xmalloc(size ? size : 1);
+	memcpy(copy->ptr, file->ptr, size);
+	copy->size = size;
+	return copy;
+}
+
+int ll_merge_fix_whitespace(mmfile_t *result, mmfile_t *ours,
+			    unsigned ws_rule)
+{
+	struct whitespace_fix_data data = { 0 };
+	struct strbuf fixed = STRBUF_INIT;
+	xpparam_t xpp = { 0 };
+	xdemitconf_t xecfg = { .ctxlen = 0 };
+	xdemitcb_t ecb = {
+		.out_hunk = mark_whitespace_fix_hunk,
+		.out_line = no_op_diff_line,
+		.priv = &data,
+	};
+	size_t pos = 0, cut = result->size;
+	int ret = -1, i = 0;
+
+	for (pos = 0; pos < result->size; pos++)
+		if (result->ptr[pos] == '\n')
+			i++;
+	if (result->size && result->ptr[result->size - 1] != '\n')
+		i++;
+	data.line_nr = i;
+	CALLOC_ARRAY(data.changed, data.line_nr);
+	if (xdi_diff(ours, result, &xpp, &xecfg, &ecb))
+		goto out;
+
+	if (ws_rule & WS_BLANK_AT_EOF) {
+		int line = data.line_nr;
+		pos = result->size;
+		while (line > 0 && data.changed[line - 1]) {
+			size_t start = pos;
+			if (start > 0 && result->ptr[start - 1] == '\n')
+				start--;
+			while (start > 0 && result->ptr[start - 1] != '\n')
+				start--;
+			if (!ws_blank_line(result->ptr + start, pos - start))
+				break;
+			cut = start;
+			pos = start;
+			line--;
+		}
+	}
+
+	strbuf_init(&fixed, result->size);
+	pos = 0;
+	for (i = 0; i < data.line_nr; i++) {
+		size_t end = pos;
+		while (end < cut && result->ptr[end] != '\n')
+			end++;
+		if (end < cut)
+			end++;
+		if (data.changed[i])
+			ws_fix_copy(&fixed, result->ptr + pos, end - pos,
+				    ws_rule, NULL);
+		else
+			strbuf_add(&fixed, result->ptr + pos, end - pos);
+		pos = end;
+	}
+	if (pos < cut)
+		strbuf_add(&fixed, result->ptr + pos, cut - pos);
+	free(result->ptr);
+	result->ptr = strbuf_detach(&fixed, &result->size);
+	ret = 0;
+out:
+	strbuf_release(&fixed);
+	free(data.changed);
+	return ret;
+}
+
 static enum ll_merge_result ll_xdl_merge(const struct ll_merge_driver *drv_unused,
 			mmfile_t *result,
 			const char *path,
@@ -112,8 +259,14 @@ static enum ll_merge_result ll_xdl_merge(const struct ll_merge_driver *drv_unuse
 {
 	enum ll_merge_result ret;
 	xmparam_t xmp;
+	mmfile_t orig_copy = { 0 }, src1_copy = { 0 }, src2_copy = { 0 };
+	mmfile_t *merge_orig = orig, *merge_src1 = src1, *merge_src2 = src2;
+	size_t src1_size;
 	int status;
+	struct whitespace_transform_data transform_data;
 	assert(opts);
+	src1_size = src1->size;
+	transform_data.ws_rule = opts->whitespace_rule;
 
 	if (orig->size > MAX_XDIFF_SIZE ||
 	    src1->size > MAX_XDIFF_SIZE ||
@@ -133,6 +286,19 @@ static enum ll_merge_result ll_xdl_merge(const struct ll_merge_driver *drv_unuse
 	xmp.level = XDL_MERGE_ZEALOUS;
 	xmp.favor = opts->variant;
 	xmp.xpp.flags = opts->xdl_opts;
+	if (opts->whitespace_fix) {
+		xmp.xpp.line_transform = transform_whitespace_record;
+		xmp.xpp.line_transform_data = &transform_data;
+		if (opts->whitespace_rule & WS_BLANK_AT_EOF) {
+			merge_orig = trimmed_copy(orig,
+				trim_blank_lines_at_eof(orig), &orig_copy);
+			merge_src1 = trimmed_copy(src1,
+				trim_blank_lines_at_eof(src1), &src1_copy);
+			merge_src2 = trimmed_copy(src2,
+				trim_blank_lines_at_eof(src2), &src2_copy);
+			src1_size = merge_src1->size;
+		}
+	}
 	if (opts->conflict_style >= 0)
 		xmp.style = opts->conflict_style;
 	else if (git_xmerge_style >= 0)
@@ -142,8 +308,22 @@ static enum ll_merge_result ll_xdl_merge(const struct ll_merge_driver *drv_unuse
 	xmp.ancestor = orig_name;
 	xmp.file1 = name1;
 	xmp.file2 = name2;
-	status = xdl_merge(orig, src1, src2, &xmp, result);
+	status = xdl_merge(merge_orig, merge_src1, merge_src2, &xmp, result);
 	ret = (status > 0) ? LL_MERGE_CONFLICT : status;
+	if (opts->whitespace_fix && status >= 0) {
+		if (src1_size < src1->size) {
+			size_t suffix_size = src1->size - src1_size;
+			result->ptr = xrealloc(result->ptr, result->size + suffix_size);
+			memcpy(result->ptr + result->size,
+			       src1->ptr + src1_size, suffix_size);
+			result->size += suffix_size;
+		}
+		if (ll_merge_fix_whitespace(result, src1, opts->whitespace_rule))
+			ret = LL_MERGE_ERROR;
+	}
+	free(orig_copy.ptr);
+	free(src1_copy.ptr);
+	free(src2_copy.ptr);
 	return ret;
 }
 
diff --git a/merge-ll.h b/merge-ll.h
index f95332c682..5a81aa2d65 100644
--- a/merge-ll.h
+++ b/merge-ll.h
@@ -83,6 +83,8 @@ struct ll_merge_options {
 
 	/* Extra xpparam_t flags as defined in xdiff/xdiff.h. */
 	long xdl_opts;
+	unsigned whitespace_fix : 1;
+	unsigned whitespace_rule;
 };
 
 #define LL_MERGE_OPTIONS_INIT { .conflict_style = -1 }
@@ -108,6 +110,9 @@ enum ll_merge_result ll_merge(mmfile_t *result_buf,
 	     struct index_state *istate,
 	     const struct ll_merge_options *opts);
 
+int ll_merge_fix_whitespace(mmfile_t *result, mmfile_t *ours,
+			    unsigned ws_rule);
+
 int ll_merge_marker_size(struct index_state *istate, const char *path);
 int is_conflict_marker_line(const char *line, unsigned long len, int marker_size);
 int has_conflict_markers(struct index_state *istate, const char *path);
diff --git a/merge-ort.c b/merge-ort.c
index 1383f7b256..912df3cb9e 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -52,6 +52,7 @@
 #include "trace2.h"
 #include "tree.h"
 #include "unpack-trees.h"
+#include "ws.h"
 #include "xdiff-interface.h"
 
 /*
@@ -1260,6 +1261,11 @@ static void collect_rename_info(struct merge_options *opt,
 	}
 }
 
+static int fix_blob_whitespace(struct merge_options *opt,
+			       const struct object_id *base_oid,
+			       struct object_id *result_oid,
+			       const char *path);
+
 static int collect_merge_info_callback(int n,
 				       unsigned long mask,
 				       unsigned long dirmask,
@@ -1385,6 +1391,11 @@ static int collect_merge_info_callback(int n,
 	 * destinations within side2.
 	 */
 	if (side1_matches_mbase && filemask == 0x07) {
+		if (opt->whitespace_fix && S_ISREG(names[2].mode)) {
+			if (fix_blob_whitespace(opt, &names[0].oid, &names[2].oid,
+						fullpath))
+				return -1;
+		}
 		/* use side2 version as resolution */
 		if (setup_path_info(opt, &pi, dirname, info->pathlen, fullpath,
 				    names, names+2, side2_null, 0,
@@ -2128,6 +2139,10 @@ static int merge_3way(struct merge_options *opt,
 	ll_opts.renormalize = opt->renormalize;
 	ll_opts.extra_marker_size = extra_marker_size;
 	ll_opts.xdl_opts = opt->xdl_opts;
+	ll_opts.whitespace_fix = opt->whitespace_fix;
+	if (ll_opts.whitespace_fix)
+		ll_opts.whitespace_rule = whitespace_rule(opt->repo->index,
+							  path);
 	ll_opts.conflict_style = opt->conflict_style;
 
 	if (opt->priv->call_depth) {
@@ -2180,6 +2195,30 @@ static int merge_3way(struct merge_options *opt,
 	return merge_status;
 }
 
+static int fix_blob_whitespace(struct merge_options *opt,
+			       const struct object_id *base_oid,
+			       struct object_id *result_oid,
+			       const char *path)
+{
+	mmfile_t base = { 0 }, result;
+	struct object_id fixed_oid;
+	int ret;
+
+	if (!is_null_oid(base_oid))
+		read_mmblob(&base, opt->repo->objects, base_oid);
+	read_mmblob(&result, opt->repo->objects, result_oid);
+	ret = ll_merge_fix_whitespace(&result, &base,
+				      whitespace_rule(opt->repo->index, path));
+	if (!ret)
+		ret = odb_write_object(opt->repo->objects, result.ptr, result.size,
+					OBJ_BLOB, &fixed_oid);
+	if (!ret)
+		oidcpy(result_oid, &fixed_oid);
+	free(base.ptr);
+	free(result.ptr);
+	return ret;
+}
+
 static int handle_content_merge(struct merge_options *opt,
 				const char *path,
 				const struct version_info *o,
@@ -4222,6 +4261,12 @@ static int process_entry(struct merge_options *opt,
 			if (ci->merged.is_null)
 				ci->merged.clean = 1;
 			oidcpy(&ci->merged.result.oid, &ci->stages[side].oid);
+			if (side == 2 && opt->whitespace_fix &&
+			    S_ISREG(ci->merged.result.mode)) {
+				if (fix_blob_whitespace(opt, &ci->stages[0].oid,
+							&ci->merged.result.oid, path))
+					return -1;
+			}
 
 			assert(othermask == 2 || othermask == 4);
 			assert(ci->merged.is_null ==
@@ -4428,6 +4473,11 @@ static int process_entry(struct merge_options *opt,
 		int side = (ci->filemask == 4) ? 2 : 1;
 		ci->merged.result.mode = ci->stages[side].mode;
 		oidcpy(&ci->merged.result.oid, &ci->stages[side].oid);
+		if (side == 2 && opt->whitespace_fix &&
+		    S_ISREG(ci->merged.result.mode) &&
+		    fix_blob_whitespace(opt, null_oid(opt->repo->hash_algo),
+					&ci->merged.result.oid, path))
+			return -1;
 		ci->merged.clean = !ci->df_conflict && !ci->path_conflict;
 	} else if (ci->filemask == 1) {
 		/* Deleted on both sides */
@@ -5598,6 +5648,8 @@ int parse_merge_opt(struct merge_options *opt, const char *s)
 		DIFF_XDL_SET(opt, IGNORE_WHITESPACE_AT_EOL);
 	else if (!strcmp(s, "ignore-cr-at-eol"))
 		DIFF_XDL_SET(opt, IGNORE_CR_AT_EOL);
+	else if (!strcmp(s, "whitespace=fix"))
+		opt->whitespace_fix = 1;
 	else if (!strcmp(s, "renormalize"))
 		opt->renormalize = 1;
 	else if (!strcmp(s, "no-renormalize"))
diff --git a/merge-ort.h b/merge-ort.h
index 6045579825..e446600fee 100644
--- a/merge-ort.h
+++ b/merge-ort.h
@@ -67,6 +67,7 @@ struct merge_options {
 
 	/* xdiff-related options (patience, ignore whitespace, ours/theirs) */
 	long xdl_opts;
+	unsigned whitespace_fix : 1;
 	int conflict_style;
 	enum {
 		MERGE_VARIANT_NORMAL = 0,
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] rebase: route whitespace fixes through the selected backend
  2026-11-30  0:01 [PATCH 0/4] rebase: support --whitespace=fix with --interactive Alessio Attilio via GitGitGadget
  2026-11-30  0:01 ` [PATCH 1/4] xdiff: support transformed records in merge matching Alessio Attilio via GitGitGadget
  2026-11-30  0:01 ` [PATCH 2/4] merge-ort: fix whitespace in replayed changes Alessio Attilio via GitGitGadget
@ 2026-11-30  0:01 ` Alessio Attilio via GitGitGadget
  2026-11-30  0:01 ` [PATCH 4/4] rebase: test whitespace fixes with the merge backend Alessio Attilio via GitGitGadget
  3 siblings, 0 replies; 5+ messages in thread
From: Alessio Attilio via GitGitGadget @ 2026-11-30  0:01 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin, Alessio Attilio, Alessio Attilio

From: Alessio Attilio <attilio.alessio@protonmail.com>

--whitespace has historically implied the apply backend because its
value was forwarded directly to git apply.  With whitespace=fix
available in the merge backend, keep apply-specific actions on that
backend while allowing fix to reach merge and interactive rebases.

Validate the action before selecting a backend, pass fix to the merge
strategy when needed, and document the backend-specific behavior.  Keep
other whitespace actions unsupported with the merge backend.  Update
the incompatibility tests so the newly supported combinations are
expected to succeed.

Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
---
 Documentation/git-rebase.adoc          |  6 +--
 builtin/rebase.c                       | 55 +++++++++++++++++++++++---
 contrib/completion/git-completion.bash |  2 +-
 t/t3422-rebase-incompatible-options.sh | 17 +++++++-
 4 files changed, 69 insertions(+), 11 deletions(-)

diff --git a/Documentation/git-rebase.adoc b/Documentation/git-rebase.adoc
index 2f0c6fbbd1..1d4c729e3f 100644
--- a/Documentation/git-rebase.adoc
+++ b/Documentation/git-rebase.adoc
@@ -466,9 +466,9 @@ merge backend;;
 	other side had no changes that conflicted.
 
 --whitespace=<option>::
-	This flag is passed to the `git apply` program
-	(see linkgit:git-apply[1]) that applies the patch.
-	Implies `--apply`.
+	In the apply backend, this flag is passed to the `git apply` program
+	(see linkgit:git-apply[1]) that applies the patch and implies `--apply`.
+	The merge backend supports only `fix`.
 +
 See also <<INCOMPATIBLE_OPTIONS,INCOMPATIBLE OPTIONS>> below.
 
diff --git a/builtin/rebase.c b/builtin/rebase.c
index 535db60181..3512fe2e14 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -405,6 +405,30 @@ static int is_merge(struct rebase_options *opts)
 	return opts->type == REBASE_MERGE;
 }
 
+static int rebase_whitespace_uses_apply_backend(
+	const struct rebase_options *opts, const char *strategy_opt)
+{
+	if (opts->type == REBASE_APPLY)
+		return 1;
+	if (opts->type != REBASE_UNSPECIFIED)
+		return 0;
+	return !strcmp(opts->default_backend, "apply") &&
+		!(opts->flags & REBASE_INTERACTIVE_EXPLICIT) &&
+		!(opts->root && !opts->onto_name) &&
+		opts->rebase_merges != 1 &&
+		opts->config_rebase_merges != 1 &&
+		!opts->strategy &&
+		!strategy_opt &&
+		!opts->strategy_opts.nr &&
+		!opts->exec.nr &&
+		opts->empty == EMPTY_UNSPECIFIED &&
+		opts->autosquash != 1 &&
+		opts->update_refs != 1 &&
+		opts->config_update_refs != 1 &&
+		!opts->trailer_args.nr &&
+		opts->reapply_cherry_picks != 1;
+}
+
 static void imply_merge(struct rebase_options *opts, const char *option)
 {
 	switch (opts->type) {
@@ -1119,6 +1143,8 @@ int cmd_rebase(int argc,
 	struct strbuf buf = STRBUF_INIT;
 	struct object_id branch_base;
 	int ignore_whitespace = 0;
+	int whitespace_uses_apply_backend = 0;
+	const char *whitespace = NULL;
 	const char *gpg_sign = NULL;
 	struct object_id squash_onto;
 	char *squash_onto_name = NULL;
@@ -1166,8 +1192,8 @@ int cmd_rebase(int argc,
 				  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_STRING(0, "whitespace", &whitespace, N_("action"),
+			   N_("specify how to handle whitespace errors")),
 		OPT_BIT('f', "force-rebase", &options.flags,
 			N_("cherry-pick all commits, even if unchanged"),
 			REBASE_FORCE),
@@ -1488,6 +1514,16 @@ int cmd_rebase(int argc,
 	}
 	if (options.committer_date_is_author_date || options.ignore_date)
 		options.flags |= REBASE_FORCE;
+	if (whitespace) {
+		if (strcmp(whitespace, "fix") && strcmp(whitespace, "warn") &&
+		    strcmp(whitespace, "nowarn") &&
+		    strcmp(whitespace, "error") && strcmp(whitespace, "error-all"))
+			die("Invalid whitespace option: '%s'", whitespace);
+		if (!strcmp(whitespace, "fix")) {
+			allow_preemptive_ff = 0;
+			options.flags |= REBASE_FORCE;
+		}
+	}
 
 	for (i = 0; i < options.git_am_opts.nr; i++) {
 		const char *option = options.git_am_opts.v[i], *p;
@@ -1499,10 +1535,6 @@ int cmd_rebase(int argc,
 				if (!isdigit(*(p++)))
 					die(_("switch `C' expects a "
 					      "numerical value"));
-		} else if (skip_prefix(option, "--whitespace=", &p)) {
-			if (*p && strcmp(p, "warn") && strcmp(p, "nowarn") &&
-			    strcmp(p, "error") && strcmp(p, "error-all"))
-				die("Invalid whitespace option: '%s'", p);
 		}
 	}
 
@@ -1544,6 +1576,11 @@ int cmd_rebase(int argc,
 	if (options.exec.nr)
 		imply_merge(&options, "--exec");
 
+	whitespace_uses_apply_backend =
+		rebase_whitespace_uses_apply_backend(&options, strategy_opt);
+	if (whitespace && whitespace_uses_apply_backend)
+		strvec_pushf(&options.git_am_opts, "--whitespace=%s", whitespace);
+
 	if (options.type == REBASE_APPLY) {
 		if (ignore_whitespace)
 			strvec_push(&options.git_am_opts,
@@ -1555,6 +1592,12 @@ int cmd_rebase(int argc,
 			strvec_push(&options.git_am_opts, "--ignore-date");
 	} else {
 		/* REBASE_MERGE */
+		if (whitespace && !whitespace_uses_apply_backend &&
+		    !strcmp(whitespace, "fix"))
+			string_list_append(&options.strategy_opts, "whitespace=fix");
+		else if (whitespace && !whitespace_uses_apply_backend)
+			die(_("--whitespace=%s is not supported with the merge backend"),
+			    whitespace);
 		if (ignore_whitespace) {
 			string_list_append(&options.strategy_opts,
 					   "ignore-space-change");
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index a7f1da040a..187de33708 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1091,7 +1091,7 @@ __git_compute_merge_strategies ()
 __git_merge_strategy_options="ours theirs subtree subtree= patience
 	histogram diff-algorithm= ignore-space-change ignore-all-space
 	ignore-space-at-eol renormalize no-renormalize no-renames
-	find-renames find-renames= rename-threshold="
+	find-renames find-renames= rename-threshold= whitespace=fix"
 
 __git_complete_revlist_file ()
 {
diff --git a/t/t3422-rebase-incompatible-options.sh b/t/t3422-rebase-incompatible-options.sh
index d6830b82e0..f955309ce8 100755
--- a/t/t3422-rebase-incompatible-options.sh
+++ b/t/t3422-rebase-incompatible-options.sh
@@ -125,7 +125,22 @@ test_rebase_am_only () {
 }
 
 # Check options which imply --apply
-test_rebase_am_only --whitespace=fix
+test_expect_success '--whitespace=fix works with --merge' '
+	git checkout B^0 &&
+	git rebase --whitespace=fix --merge A &&
+	test_seq 1 9 >expect &&
+	echo "q qfoo();" >>expect &&
+	test_cmp expect foo
+'
+
+test_expect_success '--whitespace=fix works with --interactive' '
+	git checkout B^0 &&
+	GIT_SEQUENCE_EDITOR=: git rebase --whitespace=fix --interactive A &&
+	test_seq 1 9 >expect &&
+	echo "q qfoo();" >>expect &&
+	test_cmp expect foo
+'
+
 test_rebase_am_only -C4
 # Also check an explicit --apply
 test_rebase_am_only --apply
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] rebase: test whitespace fixes with the merge backend
  2026-11-30  0:01 [PATCH 0/4] rebase: support --whitespace=fix with --interactive Alessio Attilio via GitGitGadget
                   ` (2 preceding siblings ...)
  2026-11-30  0:01 ` [PATCH 3/4] rebase: route whitespace fixes through the selected backend Alessio Attilio via GitGitGadget
@ 2026-11-30  0:01 ` Alessio Attilio via GitGitGadget
  3 siblings, 0 replies; 5+ messages in thread
From: Alessio Attilio via GitGitGadget @ 2026-11-30  0:01 UTC (permalink / raw)
  To: git; +Cc: Johannes Schindelin, Alessio Attilio, Alessio Attilio

From: Alessio Attilio <attilio.alessio@protonmail.com>

Exercise whitespace=fix while replaying commits with the merge backend,
including interactive use, attribute rules, existing whitespace in the
base, added files, and whitespace at end of file.  Also check that the
option remains rejected with the merge backend for actions it does not
support.

These tests cover the user-visible behavior across both backend
selection and merge replay, guarding against fixing unchanged context or
regressing the apply backend.

Signed-off-by: Alessio Attilio <attilio.alessio@protonmail.com>
---
 t/t3417-rebase-whitespace-fix.sh | 163 +++++++++++++++++++++++++++++++
 1 file changed, 163 insertions(+)

diff --git a/t/t3417-rebase-whitespace-fix.sh b/t/t3417-rebase-whitespace-fix.sh
index 96f2cf22fa..c65b5c1e37 100755
--- a/t/t3417-rebase-whitespace-fix.sh
+++ b/t/t3417-rebase-whitespace-fix.sh
@@ -94,6 +94,169 @@ test_expect_success 'same, but do not remove trailing spaces' '
 	test_cmp file third
 '
 
+test_expect_success 'interactive rebase fixes whitespace' '
+	git config core.whitespace blank-at-eol &&
+	git checkout -b interactive-whitespace HEAD^ &&
+	test_write_lines "clean" >file &&
+	git commit -am clean &&
+	test_write_lines "trailing " >>file &&
+	git commit -am "add whitespace errors" &&
+	write_script sequence-editor <<-\EOF &&
+	sed -e "s/^pick/pick/" "$1" >"$1.tmp" &&
+	mv "$1.tmp" "$1"
+	EOF
+	GIT_SEQUENCE_EDITOR=./sequence-editor git rebase -i --whitespace=fix HEAD^^ &&
+	test_write_lines clean "trailing" >expect &&
+	test_cmp expect file
+'
+
+test_expect_success 'interactive rebase fixes whitespace in upstream context' '
+	test_create_repo context &&
+	(
+		cd context &&
+		test_write_lines one "two " three >file &&
+		git add file && git commit -m base &&
+		git checkout -b topic &&
+		test_write_lines one two THREE >file &&
+		git commit -am topic &&
+		git checkout -b upstream HEAD^ &&
+		test_write_lines one two three >file &&
+		git commit -am whitespace &&
+		git checkout topic &&
+		write_script sequence-editor <<-\EOF &&
+		sed -e "s/^pick/pick/" "$1" >"$1.tmp" &&
+		mv "$1.tmp" "$1"
+		EOF
+		GIT_SEQUENCE_EDITOR=./sequence-editor \
+			git rebase -i --whitespace=fix upstream &&
+		test_write_lines one two THREE >expect &&
+		test_cmp expect file
+	)
+'
+
+test_expect_success 'interactive rebase preserves other whitespace changes' '
+	test_create_repo preserve &&
+	(
+		cd preserve &&
+		git config core.whitespace blank-at-eol &&
+		test_write_lines one "two " three >file &&
+		git add file && git commit -m base &&
+		git checkout -b topic &&
+		printf " one\ntwo \nthree \n" >file &&
+		git commit -am topic &&
+		git checkout -b upstream HEAD^ &&
+		printf "one\ntwo\nthree\n" >file &&
+		git commit -am whitespace &&
+		git checkout topic &&
+		write_script sequence-editor <<-\EOF &&
+		sed -e "s/^pick/pick/" "$1" >"$1.tmp" &&
+		mv "$1.tmp" "$1"
+		EOF
+		GIT_SEQUENCE_EDITOR=./sequence-editor \
+			git rebase -i --whitespace=fix upstream &&
+		printf " one\ntwo\nthree\n" >expect &&
+		test_cmp expect file
+	)
+'
+
+test_expect_success 'interactive rebase rejects unsupported whitespace actions' '
+	test_create_repo unsupported &&
+	(
+		cd unsupported &&
+		test_write_lines base >file &&
+		git add file && git commit -m base &&
+		test_write_lines change >>file &&
+		git commit -am change &&
+		test_must_fail env GIT_SEQUENCE_EDITOR=: \
+			git rebase -i --whitespace=warn HEAD^
+	)
+'
+
+test_expect_success 'interactive rebase fixes blank-at-eof' '
+	test_create_repo eof &&
+	(
+		cd eof &&
+		test_write_lines one >file &&
+		git add file && git commit -m base &&
+		test_write_lines one two >file &&
+		printf "\n\n" >>file &&
+		git commit -am whitespace &&
+		write_script sequence-editor <<-\EOF &&
+		sed -e "s/^pick/pick/" "$1" >"$1.tmp" &&
+		mv "$1.tmp" "$1"
+		EOF
+		GIT_SEQUENCE_EDITOR=./sequence-editor \
+			git rebase -i --whitespace=fix HEAD^ &&
+		test_write_lines one two >expect &&
+		test_cmp expect file
+	)
+'
+
+test_expect_success 'interactive rebase handles upstream blank-at-eof fixes' '
+	test_create_repo eof-context &&
+	(
+		cd eof-context &&
+		test_write_lines one >file &&
+		printf "\n\n" >>file &&
+		git add file && git commit -m base &&
+		git checkout -b topic &&
+		test_write_lines one two >file &&
+		printf "\n\n" >>file &&
+		git commit -am topic &&
+		git checkout -b upstream HEAD^ &&
+		test_write_lines one >file &&
+		git commit -am whitespace &&
+		git checkout topic &&
+		write_script sequence-editor <<-\EOF &&
+		sed -e "s/^pick/pick/" "$1" >"$1.tmp" &&
+		mv "$1.tmp" "$1"
+		EOF
+		GIT_SEQUENCE_EDITOR=./sequence-editor \
+			git rebase -i --whitespace=fix upstream &&
+		test_write_lines one two >expect &&
+		test_cmp expect file
+	)
+'
+
+test_expect_success 'interactive rebase honors path whitespace rules' '
+	test_create_repo attr &&
+	(
+		cd attr &&
+		echo "file whitespace=-blank-at-eol" >.gitattributes &&
+		test_write_lines one >file &&
+		git add .gitattributes file && git commit -m base &&
+		printf "one \n" >file &&
+		git commit -am whitespace &&
+		write_script sequence-editor <<-\EOF &&
+		sed -e "s/^pick/pick/" "$1" >"$1.tmp" &&
+		mv "$1.tmp" "$1"
+		EOF
+		GIT_SEQUENCE_EDITOR=./sequence-editor \
+			git rebase -i --whitespace=fix HEAD^ &&
+		printf "one \n" >expect &&
+		test_cmp expect file
+	)
+'
+
+test_expect_success 'interactive rebase fixes whitespace in added files' '
+	test_create_repo added &&
+	(
+		cd added &&
+		test_write_lines base >file &&
+		git add file && git commit -m base &&
+		printf "new file with whitespace \n" >new-file &&
+		git add new-file && git commit -m add &&
+		write_script sequence-editor <<-\EOF &&
+		sed -e "s/^pick/pick/" "$1" >"$1.tmp" &&
+		mv "$1.tmp" "$1"
+		EOF
+		GIT_SEQUENCE_EDITOR=./sequence-editor \
+			git rebase -i --whitespace=fix HEAD^ &&
+		printf "new file with whitespace\n" >expect &&
+		test_cmp expect new-file
+	)
+'
+
 sed -e's/Z//' >beginning <<EOF
 a
 		    Z
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-30  0:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30  0:01 [PATCH 0/4] rebase: support --whitespace=fix with --interactive Alessio Attilio via GitGitGadget
2026-11-30  0:01 ` [PATCH 1/4] xdiff: support transformed records in merge matching Alessio Attilio via GitGitGadget
2026-11-30  0:01 ` [PATCH 2/4] merge-ort: fix whitespace in replayed changes Alessio Attilio via GitGitGadget
2026-11-30  0:01 ` [PATCH 3/4] rebase: route whitespace fixes through the selected backend Alessio Attilio via GitGitGadget
2026-11-30  0:01 ` [PATCH 4/4] rebase: test whitespace fixes with the merge backend Alessio Attilio via GitGitGadget

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox