Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expand Swift integration with Mint support #724

Merged
merged 1 commit into from
May 24, 2024

Conversation

levibostian
Copy link
Contributor

@levibostian levibostian commented May 21, 2024

Building on top of previous PR that added Swift support.

⚡ 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!

☑️ Checklist

  • Check locally
  • Add tests
  • Add documentation

@mrexox
Copy link
Member

mrexox commented May 22, 2024

Thank you! Have you tested this locally?

@levibostian
Copy link
Contributor Author

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
Copy link
Member

mrexox commented May 22, 2024

@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
Copy link
Contributor Author

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
Copy link
Member

mrexox commented May 23, 2024

@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
Copy link
Contributor Author

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
Copy link
Contributor Author

Let me check 1 more thing....

@levibostian
Copy link
Contributor Author

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
Copy link
Member

mrexox commented May 23, 2024

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

@mrexox mrexox merged commit 04a6d51 into evilmartians:master May 24, 2024
19 checks passed
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.

None yet

2 participants