Repository navigation
[githooks] Support git worktrees and relative hooksPath - #193170
Conversation
|
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. |
There was a problem hiding this comment.
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.
8818a06 to
3223f42
Compare
3223f42 to
6bbe326
Compare
|
/gemini review |
There was a problem hiding this comment.
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.
d6b9dbc to
de0fce8
Compare
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.
de0fce8 to
4bf812c
Compare
|
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:
A blank commit, or merging to head, will be required to resume running CI for this PR. Error Details: Stack trace: |
|
Thank you for making this quality of life change! |
|
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. |
Bug with Current Behavior
In
engine/src/flutter/tools/githooks/setup.py,core.hooksPathis set as an absolute filesystem path in the repository configuration (.git/config).In environments with Git worktrees (
git worktree add):.git/config) is shared across all worktrees. Settingcore.hooksPathglobally affects all worktrees, including those where engine dependencies (such as the Dart SDK fetched viagclient 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.core.hooksPathto a specific worktree directory. If that worktree is deleted or moved, Git hooks fail across all other worktrees.How this PR Fixes It
--git-diragainst--git-common-dir. When in a worktree, enablesextensions.worktreeConfigand appliesgit config --worktreesocore.hooksPathis scoped strictly to the active worktree. This prevents hook failures in uninitialized worktrees or the main repository.core.hooksPathto 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).