Skip to content

Commit

Permalink
Add --overwriteWithoutBackup flag for usage with pre-commit
Browse files Browse the repository at this point in the history
Spamming backup files for files that are already managed by git is
pointless.

By using this new flag, the user explicitly states that he or she wants
to overwrite the files without backup. There is no short option to avoid
triggering this option by accident and the help text should be pretty
clear that using this option is not recommended unless you know what
you're doing. Hence, the risk of accidental data loss something should
be pretty much non-existant.

Also note that almost every other source code formatter has options to
to reformat and overwrite files without creating a backup.

Fixes cmhughes#333.
  • Loading branch information
Holzhaus committed Mar 30, 2022
1 parent 18bf4bc commit 94d4f82
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion LatexIndent/Document.pm
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ sub latexindent{
# overwrite and overwriteIfDifferent switches, per file
${$self}{overwrite} = $switches{overwrite};
${$self}{overwriteIfDifferent} = $switches{overwriteIfDifferent};
${$self}{overwriteWithoutBackup} = $switches{overwriteWithoutBackup};

# the main operations
$self->operate_on_file;
Expand Down Expand Up @@ -211,7 +212,7 @@ sub output_indented_text{
$logger->info("*Output routine:");

# if -overwrite is active then output to original fileName
if(${$self}{overwrite}){
if(${$self}{overwrite} || ${$self}{overwriteWithoutBackup}){
$logger->info("Overwriting file ${$self}{fileName}");
open(OUTPUTFILE,">",${$self}{fileName});
print OUTPUTFILE ${$self}{body};
Expand Down
2 changes: 2 additions & 0 deletions LatexIndent/LogFile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ usage: latexindent.pl [options] [file]
-wd, --overwriteIfDifferent
overwrite the current file IF the indented text is different from original;
a backup will be made, but still be careful
--overwriteWithoutBackup
overwrite the current file; NO BACKUP WILL BE MADE, USE AT YOUR OWN RISK!
-s, --silent
silent mode: no output will be given to the terminal
-t, --trace
Expand Down
1 change: 1 addition & 0 deletions latexindent.pl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"onlydefault|d"=>\$switches{onlyDefault},
"overwrite|w"=>\$switches{overwrite},
"overwriteIfDifferent|wd"=>\$switches{overwriteIfDifferent},
"overwriteWithoutBackup"=>\$switches{overwriteWithoutBackup},
"outputfile|o=s"=>\$switches{outputToFile},
"modifylinebreaks|m"=>\$switches{modifyLineBreaks},
"logfile|g=s"=>\$switches{logFileName},
Expand Down

0 comments on commit 94d4f82

Please sign in to comment.