Skip to content

fix: improve error messages when git executable not found or Husky path unconfigured#165

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-github-actions-git-command-error
Draft

fix: improve error messages when git executable not found or Husky path unconfigured#165
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-github-actions-git-command-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 12, 2026

When dotnet husky run fails because git isn't in PATH or husky install was never run (common in CI), the error output was misleading — "failed to execute command 'git'" was emitted for all failures (including non-zero exit codes), and "Could not find Husky path" gave no actionable guidance.

Changes

  • HuskyCliWrap.csExecBufferedAsync now distinguishes executable-not-found (Win32Exception NativeErrorCode 2/3) from other failures:

    • Not found → "'git' executable not found. Make sure 'git' is installed and available in your PATH."
    • Other failure → existing "failed to execute command 'git'" message retained
  • Git.csGetHuskyPath() error message updated from the opaque "Could not find Husky path" to "Could not find Husky path. Make sure Husky is installed (run: dotnet husky install)" — covering the common CI case where husky install was never run

  • GitTests.cs — Added unit test verifying GetHuskyPathAsync() throws a CommandException containing the dotnet husky install hint on failure

  • GitErrorMessageTests.cs — Added Docker-based integration tests that simulate the real failure scenarios:

    • HuskyRun_WhenHuskyIsNotInstalled_ShouldShowInstallHintInErrorMessage — simulates the exact CI scenario from the issue (tools restored but dotnet husky install never run), verifies stderr contains "dotnet husky install"
    • HuskyRun_WhenGitIsNotAvailable_ShouldShowHelpfulErrorMessage — hides the git binary to simulate it being absent from PATH, verifies the error output contains "not found" and "PATH"

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works
  • I have made corresponding changes to the documentation
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes
  • I did test corresponding changes on Windows
  • I did test corresponding changes on Linux
  • I did test corresponding changes on Mac
Original prompt

This section details on the original issue you should resolve

<issue_title>GitHub Actions failed to execute command 'git' for dotnet project that works locally?</issue_title>
<issue_description>### Version

0.7.2

Details

Pre-commit hooks work fine locally
I can run dotnet husky run locally for testing.
I added a dotnet husky run as part of my github actions test steps.
When I test the action locally using Nektos ACT it works fine.

When my action runs on github I get this error:

4s
Run dotnet tool restore
  dotnet tool restore
  dotnet husky run
  shell: /usr/bin/bash -e {0}
  env:
    DOTNET_ROOT: /usr/share/dotnet
Tool 'csharpier' (version '1.0.3') was restored. Available commands: csharpier
Tool 'husky' (version '0.7.2') was restored. Available commands: husky

Restore was successful.
[Husky] 🚀 Loading tasks ...
failed to execute command 'git'
Could not find Husky path
Error: Process completed with exit code 1.

I found an issue with similar error, but this prjoctect has only 1 root and is in the root.

Any ideas what I'm doing wrong?

task runner:

{
    "$schema": "https://alirezanet.github.io/Husky.Net/schema.json",
    "tasks": [
        {
            "name": "CSharpier Format",
            "command": "dotnet",
            "args": [
                "csharpier",
                "format",
                "--log-level=debug",
                "${staged}"
            ],
            "include": [
                "**/*.cs"
            ]
        },
        {
            "name": ".Net Format",
            "command": "dotnet",
            "args": [
                "format",
                "style",
                "--verify-no-changes",
                "--severity=info",
                "--verbosity=detailed",
                "--exclude-diagnostics=IDE0055"
            ],
            "include": [
                "**/*.cs"
            ]
        }
    ]
}

Github actions:

  test:
    name: Test
    runs-on: ubuntu-latest

    steps:

      # https://github.com/marketplace/actions/setup-net-core-sdk
      - name: Setup .NET SDK
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: "9.x"

      # https://github.com/marketplace/actions/checkout
      - name: Checkout code
        uses: actions/checkout@v4

     # Format checks
      - name: Format checks
        run: |
          dotnet tool restore
          dotnet husky run

        # https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test
      - name: Run unit tests
        run: dotnet test ./PlexCleanerTests/PlexCleanerTests.csproj

Steps to reproduce

  1. Run locally, ok
  2. Run locally in github actions, ok
  3. Run remote github actions, fail</issue_description>

<agent_instructions>if I'm not wrong we should just improve the error message in this case right?
</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@alirezanet Hi @ptr727, The error says `failed to execute command 'git'`, Husky is relying on the locally installed Git, and in your case, the remote environment doesn’t have Git installed — that’s why it’s failing during the GitHub Action run. Make sure Git is available in that environment for the hook to work. Or you can simply [disable Husky](https://alirezanet.github.io/Husky.Net/guide/automate.html#disable-husky-in-ci-cd-pipelines) in the GitHub actions:

You can set the HUSKY environment variable to 0 in order to disable husky in CI/CD pipelines.</comment_new>
<comment_new>@alirezanet
Hi @ptr727,
Thanks for the investigation, yeah the husky install is always required so I think we should try to improve the error message in this case</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…t configured

Co-authored-by: alirezanet <7004080+alirezanet@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix GitHub Actions 'failed to execute command git' for dotnet project fix: improve error messages when git executable not found or Husky path unconfigured Mar 12, 2026
Copilot AI requested a review from alirezanet March 12, 2026 18:00
alirezanet

This comment was marked as duplicate.

Copy link
Copy Markdown
Owner

@alirezanet alirezanet left a comment

Choose a reason for hiding this comment

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

would be nice to have a integration test to simulate the problem and make sure the error message is what we expect.

Co-authored-by: alirezanet <7004080+alirezanet@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 12, 2026

would be nice to have a integration test to simulate the problem and make sure the error message is what we expect.

Added two integration tests in GitErrorMessageTests.cs (commit e3c48f0):

  1. HuskyRun_WhenHuskyIsNotInstalled_ShouldShowInstallHintInErrorMessage — simulates the exact CI scenario from the issue: git is present, tools are restored, but dotnet husky install was never run. Verifies stderr contains "dotnet husky install".

  2. HuskyRun_WhenGitIsNotAvailable_ShouldShowHelpfulErrorMessage — hides the git binary with mv $(which git) /tmp/git_backup to simulate it being missing from PATH. Verifies the error output contains "not found" and "PATH" (from the new message: "'git' executable not found. Make sure 'git' is installed and available in your PATH.").

Copilot AI requested a review from alirezanet March 12, 2026 18:41
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.

GitHub Actions failed to execute command 'git' for dotnet project that works locally?

2 participants