Skip to content

Commit

Permalink
tools: skip _input.vv files in cmd/tools/git_pre_commit_hook.vsh, jus…
Browse files Browse the repository at this point in the history
…t report them without vfmt-ing them
  • Loading branch information
spytheman committed Sep 14, 2023
1 parent 50ab331 commit b746083
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
18 changes: 15 additions & 3 deletions cmd/tools/git_pre_commit_hook.vsh
Expand Up @@ -26,11 +26,23 @@ import term
fn main() {
// This hook cares only about the changed V files, that will be commited, as reported by git itself:
changed := os.execute('git diff --cached --name-only --diff-filter=ACMR -- "*.v" "*.vsh" "*.vv"')
if changed.output == '' {
eprintln('>>> 0 changed V files found.')

all_changed_vfiles := changed.output.trim_space().split('\n')
// _input.vv files are NOT formatted on purpose.
// There is no point in verifying them, or ruining them over with `v fmt -w`.
// Just filter them out, but still report to the user, that they will not be formatted:
vfiles := all_changed_vfiles.filter(!it.ends_with('_input.vv'))
input_vfiles := all_changed_vfiles.filter(it.ends_with('_input.vv'))
if input_vfiles.len > 0 {
eprintln('>>> ${input_vfiles.len} `_input.vv` files found, that *will NOT be* formatted.')
for ifile in input_vfiles {
eprintln(' ${ifile}')
}
}
if changed.output == '' || vfiles.len == 0 {
eprintln('>>> 0 changed V files, that may need formatting found.')
exit(0)
}
vfiles := changed.output.trim_space().split('\n')
configured_stop_commiting := os.execute('git config --bool hooks.stopCommitOfNonVfmtedVFiles')
if configured_stop_commiting.output.trim_space().bool() {
verify_result := os.execute('v fmt -verify ${vfiles.join(' ')}')
Expand Down
7 changes: 4 additions & 3 deletions vlib/v/fmt/tests/structs_input.vv
@@ -1,11 +1,12 @@
struct User {

struct User {
name string // name
name2 []rune // name2
name2 []rune // name2
very_long_field bool
age int // age
very_long_type_field1 very_looooog_type // long
very_long_type_field2 very_loooooooong_type // long
}
}

struct FamousUser {
User
Expand Down

0 comments on commit b746083

Please sign in to comment.