moonrepo / moon

A build system and monorepo management tool for the web ecosystem, written in Rust.
https://moonrepo.dev/moon
MIT License
2.81k stars 154 forks source link

[bug] GIT hooks synchronization not working on windows under git bash #1558

Open sybernatus opened 1 month ago

sybernatus commented 1 month ago

Describe the bug

I'm trying to setup git hooks via moon on windows under GIT bash. The issue is that under GIT bash, moon sync hooks will deploy under .git/hooks/pre-commit, a hook that is calling the .\.moon\hooks\pre-commit.ps1 (powershell) file instead of .\.moon\hooks\pre-commit (bash):

#!/bin/sh
powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -File ".\.moon\hooks\pre-commit.ps1" $1 $2 $3

Steps to reproduce

  1. Create your hook under .moon/hooks/pre-commit.

  2. Add the hook config under .moon/workspace.yml

    ...
    vcs:
    manager: 'git'
    syncHooks: true
    hooks:
    pre-commit:
      - 'pre-commit run'
    ...
  3. Run moon sync hooks under GIT bash

  4. Add and commit `git commit -am "test"

error: pre-commit : The term 'pre-commit' is not recognized as the name of cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:........moon\hooks\pre-commit.ps1:7 char:1

Expected behavior Under windows & GIT bash, when syncing hooks, the hook that should be used is the bash one instead of the powershell one.

Screenshots

Environment

moon --version
moon 1.23.1

Additional context Here also the file pre-commit.ps1 generated

#!/usr/bin/env powershell
$ErrorActionPreference = 'Stop'

# Automatically generate by moon. DO NOT MODIFY!
# https://moonrepo.dev/docs/guides/vsc-hooks

pre-commit run

EDIT: I think I misunderstood how it work. I didn't notice that the file generated by moon sync hooks was based on the vcs.hooks. commands. But the issue remains the same, the sync generate the ps1 that is called from git hooks. But as I'm using GIT bash, it'd be better to generate the bash version of the hook and not the ps1.

milesj commented 1 month ago

Yah right now Windows assumes powershell. Let me add a setting to force it to Bash.