mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 15:18:50 +08:00
fish_indent: Truncate file to the size of the text
This can happen in case the formatted script is shorter, e.g. because we ditched superfluous quotes. Fixes #10724
This commit is contained in:
parent
9fafae7a8a
commit
e27f4a3744
|
@ -979,7 +979,10 @@ fn throwing_main() -> i32 {
|
|||
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) => {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user