File tree 1 file changed +13
-6
lines changed
1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -165,12 +165,19 @@ def with_clean_env
165
165
expandtab0 = false
166
166
updated_lines = vcs . updated_lines ( f )
167
167
if !updated_lines . empty? && ( f . end_with? ( '.c' ) || f . end_with? ( '.h' ) || f == 'insns.def' ) && EXPANDTAB_IGNORED_FILES . all? { |re | !f . match ( re ) }
168
- src . gsub! ( /^.*$/ ) . with_index do |line , lineno |
169
- if updated_lines . include? ( lineno ) && line . start_with? ( "\t " ) # last-committed line with hard tabs
170
- expandtab = expandtab0 = true
171
- line . sub ( /\A \t +/ ) { |tabs | ' ' * ( 8 * tabs . length ) }
172
- else
173
- line
168
+ # If and only if unedited lines did not have tab indentation, prevent introducing tab indentation to the file.
169
+ expandtab_allowed = src . each_line . with_index . all? do |line , lineno |
170
+ updated_lines . include? ( lineno ) || !line . start_with? ( "\t " )
171
+ end
172
+
173
+ if expandtab_allowed
174
+ src . gsub! ( /^.*$/ ) . with_index do |line , lineno |
175
+ if updated_lines . include? ( lineno ) && line . start_with? ( "\t " ) # last-committed line with hard tabs
176
+ expandtab = expandtab0 = true
177
+ line . sub ( /\A \t +/ ) { |tabs | ' ' * ( 8 * tabs . length ) }
178
+ else
179
+ line
180
+ end
174
181
end
175
182
end
176
183
end
You can’t perform that action at this time.
0 commit comments