evilmartians / lefthook

Fast and powerful Git hooks manager for any type of projects.
MIT License
4.66k stars 211 forks source link

feat: expand Swift integration with Mint support #724

Closed levibostian closed 2 months ago

levibostian commented 2 months ago

Building on top of previous PR that added Swift support.

:zap: Summary

The csjones/lefthook-plugin Swift project has recently added mint package manager support. To advertise this functionality, I wanted to mention this new feature in the lefthook docs.

For my edits in this PR, I used the previous PR that added Swift support as a reference. I have not tested internal/templates/hook.tmpl, if it's even possible to do so.

Thanks!

:ballot_box_with_check: Checklist

mrexox commented 2 months ago

Thank you! Have you tested this locally?

levibostian commented 2 months ago

I have tested the mint commands, yes. I haven't tested the toml file in this pr if that's what you're asking.

mrexox commented 2 months ago

@levibostian I mean, does the generated hook works as expected and mint run csjones/lefthook-plugin "$@" gets executed, not swift package --disable-sandbox plugin lefthook "$@" or npx lefthook "$@" ?

I am not aware of Swift tools, so I'll rely on your experience :)

levibostian commented 2 months ago

Do you mind pointing me in the right direction as far as testing this pull request out?

I looked at a couple other prs that did a similar modification and didn't find any help there. Maybe I'm looking in the wrong spot?

Happy to test it out and answer your questions though!

mrexox commented 2 months ago

@levibostian Sure, to test this locally you can do the following:

  1. Build the lefthook using make call and copy the binary to one of your projects that use Mint.
  2. Call ./lefthook install -f
  3. Run the git command with LEFTHOOK_VERBOSE=1 set, e.g.LEFTHOOK_VERBOSE=1 git commit
  4. Check the output, it should contain mint run csjones/lefthook-plugin line. But make sure you don't have lefthook binary in one of your PATHs, because it will be used instead by default.
levibostian commented 2 months ago

Thanks for the help! Especially the tip on lefthook in my PATH.

After I ran ./lefthook install -f, my .git/hooks/pre-commit file does contain the mint code I added in the PR. Then when I create a commit, I see mint gets executed as expected:

LEFTHOOK_VERBOSE=1 git commit -m "testing"
+ '[' '' = 0 ']'
+ call_lefthook run pre-commit
++ git rev-parse --show-toplevel
+ dir=/Users/levibostian/code/Wendy-iOS
++ uname
++ tr '[:upper:]' '[:lower:]'
+ osArch=darwin
++ uname -m
++ sed s/aarch64/arm64/
+ cpuArch=x86_64
+ test -n ''
+ test -f /Users/levibostian/code/Wendy-iOS/node_modules/lefthook/bin/index.js
+ test -f /Users/levibostian/code/Wendy-iOS/node_modules/@evilmartians/lefthook/bin/lefthook_darwin_x86_64/lefthook
+ test -f /Users/levibostian/code/Wendy-iOS/node_modules/@evilmartians/lefthook-installer/bin/lefthook_darwin_x86_64/lefthook
+ bundle exec lefthook -h
+ yarn lefthook -h
+ pnpm lefthook -h
+ swift package plugin lefthook
+ command -v mint
+ mint run csjones/lefthook-plugin run pre-commit
🌱 Finding latest version of lefthook-plugin
🌱 Cloning lefthook-plugin 1.6.12
🌱 Resolving package
🌱 Building product lefthook
🌱 Copying resources for lefthook: .build/artifacts ...
🌱 Installed lefthook-plugin 1.6.12
🌱 Running lefthook 1.6.12...
│ [lefthook] cmd: [git rev-parse --show-toplevel]
│ [lefthook] dir:
│ [lefthook] err: <nil>
│ [lefthook] out: /Users/levibostian/code/Wendy-iOS

│ [lefthook] cmd: [git rev-parse --git-path hooks]
│ [lefthook] dir:
│ [lefthook] err: <nil>
│ [lefthook] out: .git/hooks

│ [lefthook] cmd: [git rev-parse --git-path info]
│ [lefthook] dir:
│ [lefthook] err: <nil>
│ [lefthook] out: .git/info

│ [lefthook] cmd: [git rev-parse --git-dir]
│ [lefthook] dir:
│ [lefthook] err: <nil>
│ [lefthook] out: .git

│ [lefthook] cmd: [git hash-object -t tree /dev/null]
│ [lefthook] dir:
│ [lefthook] err: <nil>
│ [lefthook] out: 4b825dc642cb6eb9a060e54bf8d69288fbee4904

╭───────────────────────────────────────╮
│ 🥊 lefthook v1.6.12  hook: pre-commit │
╰───────────────────────────────────────╯
│ [lefthook] cmd: [git status --short --porcelain]
│ [lefthook] dir: /Users/levibostian/code/Wendy-iOS
│ [lefthook] err: <nil>
│ [lefthook] out: ?? lefthook

│ [lefthook] cmd: [git diff --name-only --cached --diff-filter=ACMR]
│ [lefthook] dir: /Users/levibostian/code/Wendy-iOS
│ [lefthook] err: <nil>
│ [lefthook] out:
│  lint (skip) no files for inspection
│ [lefthook] cmd: [git stash list]
│ [lefthook] dir: /Users/levibostian/code/Wendy-iOS
│ [lefthook] err: <nil>
│ [lefthook] out:

  ────────────────────────────────────
summary: (done in 0.04 seconds)

LGTM!

levibostian commented 2 months ago

Let me check 1 more thing....

levibostian commented 2 months ago

I wanted to check if you could specify a specific version of lefthook to run with mint. You can!

If your project contains a Mintfile giving the version of csjones/lefthook-plugin you want to run, this git hook picks that up and runs the version you specify. Otherwise, by default, mint will find the latest version of lefthook.

LGTM

mrexox commented 2 months ago

Nice, thank you! I am going to merge this tomorrow and release with the next lefthook version 👌