git-worktree-precommit-hook-flutter-failure

Unset git environment variables before Flutter analyze in pre-commit hooks.

262|51|Updated Jun 15, 2025
One-click install
npx skills add https://github.com/divinevideo/divine-mobile --skill git-worktree-precommit-hook-flutter-failure
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-worktree-precommit-hook-flutter-failure
Source: https://github.com/divinevideo/divine-mobile/tree/main/.claude/skills/git-worktree-precommit-hook-flutter-failure
Command: npx skills add https://github.com/divinevideo/divine-mobile --skill git-worktree-precommit-hook-flutter-failure

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Pre-commit hooks that run flutter analyze in Flutter projects fail when using git worktrees, causing commits to abort despite there being no actual code issues. The root cause is that git sets GIT_DIR to a worktree-style path during hook execution, which breaks flutter pub get invoked by flutter analyze. This Skill provides a robust workaround: unset GIT_DIR, GIT_INDEX_FILE, and GIT_WORK_TREE after performing required git operations and before flutter/dart commands.

Core Features & Use Cases

  • Stabilizes pre-commit hooks in Flutter worktree workflows where pub get or analyze fails due to git env vars.
  • Minimal, targeted change: introduce an unset step in the pre-commit hook to ensure consistent environment for Flutter tooling.
  • Use Case: A team maintains multiple git worktrees for parallel features; enabling reliable pre-commit checks across all worktrees.

Quick Start

Update your pre-commit hook to unset GIT_DIR, GIT_INDEX_FILE, and GIT_WORK_TREE after the git operations and before flutter/dart commands.

Frequently Asked Questions about git-worktree-precommit-hook-flutter-failure

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does flutter analyze fail in pre-commit hooks when using git worktrees?

Flutter analyze fails in git worktrees because git sets the GIT_DIR environment variable to a worktree-style path during hook execution, which breaks dependency resolution during pub get. Unsetting GIT_DIR, GIT_INDEX_FILE, and GIT_WORK_TREE before flutter commands fixes this.

How do I fix pre-commit hook failures during flutter analyze in a git worktree?

To fix pre-commit hook failures, unset the GIT_DIR, GIT_INDEX_FILE, and GIT_WORK_TREE environment variables in your hook script after completing required git operations but before executing any flutter or dart commands to ensure reliable dependency resolution.

Do I need to unset GIT_WORK_TREE for dart commands in pre-commit hooks?

Yes, you need to unset GIT_WORK_TREE, along with GIT_DIR and GIT_INDEX_FILE, before running dart commands in pre-commit hooks. This prevents git environment variables from interfering with Flutter tooling and dependency resolution in worktree workflows.

Can I run flutter pub get inside a pre-commit hook with git worktrees?

Running flutter pub get inside a pre-commit hook fails with git worktrees because git injects environment variables that disrupt the process. You must unset GIT_DIR, GIT_INDEX_FILE, and GIT_WORK_TREE before invoking flutter commands for pub get to succeed.

What is the best way to stabilize Flutter pre-commit hooks across multiple worktrees?

The best way to stabilize Flutter pre-commit hooks across multiple worktrees is introducing a targeted unset step for GIT_DIR, GIT_INDEX_FILE, and GIT_WORK_TREE. This ensures a consistent environment for Flutter tooling during commits in parallel feature workflows.

Why does manual flutter analyze pass but my pre-commit hook fails in a worktree?

Manual flutter analyze passes because your shell environment is clean, but pre-commit hooks fail because git automatically sets GIT_DIR and related variables during execution. Unsetting these variables before flutter commands ensures the hook matches manual behavior.