diff --git a/src/bin/fish_indent.rs b/src/bin/fish_indent.rs index d37a8803f..141e3637f 100644 --- a/src/bin/fish_indent.rs +++ b/src/bin/fish_indent.rs @@ -979,7 +979,10 @@ enum OutputType { Ok(mut file) => { // If the output is the same as the input, don't write it. if output_wtext != src { - let _ = file.write_all(&wcs2string(&output_wtext)); + let text = wcs2string(&output_wtext); + let _ = file.write_all(&text); + // Truncate the file in case it shrunk. + let _ = file.set_len(text.len().try_into().unwrap()); } } Err(err) => { diff --git a/tests/checks/indent.fish b/tests/checks/indent.fish index e05e8679a..9648042cd 100644 --- a/tests/checks/indent.fish +++ b/tests/checks/indent.fish @@ -525,3 +525,9 @@ end # CHECK: {{^}}" # CHECK: {{^}} end # CHECK: {{^}}) + +set -l tmpdir (mktemp -d) +echo 'echo "foo" "bar"' > $tmpdir/indent_test.fish +$fish_indent --write $tmpdir/indent_test.fish +cat $tmpdir/indent_test.fish +# CHECK: echo foo bar