Skip to content

tools: add support for vgit-fmt-hook on OpenBSD#26388

Merged
spytheman merged 3 commits into
vlang:masterfrom
lcheylus:openbsd-git_fmt_hook_script
Jan 18, 2026
Merged

tools: add support for vgit-fmt-hook on OpenBSD#26388
spytheman merged 3 commits into
vlang:masterfrom
lcheylus:openbsd-git_fmt_hook_script

Conversation

@lcheylus

@lcheylus lcheylus commented Jan 18, 2026

Copy link
Copy Markdown
Contributor

On OpenBSD env -S is not supported => cmd/tools/git_pre_commit_hook.vsh cannot be used as pre-commit git hook.

Generate an equivalent shell script to run cmd/tools/git_pre_commit_hook.vsh file => exec it via v run then copy temporary generated shell script in .git/hook/pre-commit

Fix #26344

  • Also add fix to not install pre-commit Git hook if already the same than the original version (VSH or shell script) (command ./v git-fmt-hook install)

Thanks to @spytheman for his help and see PR #26374 for previous discussions.


Tests OK on OpenBSD for status / install / remove with vgit-fmt-hook

$ ./v git-fmt-hook status
>   CURRENT git repo pre-commit hook: missing /home/fox/dev/vlang.git/.git/hooks/pre-commit
> Main V repo pre-commit hook script: size:     73 bytes, sha256: 33fd97a1602eafa9091f9378ac5e04213f5ae9a45d752c08326f2e8586bd6eeb, /tmp/v_1000/git_pre_commit_hook.sh
> Files have different hashes.
> Use `v git-fmt-hook install` to update the CURRENT repository's pre-commit hook,
> with the newest pre-commit formatting script from the main V repo.

$ ./v git-fmt-hook install
>   CURRENT git repo pre-commit hook: missing /home/fox/dev/vlang.git/.git/hooks/pre-commit
> Main V repo pre-commit hook script: size:     73 bytes, sha256: 33fd97a1602eafa9091f9378ac5e04213f5ae9a45d752c08326f2e8586bd6eeb, /tmp/v_1000/git_pre_commit_hook.sh
> Files have different hashes.
> Installing the newest version of /home/fox/dev/vlang.git/cmd/tools/git_pre_commit_hook.vsh over /home/fox/dev/vlang.git/.git/hooks/pre-commit ...
> Done.
$  ./v git-fmt-hook install
>   CURRENT git repo pre-commit hook: size:     73 bytes, sha256: 33fd97a1602eafa9091f9378ac5e04213f5ae9a45d752c08326f2e8586bd6eeb, /home/fox/dev/vlang.git/.git/hooks/pre-commit
> Main V repo pre-commit hook script: size:     73 bytes, sha256: 33fd97a1602eafa9091f9378ac5e04213f5ae9a45d752c08326f2e8586bd6eeb, /tmp/v_1000/git_pre_commit_hook.sh
> Both files are exactly the same.

./v git-fmt-hook remove
>   CURRENT git repo pre-commit hook: size:     73 bytes, sha256: 33fd97a1602eafa9091f9378ac5e04213f5ae9a45d752c08326f2e8586bd6eeb, /home/fox/dev/vlang.git/.git/hooks/pre-commit
> Main V repo pre-commit hook script: size:     73 bytes, sha256: 33fd97a1602eafa9091f9378ac5e04213f5ae9a45d752c08326f2e8586bd6eeb, /tmp/v_1000/git_pre_commit_hook.sh
> Both files are exactly the same.
> Removing /home/fox/dev/vlang.git/.git/hooks/pre-commit ...
> Done.

pre-commit Git hook works as attended on OpenBSD when commiting V files with bad format.

  • Update tests for vgit-fmt-hook
$ ---- Testing... ----
        V  source  code size:      31733 lines,     145986 tokens,     864126 bytes,   322 types,    13 modules,   150 files
generated  target  code size:      11608 lines,     445294 bytes
compilation took: 639.449 ms, compilation speed: 49625 vlines/s, cgen threads: 3
running tests in: /home/fox/dev/vlang.git/cmd/tools/vgit-fmt-hook_test.v
>>>>>> preparing tfolder: /tmp/v_1000/tsession_22e0fca70_01KF95440J5SZ4SQ68EK347P35/fmt_hook_test
      OK    [1/9]   127.790 ms     3 asserts | main.testsuite_begin()
>>>> test_commit_no_vfmt
      OK    [2/9]    87.661 ms     6 asserts | main.test_commit_no_vfmt()
>>>> test_run_vfmt_manually
      OK    [3/9]   112.881 ms     7 asserts | main.test_run_vfmt_manually()
>>>> test_run_git_fmt_hook
      OK    [4/9]    28.258 ms     7 asserts | main.test_run_git_fmt_hook()
>>>> test_run_git_fmt_hook_status_explicit
      OK    [5/9]    65.794 ms     7 asserts | main.test_run_git_fmt_hook_status_explicit()
>>>> test_run_git_fmt_hook_install
      OK    [6/9]   879.745 ms    18 asserts | main.test_run_git_fmt_hook_install()
>>>> test_run_git_fmt_hook_remove
      OK    [7/9]   158.407 ms     7 asserts | main.test_run_git_fmt_hook_remove()
>>>> test_run_git_fmt_hook_install_and_remove_on_foreign_hook_should_be_a_nop
      OK    [8/9]   553.434 ms    16 asserts | main.test_run_git_fmt_hook_install_and_remove_on_foreign_hook_should_be_a_nop()
* commit 719ea573fa670b1e095733983fd77ed0bcfddf11 (install_and_remove_should_be_a_nop_on_a_foreign_hook)
| Author: Myself <me@example.com>
| Date:   Sun Jan 18 19:15:54 2026 +0100
|
|     this should NOT be formatted 2
|
| * commit 1c7114d48714cb744ee4afc3528329e754fbc22a (non_formatting_after_removing_hook)
|/  Author: Myself <me@example.com>
|   Date:   Sun Jan 18 19:15:54 2026 +0100
|
|       this should NOT be formatted again
|
| * commit ca13b484fb2c46cc797cd8399b01994687b8dc80 (formatted)
|/  Author: Myself <me@example.com>
|   Date:   Sun Jan 18 19:15:53 2026 +0100
|
|       formatted change
|
| * commit b961bc5d1ea54a6604bde31d5c64e7459de5874c (formatting_with_hook)
|/  Author: Myself <me@example.com>
|   Date:   Sun Jan 18 19:15:53 2026 +0100
|
|       this should be formatted
|
| * commit 9e025830c620248e4bc7374eac3f7195925587fc (unformatted)
|/  Author: Myself <me@example.com>
|   Date:   Sun Jan 18 19:15:52 2026 +0100
|
|       unformatted change
|
* commit f1134fd802b5cfe4ace6210fcd5f153f029aaba1 (HEAD -> start, master)
  Author: Myself <me@example.com>
  Date:   Sun Jan 18 19:15:52 2026 +0100

      start testing, initially unformatted
On branch start
nothing to commit, working tree clean
>>>>>> deleted /tmp/v_1000/tsession_22e0fca70_01KF95440J5SZ4SQ68EK347P35/fmt_hook_test . Use VTEST_KEEP_TFOLDER=1 to keep it to ease diagnosing platform issues.
      OK    [9/9]    68.670 ms     2 asserts | main.testsuite_end()
     Summary for running V tests in "vgit-fmt-hook_test.v": 73 passed, 73 total. Elapsed time: 2083 ms.

 OK    2793.188 ms cmd/tools/vgit-fmt-hook_test.v
----

With this fix, all self tests OK on OpenBSD for cmd/

$ ./v test-self cmd
---- testing: cmd ----
 OK    [ 1/25] C:   745.0 ms, R:  1162.800 ms cmd/tools/vbump_test.v
 OK    [ 2/25] C:   739.7 ms, R:  1451.023 ms cmd/tools/vcomplete_test.v
 OK    [ 3/25] C:   762.8 ms, R:     6.423 ms cmd/tools/vcreate/vcreate_init_test.v
 OK    [ 4/25] C:   780.9 ms, R:     5.991 ms cmd/tools/vcreate/vcreate_new_test.v
 OK    [ 5/25] C:   754.0 ms, R:  4352.684 ms cmd/tools/vcover/cover_test.v
 OK    [ 6/25] C:  3189.3 ms, R:    11.830 ms cmd/tools/vdoc/document/doc_private_fn_test.v
 OK    [ 7/25] C:  3789.0 ms, R:    99.690 ms cmd/tools/vdoc/document/doc_test.v
 OK    [ 8/25] C:   950.0 ms, R:  5196.406 ms cmd/tools/vdoc/vdoc_file_test.v
 OK    [ 9/25] C:  4498.8 ms, R:    76.193 ms cmd/tools/vdoc/vdoc_test.v
 OK    [10/25] C:  1094.1 ms, R:     9.843 ms cmd/tools/vpm/dependency_test.v
 OK    [11/25] C:   898.7 ms, R:  5920.660 ms cmd/tools/vdoc/vdoc_run_examples_test.v
 OK    [12/25] C:   977.3 ms, R:    10.691 ms cmd/tools/vpm/install_version_input_test.v
 OK    [13/25] C:   907.0 ms, R:  2645.469 ms cmd/tools/vgit-fmt-hook_test.v
 OK    [14/25] C:  8740.1 ms, R:    20.826 ms cmd/tools/vpm/install_test.v
 OK    [15/25] C:  6497.6 ms, R:    25.715 ms cmd/tools/vpm/outdated_test.v
 OK    [16/25] C:  7636.4 ms, R:    26.857 ms cmd/tools/vpm/install_version_test.v
 OK    [17/25] C:  1035.7 ms, R:     6.727 ms cmd/tools/vpm/remove_test.v
 OK    [18/25] C:  1004.9 ms, R:     7.688 ms cmd/tools/vpm/update_test.v
 OK    [19/25] C:  1662.5 ms, R:    16.467 ms cmd/tools/vpm/search_test.v
 OK    [20/25] C:  1591.4 ms, R:    16.294 ms cmd/tools/vpm/vcs_test.v
 OK    [21/25] C:   796.9 ms, R:    32.047 ms cmd/tools/vtimeout_test.v
 OK    [22/25] C:   931.1 ms, R:  3223.989 ms cmd/tools/vvet/vet_test.v
 OK    [23/25] C:   911.5 ms, R:  5692.915 ms cmd/tools/vretry_test.v
 OK    [24/25] C:   816.9 ms, R:  5719.786 ms cmd/tools/vtest_test.v
 OK    [25/25] C:   896.8 ms, R:    13.784 ms cmd/tools/vwhere/vwhere_test.v
----
Summary for testing: cmd: 25 passed, 25 total. Elapsed time: 29943 ms, on 3 parallel jobs. Comptime: 52608 ms. Runtime: 35752 ms.

On OpenBSD 'env -S' is not supported
=> cmd/tools/git_pre_commit_hook.vsh cannot be used as pre-commit git hook.
Generate and copy a shell script to run cmd/tools/git_pre_commit_hook.vsh

Signed-off-by: Laurent Cheylus <foxy@free.fr>
Signed-off-by: Laurent Cheylus <foxy@free.fr>

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @lcheylus 🙇🏻 .

@spytheman spytheman merged commit 3a435fa into vlang:master Jan 18, 2026
27 checks passed
@lcheylus lcheylus deleted the openbsd-git_fmt_hook_script branch January 19, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test cmd/tools/vgit-fmt-hook_test.v fails on OpenBSD

2 participants