Skip to content

Feature: copy repo hooks on init#8

Merged
bjester merged 1 commit intomainfrom
init-helper
Feb 15, 2026
Merged

Feature: copy repo hooks on init#8
bjester merged 1 commit intomainfrom
init-helper

Conversation

@bjester
Copy link
Owner

@bjester bjester commented Feb 15, 2026

Summary

  • Removes automatic chmod for hooks
  • Adds ability to define hooks in a repo and copy them on init

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @bjester, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the gh worktree init command by enabling the automatic copying of repository-defined Git hooks into the local worktree's configuration. This change streamlines the setup process for projects that rely on specific Git hooks, ensuring consistency across development environments. It also refines the handling of hook executability, shifting from an automatic chmod attempt during execution to a more explicit management during hook addition.

Highlights

  • Repository-defined Hooks: Introduced the ability to define Git hooks within a repository under .gh/worktree/hooks/ which are automatically copied to the local worktree's configuration directory upon gh worktree init.
  • Hook Executability Handling: Modified the hook execution logic to no longer automatically chmod hook files to make them executable. Instead, hooks are now expected to be executable when copied, and a new add context manager ensures executability for newly added hooks.
  • New Hook Management API: Added a new add context manager to the Hooks class, providing a controlled way to write new hook files and automatically set their executable permissions. A HookExists exception was also introduced to prevent overwriting existing hooks.
  • Test Suite Refactoring: Refactored the test suites for init commands and hooks to use unittest.TestCase classes, improving test structure and setup/teardown procedures. New tests were added to cover the hook copying functionality.
Changelog
  • src/gh_worktree/commands/init.py
    • Imported HookExists from gh_worktree.hooks.
    • Updated pre_init and post_init hook firing to pass project_dir instead of repo_target.destination_dir.
    • Added a new private method _add_hooks to check for and copy repository-defined hooks during initialization.
    • Called _add_hooks after saving the repository configuration.
  • src/gh_worktree/hooks.py
    • Imported contextmanager from contextlib.
    • Added a git_path property to the Hook enum to define the expected path for hooks within a Git repository.
    • Defined a new exception HookExists.
    • Removed the automatic chmod attempt within the fire method; now it only checks for executability and skips if not executable.
    • Introduced an add context manager to safely create and write new hook files, ensuring they are made executable upon creation.
  • tests/commands/test_init.py
    • Added necessary imports for glob, os, pathlib, shutil, TestCase, and MagicMock.
    • Refactored normalize tests into more granular functions.
    • Converted RepositoryTarget related tests into a RepositoryTargetTestCase class.
    • Converted InitCommand related tests into an InitCommandTestCase class, including setUp and tearDown methods for better test isolation.
    • Updated assertions for pre_init and post_init hook firing to reflect the change in passed arguments.
    • Added a new test case test_call__installs_hooks to verify the functionality of copying hooks from the repository.
  • tests/test_hooks.py
    • Added imports for glob, shutil, mock, and TestCase.
    • Replaced StubContext with the actual Context class for testing.
    • Refactored hook tests into a HooksTestCase class with setUp and tearDown methods.
    • Updated _check_allowed tests to use mock.patch for input.
    • Modified fire tests to use mock.patch for _check_allowed and stream_exec.
    • Added specific test cases for the new add context manager, including testing for successful addition and HookExists exception handling.
Activity
  • No human activity (comments, reviews) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

github-actions bot commented Feb 15, 2026

🎉 Build Assets are ready!

File Checksum
gh_worktree-0.1.1-py3-none-any.whl ``
gh-worktree.pex ``

Copy link
Contributor

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

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 introduces a valuable feature for copying repository-defined hooks during the init process. The changes are well-structured, including a logical refactoring of hook execution permissions and a significant improvement in the test suite's structure and coverage. My review identifies a critical bug that would corrupt the copied hook files by stripping newlines, a high-severity issue concerning file line endings on Windows, and a medium-severity suggestion to improve code readability.

@bjester bjester merged commit 15e62c3 into main Feb 15, 2026
10 checks passed
@bjester bjester deleted the init-helper branch February 16, 2026 16: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.

1 participant