Skip to content

[githooks] Support git worktrees and relative hooksPath - #193170

Merged
jtmcdole merged 3 commits into
flutter:masterfrom
mdebbar:githooks_worktree
Sep 24, 2026
Merged

jtmcdole merged 3 commits into
flutter:masterfrom
mdebbar:githooks_worktree

Conversation

@mdebbar

@mdebbar mdebbar commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Bug with Current Behavior

In engine/src/flutter/tools/githooks/setup.py, core.hooksPath is set as an absolute filesystem path in the repository configuration (.git/config).

In environments with Git worktrees (git worktree add):

  1. Repository configuration (.git/config) is shared across all worktrees. Setting core.hooksPath globally affects all worktrees, including those where engine dependencies (such as the Dart SDK fetched via gclient sync) are not installed. Subsequent Git operations (git push, git rebase) in unconfigured worktrees or the main repository fail when Git attempts to run missing hook binaries.
  2. Setting an absolute path ties core.hooksPath to a specific worktree directory. If that worktree is deleted or moved, Git hooks fail across all other worktrees.
  3. Absolute paths prevent portability across checkout locations.

How this PR Fixes It

  1. Worktree detection & scoping: Detects execution within a Git worktree by comparing --git-dir against --git-common-dir. When in a worktree, enables extensions.worktreeConfig and applies git config --worktree so core.hooksPath is scoped strictly to the active worktree. This prevents hook failures in uninitialized worktrees or the main repository.
  2. Relative hook path: Sets core.hooksPath to a relative path from the repository root (os.path.relpath(githooks, repo_root)) normalized with forward slashes for cross-platform portability.

Fixes: N/A (no existing issue found in flutter/flutter).

Pre-launch Checklist

Tests: test-exempt (developer tooling / git configuration script).

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Sep 22, 2026
@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request modifies engine/src/flutter/tools/githooks/setup.py to add support for Git worktrees by introducing helper functions to detect worktrees and resolve the repository root, and conditionally applying the --worktree flag during hook configuration. The review feedback suggests simplifying this implementation by removing the worktree-specific configuration entirely, as setting a relative path for core.hooksPath naturally resolves correctly across all worktrees. Additionally, the feedback recommends using forward slashes in the relative path to ensure cross-platform compatibility on Windows.

Comment thread engine/src/flutter/tools/githooks/setup.py Outdated
Comment thread engine/src/flutter/tools/githooks/setup.py Outdated
@github-actions github-actions Bot added the engine flutter/engine related. See also e: labels. label Sep 22, 2026
@mdebbar mdebbar changed the title [githooks] Support git worktrees and relative hooksPath [githooks] Use relative path for core.hooksPath Sep 22, 2026
@mdebbar

mdebbar commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the Git hooks setup script to configure core.hooksPath using a relative path calculated from the repository root. The review feedback recommends renaming the new helper function to get_repo_root to comply with the Google Python Style Guide, and expanding the exception handling to catch OSError in case the git executable is missing.

Comment thread engine/src/flutter/tools/githooks/setup.py Outdated
Comment thread engine/src/flutter/tools/githooks/setup.py Outdated
@mdebbar
mdebbar force-pushed the githooks_worktree branch 2 times, most recently from d6b9dbc to de0fce8 Compare September 23, 2026 17:22
Currently, setup.py sets core.hooksPath using an absolute filesystem path in the repository configuration.

In environments with Git worktrees, repository configuration (.git/config) is shared across all worktrees. Setting core.hooksPath globally in .git/config impacts all worktrees, even those where engine dependencies (such as the Dart SDK fetched via gclient sync) have not been installed. Git operations in unconfigured worktrees (or the root repository) then fail when attempting to run non-existent hook binaries.

This change:
- Detects if running inside a Git worktree.
- Enables extensions.worktreeConfig and applies git config --worktree to scope core.hooksPath strictly to the active worktree.
- Uses a relative path from the repository root for core.hooksPath with forward slashes for cross-platform portability.
@flutter-dashboard

Copy link
Copy Markdown

CI had a failure that stopped further tests from running. We need to investigate to determine the root cause.

SHA at time of execution: 4bf812c.

Possible causes:

  • Configuration Changes: The .ci.yaml file might have been modified between the creation of this pull request and the start of this test run. This can lead to ci yaml validation errors.
  • Infrastructure Issues: Problems with the CI environment itself (e.g., quota) could have caused the failure.

A blank commit, or merging to head, will be required to resume running CI for this PR.

Error Details:

FormatException: ERROR: Mac_arm64_ios basic_material_app_ios__compile is a new builder added. it needs to be marked bringup: true
If ci.yaml wasn't changed, try `git fetch upstream && git merge upstream/master`



Stack trace:

#0      CiYaml._validate (package:cocoon_service/src/model/ci_yaml/ci_yaml.dart:395:7)
#1      new CiYaml (package:cocoon_service/src/model/ci_yaml/ci_yaml.dart:128:7)
#2      new CiYamlSet (package:cocoon_service/src/model/ci_yaml/ci_yaml.dart:48:23)
#3      CiYamlFetcher._getCiYaml (package:cocoon_service/src/service/scheduler/ci_yaml_fetcher.dart:124:12)
<asynchronous suspension>
#4      Scheduler.getPresubmitTargets (package:cocoon_service/src/service/scheduler.dart:1064:20)
<asynchronous suspension>
#5      Scheduler._getTestsForStage (package:cocoon_service/src/service/scheduler.dart:1367:14)
<asynchronous suspension>
#6      Scheduler._runCiTestingStage (package:cocoon_service/src/service/scheduler.dart:1408:30)
<asynchronous suspension>
#7      Scheduler.proceedToCiTestingStage (package:cocoon_service/src/service/scheduler.dart:1517:7)
<asynchronous suspension>
#8      Scheduler._closeSuccessfulEngineBuildStage (package:cocoon_service/src/service/scheduler.dart:1312:5)
<asynchronous suspension>
#9      Scheduler.processCheckRunCompleted (package:cocoon_service/src/service/scheduler.dart:1253:11)
<asynchronous suspension>
#10     PresubmitSubscription._processBuild (package:cocoon_service/src/request_handlers/presubmit_subscription.dart:228:7)
<asynchronous suspension>
#11     PresubmitSubscription.post (package:cocoon_service/src/request_handlers/presubmit_subscription.dart:119:5)
<asynchronous suspension>
#12     RequestHandler.service (package:cocoon_service/src/request_handling/request_handler.dart:42:20)
<asynchronous suspension>
#13     SubscriptionHandler.service (package:cocoon_service/src/request_handling/subscription_handler.dart:134:5)
<asynchronous suspension>
#14     createServer.<anonymous closure> (package:cocoon_service/server.dart:462:7)
<asynchronous suspension>
#15     main.<anonymous closure>.<anonymous closure> (file:///app/app_dart/bin/gae_server.dart:192:9)
<asynchronous suspension>

@mdebbar mdebbar changed the title [githooks] Use relative path for core.hooksPath [githooks] Support git worktrees and relative hooksPath Sep 24, 2026
jtmcdole
jtmcdole previously approved these changes Sep 24, 2026
@jtmcdole

Copy link
Copy Markdown
Member

Thank you for making this quality of life change!

@mdebbar mdebbar added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 24, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 24, 2026
@auto-submit

auto-submit Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/193170, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label.

@mdebbar mdebbar added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 24, 2026

@jtmcdole jtmcdole left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

RSLGTM

@jtmcdole
jtmcdole added this pull request to the merge queue Sep 24, 2026
Merged via the queue into flutter:master with commit d54022a Sep 24, 2026
23 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants