Skip to content

Fix: Resolve git-lfs and husky hooks conflict in devcontainer setup #481

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

aicodexp
Copy link

@aicodexp aicodexp commented Aug 6, 2025

Problem

When starting the devcontainer, the setup fails due to a conflict between git-lfs and husky hooks:

Running the postCreateCommand from Feature 'ghcr.io/devcontainers/features/git-lfs:1'...
[16420 ms] Start: Run in container: /bin/sh -c /usr/local/share/pull-git-lfs-artifacts.sh
Fetching git lfs artifacts...
Hook already exists: pre-push
        #!/usr/bin/env sh
        . "$(dirname "$0")/h"
To resolve this, either:
  1: run `git lfs update --manual` for instructions on how to merge hooks.
  2: run `git lfs update --force` to overwrite your hook.
[16922 ms] postCreateCommand from Feature 'ghcr.io/devcontainers/features/git-lfs:1' failed with exit code 2.

Root Cause Analysis

The issue occurs because:

  1. Husky runs first during npm install and sets core.hookspath to .husky/_
  2. Git LFS feature runs later and attempts to install its hooks, but finds existing husky hooks
  3. The conflict causes the devcontainer setup to fail

Note: Reversing the execution order wouldn't solve the problem either. If git-lfs ran first and modified .git/hooks, husky would later change core.hookspath to .husky/_, effectively bypassing the git-lfs hooks and leaving git-lfs silently improperly configured.

Current Hook Structure

  • Husky creates hooks in .husky/_/ that source .husky/_/h
  • The h script then calls any matching hook script in .husky/ if it exists
  • Git LFS needs to inject its own hook logic into this chain

Solution

This PR implements a controlled merge of git-lfs hooks with husky's hook system:

  1. Let husky complete its setup - maintains the existing hook infrastructure
  2. Delay git-lfs hook installation - prevents the initial conflict
  3. Merge hooks in postCreateCommand - combine git-lfs functionality with husky's hook chain

Implementation Details

The solution adds a custom script that:

  • Extracts git-lfs hook content
  • Merges it with husky's template structure
  • Ensures both git-lfs and husky hooks execute correctly

Related Issues

aicodexp added 19 commits August 6, 2025 18:00
as it is redundant to git-lfs feature
'git lfs install' which sets the .git/hooks

CAUTION: relies heavily on current implementation of https://github.com/devcontainers/features/blob/main/src/git-lfs/install.sh

- an option like 'skipHooks' over there is an idea maybe
that as this will be set up properly
using git lfs install
to ensure proper execution order with Husky
@aicodexp
Copy link
Author

aicodexp commented Aug 6, 2025

@microsoft-github-policy-service agree

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.

3 participants