Skip to content

Commit dee40e5

Browse files
committed
Merge branch 'js/maint-apply-tab-in-indent-fix' into HEAD
* js/maint-apply-tab-in-indent-fix: apply --whitespace=fix: fix tab-in-indent
2 parents 7d43de9 + d35711a commit dee40e5

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

t/t4124-apply-ws-rule.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,34 @@ test_expect_success 'whitespace=error-all, no rule (attribute)' '
121121
122122
'
123123

124+
test_expect_success 'spaces inserted by tab-in-indent' '
125+
126+
git config core.whitespace -trailing,-space,-indent,tab &&
127+
rm -f .gitattributes &&
128+
test_fix % &&
129+
sed -e "s/_/ /g" -e "s/>/ /" <<-\EOF >expect &&
130+
An_SP in an ordinary line>and a HT.
131+
________A HT (%).
132+
________A SP and a HT (@%).
133+
_________A SP, a HT and a SP (@%).
134+
_______Seven SP.
135+
________Eight SP (#).
136+
________Seven SP and a HT (@%).
137+
________________Eight SP and a HT (@#%).
138+
_________Seven SP, a HT and a SP (@%).
139+
_________________Eight SP, a HT and a SP (@#%).
140+
_______________Fifteen SP (#).
141+
________________Fifteen SP and a HT (@#%).
142+
________________Sixteen SP (#).
143+
________________________Sixteen SP and a HT (@#%).
144+
_____a__Five SP, a non WS, two SP.
145+
A line with a (!) trailing SP_
146+
A line with a (!) trailing HT>
147+
EOF
148+
test_cmp expect target
149+
150+
'
151+
124152
for t in - ''
125153
do
126154
case "$t" in '') tt='!' ;; *) tt= ;; esac

ws.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,13 @@ void ws_fix_copy(struct strbuf *dst, const char *src, int len, unsigned ws_rule,
363363
fixed = 1;
364364
} else if ((ws_rule & WS_TAB_IN_INDENT) && last_tab_in_indent >= 0) {
365365
/* Expand tabs into spaces */
366+
int start = dst->len;
366367
int last = last_tab_in_indent + 1;
367368
for (i = 0; i < last; i++) {
368369
if (src[i] == '\t')
369370
do {
370371
strbuf_addch(dst, ' ');
371-
} while (dst->len % 8);
372+
} while ((dst->len - start) % 8);
372373
else
373374
strbuf_addch(dst, src[i]);
374375
}

0 commit comments

Comments
 (0)