Skip to content

fix(hooks): expand ~ in core.hooksPath before resolving install target#554

Merged
safishamsi merged 1 commit into
Graphify-Labs:v5from
Koushik-Salammagari:fix/547-hooks-tilde-expansion
May 2, 2026
Merged

fix(hooks): expand ~ in core.hooksPath before resolving install target#554
safishamsi merged 1 commit into
Graphify-Labs:v5from
Koushik-Salammagari:fix/547-hooks-tilde-expansion

Conversation

@Koushik-Salammagari

Copy link
Copy Markdown

Problem

When .gitconfig sets:

[core]
    hooksPath = ~/gitconfig/hooks

graphify hook install installs into <repo>/~/gitconfig/hooks instead of the user's home-relative path. The tilde is treated as a literal directory name.

Root cause: _hooks_dir() built Path(custom) from the raw git config string without calling .expanduser().

Fix

Add .expanduser() immediately after constructing the path from the config value, before the is_absolute() / root-relative fallback:

p = Path(custom).expanduser()

Testing

Added test_hooks_dir_expands_tilde in tests/test_hooks.py:

  • patches $HOME so ~/custom_hooks resolves to a known temp directory
  • stubs subprocess.run to return a tilde-form core.hooksPath
  • asserts _hooks_dir() returns the fully expanded absolute path

All 15 hook tests pass.

Fixes #547

When a user configures core.hooksPath = ~/gitconfig/hooks in .gitconfig,
_hooks_dir() was constructing Path("~/gitconfig/hooks") without calling
expanduser(), so hooks were installed into <repo>/~/gitconfig/hooks instead
of the intended absolute path.

Add Path.expanduser() call immediately after reading the raw string from
git config, before the is_absolute() / root-relative fallback logic.

Fixes Graphify-Labs#547
rosschurchill added a commit to rosschurchill/graphify-super that referenced this pull request Apr 27, 2026
Path("~/.git-hooks") keeps the literal tilde; .expanduser() converts it
to the real home directory so install writes to the correct location.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@safishamsi
safishamsi merged commit e194782 into Graphify-Labs:v5 May 2, 2026
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.

Hooks Install isn't explanding the ~

2 participants