Skip to content

fix: create .git/hooks directory if it doesn't exist#6

Merged
wesm merged 1 commit intoroborev-dev:mainfrom
sinzin91:fix-init
Jan 8, 2026
Merged

fix: create .git/hooks directory if it doesn't exist#6
wesm merged 1 commit intoroborev-dev:mainfrom
sinzin91:fix-init

Conversation

@sinzin91
Copy link
Copy Markdown
Contributor

@sinzin91 sinzin91 commented Jan 8, 2026

Problem

roborev init fails when the .git/hooks directory doesn't exist:

Error: install hook: open /path/to/repo/.git/hooks/post-commit: no such file or directory

This happens in repositories where the hooks directory has been removed or was never created.

Solution

Added os.MkdirAll to create the .git/hooks directory before attempting to write the post-commit hook file.

Changes

  • cmd/roborev/main.go: Added hooks directory creation in both initCmd() and installHookCmd()
  • cmd/roborev/main_test.go: Added comprehensive test TestInitCmdCreatesHooksDirectory that:
    • Creates a git repo without a hooks directory
    • Verifies roborev init succeeds
    • Confirms the hooks directory and post-commit hook are created
    • Validates hook is executable

Testing

All existing tests pass, and the new test confirms the fix:

go test ./cmd/roborev/...
# ok  	github.com/wesm/roborev/cmd/roborev	3.617s

The fix follows TDD methodology:

  1. ✅ Wrote failing test first
  2. ✅ Implemented minimal fix
  3. ✅ Verified test passes

The init and install-hook commands now create the .git/hooks directory
if it doesn't exist before attempting to write the post-commit hook file.
This fixes the "no such file or directory" error when initializing roborev
in repositories where the hooks directory has been removed or never created.

Changes:
- Added os.MkdirAll for hooks directory in initCmd()
- Added os.MkdirAll for hooks directory in installHookCmd()
- Added comprehensive test TestInitCmdCreatesHooksDirectory

Fixes the issue where roborev init would fail with:
Error: install hook: open .git/hooks/post-commit: no such file or directory

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@wesm wesm merged commit 084844b into roborev-dev:main Jan 8, 2026
2 checks passed
@wesm
Copy link
Copy Markdown
Collaborator

wesm commented Jan 8, 2026

thank you!

wesm added a commit that referenced this pull request Jan 8, 2026
- Use os.PathListSeparator instead of hardcoded ":" for Windows compat
- Remove dead cmd = exec.Command() code that was never executed
- Add TestInstallHookCmdCreatesHooksDirectory for install-hook coverage

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

2 participants