Skip to content

feat(setup): support custom Git hooks directories - #93

Merged
chenjiahan merged 1 commit into
mainfrom
chenjiahan/feat-setup-custom-hooks-dir
Jul 29, 2026
Merged

feat(setup): support custom Git hooks directories#93
chenjiahan merged 1 commit into
mainfrom
chenjiahan/feat-setup-custom-hooks-dir

Conversation

@chenjiahan

Copy link
Copy Markdown
Member

Summary

This PR lets rs setup install Git hooks in a custom cwd-relative directory and from nested projects. It adds --hooks-dir, derives the repository-relative core.hooksPath from Git's current prefix, and normalizes Windows path separators. Integration coverage verifies root and nested installation, paths with spaces, and real hook execution.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying rstack-cli with  Cloudflare Pages  Cloudflare Pages

Latest commit: 06a74d3
Status: ✅  Deploy successful!
Preview URL: https://09d32a08.rstack-cli.pages.dev
Branch Preview URL: https://chenjiahan-feat-setup-custom.rstack-cli.pages.dev

View logs

@chenjiahan
chenjiahan merged commit 55f5675 into main Jul 29, 2026
4 checks passed
@chenjiahan
chenjiahan deleted the chenjiahan/feat-setup-custom-hooks-dir branch July 29, 2026 07:34
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The setup CLI adds a --hooks-dir <path> option with duplicate and missing-value validation. The hook installer now accepts options for cwd and hooksDir, resolves repository-relative paths using Git’s prefix, normalizes separators and line endings, and configures the computed core.hooksPath. Tests cover custom directories, nested projects, CLI errors, idempotency, failures, permissions, and hook execution.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: adding support for custom Git hooks directories in setup.
Description check ✅ Passed The description is directly related to the changeset and accurately summarizes the new hooks-dir support and nested install behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chenjiahan/feat-setup-custom-hooks-dir

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/rstack/src/setup/install.ts (1)

78-94: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Reject absolute hooks directories.

At repository root, --hooks-dir /tmp/hooks makes Line 80 configure Git with /tmp/hooks/_ (an absolute path), while Line 90 writes to <cwd>/tmp/hooks/_. Git therefore does not run the generated hooks. Validate that the normalized directory is relative, including leading / or \, drive-rooted, and UNC paths; add a regression test.

Proposed fix
 const prefix = removeLineEnding(prefixResult.stdout).replaceAll('\\', '/');
 const resolvedHooksDir = hooksDir.replaceAll('\\', '/');
+if (path.posix.isAbsolute(resolvedHooksDir) || path.win32.isAbsolute(hooksDir)) {
+  return fail('invalid-hooks-dir', 'Hooks directory must be relative to the current directory.');
+}
 const hooksPath = `${prefix}${resolvedHooksDir}/_`;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/rstack/src/setup/install.ts` around lines 78 - 94, Validate the
normalized hooks directory before constructing hooksPath or writing files,
rejecting absolute paths including leading slash or backslash, drive-rooted
paths, and UNC paths. Apply this validation in the setup flow around
resolvedHooksDir and return the existing failure form for invalid input;
preserve relative-directory behavior, and add a regression test covering an
absolute hooks directory such as /tmp/hooks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/rstack/src/setup/install.ts`:
- Around line 78-94: Validate the normalized hooks directory before constructing
hooksPath or writing files, rejecting absolute paths including leading slash or
backslash, drive-rooted paths, and UNC paths. Apply this validation in the setup
flow around resolvedHooksDir and return the existing failure form for invalid
input; preserve relative-directory behavior, and add a regression test covering
an absolute hooks directory such as /tmp/hooks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4f447f4a-9a55-48b8-93c8-b7108ef0da4b

📥 Commits

Reviewing files that changed from the base of the PR and between 07cdb8a and 06a74d3.

📒 Files selected for processing (4)
  • packages/rstack/src/setup/index.ts
  • packages/rstack/src/setup/install.ts
  • packages/rstack/tests/cli/setup/index.test.ts
  • packages/rstack/tests/setup/install.test.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 06a74d3320

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


const prefix = removeLineEnding(prefixResult.stdout).replaceAll('\\', '/');
const resolvedHooksDir = hooksDir.replaceAll('\\', '/');
const hooksPath = `${prefix}${resolvedHooksDir}/_`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject absolute hook directory paths

When a user passes an absolute value such as --hooks-dir /tmp/hooks, this constructs an absolute core.hooksPath, but the later path.join(cwd, resolvedHooksDir, '_') writes the generated files beneath the current repository (for example, /repo/tmp/hooks/_). Setup therefore reports success while Git looks in /tmp/hooks/_ and runs no generated hooks. Although the help describes the option as relative, the parser currently accepts this value, so validate and reject absolute paths before installation.

Useful? React with 👍 / 👎.

);
}

const prefix = removeLineEnding(prefixResult.stdout).replaceAll('\\', '/');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve literal backslashes in repository prefixes

On POSIX, backslash is a valid filename character rather than a path separator. If setup runs from a directory such as a literal front\end, Git returns that exact prefix, but this replacement changes it to front/end; the files are still written beneath the original cwd, while core.hooksPath points to a nonexistent directory, so hooks silently stop running. Only apply separator normalization on platforms where backslash is actually a separator.

Useful? React with 👍 / 👎.

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