Right now, if a file has both staged and unstaged changes, the pre-commit script will fail instead of checking if the staged changes need formatting.
This PR is for the script to check the staged changes will need formatting before exiting due to this.
What is being changed?
files_with_unstaged_changes is changed to an associative array so it's easier to check if a file is there
clang_format section changed to read from stdin through git show. This will return the staged version of the file. If it is properly formatted, there is no need to fail anymore.
cmake_format section changed to use a temporary file (which is also added to .gitignore in case the script fails or is killed and the file remains). That's because cmake_format does not allow stdin formatting. The staged version of the file is checked, and if properly formatted, there is no need to fail anymore.
What remains unformatted will be reported and the script will exit with 1.
Converted tabs to spaces in script
How was the change tested?
Not a functional change. Ex: modifying documentation, auxiliary files, etc
Tested manually by staging files with formatted changes and then having unformatted unstaged changes.
Related Issues
Why is this change being made?
Right now, if a file has both staged and unstaged changes, the pre-commit script will fail instead of checking if the staged changes need formatting. This PR is for the script to check the staged changes will need formatting before exiting due to this.
What is being changed?
files_with_unstaged_changes
is changed to an associative array so it's easier to check if a file is theregit show
. This will return the staged version of the file. If it is properly formatted, there is no need to fail anymore.1
.How was the change tested?