Skip to content

feat: allow copy hook to omit to#77

Merged
satococoa merged 6 commits intomainfrom
fix/copy-hook-from-only
Jan 31, 2026
Merged

feat: allow copy hook to omit to#77
satococoa merged 6 commits intomainfrom
fix/copy-hook-from-only

Conversation

@satococoa
Copy link
Owner

@satococoa satococoa commented Jan 15, 2026

Summary

  • allow copy hooks to omit "to" and default it to "from" for relative paths (absolute "from" still requires explicit "to")
  • update config validation and tests to reflect the new default
  • document the shorthand in README and architecture docs

Closes #75.

Testing

  • go tool task test

Summary by CodeRabbit

  • New Features

    • Copy hooks may omit "to"; it now defaults to the "from" value.
  • Bug Fixes

    • Post-create copy and symlink operations now reject when source and destination refer to the same path or the same underlying file (including symlink-to-source), preventing accidental overwrites.
  • Documentation

    • README and architecture docs updated to describe the copy-hook default behavior.
  • Tests

    • Added tests for "to" defaulting and for self-path/symlink-to-source rejection.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings January 15, 2026 15:55
@coderabbitai
Copy link

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

Defaults for copy hooks now apply in-place: when a copy hook has from but omits to, to is set to from (relative paths only). Docs and tests updated. Runtime hook execution now rejects operations where source and destination refer to the same file (including when destination is a symlink to the source).

Changes

Cohort / File(s) Summary
Documentation
README.md, docs/architecture.md
Clarified copy-hook semantics: to defaults to from when omitted (relative paths only); updated examples and explanatory notes.
Config defaults & validation
internal/config/config.go, internal/config/config_test.go
Added Config.ApplyDefaults() and Hook.ApplyDefaults(); Load/Save call ApplyDefaults before Validate; copy hooks default to = from when from is relative; validation treats absolute from without to as an error; tests added/updated.
Hook execution & tests
internal/hooks/executor.go, internal/hooks/executor_test.go
Added ensureDistinctPaths(src,dst,srcInfo) and invoked it from copy and symlink execution to reject identical source/destination (including symlink-to-source); moved checks to run before creating destination dirs; tests added to assert rejection and no side effects.
Module / manifests
go.mod, manifest files
Minor manifest/module adjustments referenced by changes.

Sequence Diagram(s)

sequenceDiagram
    participant Runner as "PostCreate Runner"
    participant Exec as "Hook Executor"
    participant OS as "OS (stat / samefile)"
    participant FS as "Filesystem (mkdir/copy/symlink)"

    rect rgba(200,200,255,0.5)
    Runner->>Exec: invoke copy/symlink hook (from, to)
    end

    rect rgba(200,255,200,0.5)
    Exec->>OS: os.Stat(from) -> srcInfo
    Exec->>OS: os.Lstat(destination) -> dstInfo (if exists)
    OS-->>Exec: srcInfo, dstInfo
    end

    rect rgba(255,200,200,0.5)
    Exec->>OS: os.SameFile(srcInfo, dstInfo)?
    OS-->>Exec: sameFile? (true/false)
    Exec-->>Runner: error "source and destination paths must be different" (if true)
    end

    rect rgba(200,255,255,0.5)
    Exec->>FS: mkdir destination dir (if needed)
    Exec->>FS: perform copy or create symlink
    FS-->>Exec: success/failure
    Exec-->>Runner: result
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • feat: add symlink hook #71 — overlaps with symlink/copy hook execution logic and tests; may interact with the new distinct-path checks.

Poem

🐇 I hop through docs and tests with cheer,

From becomes To when To won't appear,
I nose each path to keep them apart,
I stop colliding files before they start,
A tidy hop — no copies collide.

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Out of Scope Changes check ❓ Inconclusive The PR includes an additional feature (distinct-path validation for copy/symlink hooks) not explicitly requested in issue #75, though the validation itself prevents errors from the new default behavior. Clarify whether the distinct-path validation for preventing source=destination scenarios is in scope for this PR or should be separated into a follow-up issue.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: allow copy hook to omit to' directly and concisely describes the main change: enabling copy hooks to work without an explicit 'to' field, which matches the primary objective of the PR.
Linked Issues check ✅ Passed The PR implements the core requirement from #75: allowing copy hooks to omit 'to' and default it to 'from' value. Config validation updated, tests added, and documentation revised to reflect this behavior.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/copy-hook-from-only

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 and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the copy hook functionality by making the to field optional, defaulting it to the from value when omitted. This provides a convenient shorthand for the common case where files are copied to the same relative path in the new worktree.

Changes:

  • Modified validation logic to allow omitting the to field for copy hooks and automatically default it to from
  • Updated loop iteration to modify hooks by reference, enabling in-place default assignment
  • Added comprehensive test coverage for the new defaulting behavior
  • Updated documentation in README and architecture docs to explain the shorthand

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
internal/config/config.go Modified validation to default to field to from when empty; changed loop to use index-based iteration for in-place mutation
internal/config/config_test.go Updated test expectations and added new tests to verify default behavior at hook and config levels
README.md Added documentation comments and examples showing the to field can be omitted
docs/architecture.md Added note explaining the default behavior for copy hooks

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

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

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: 573df4f0c9

ℹ️ 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".

@satococoa satococoa merged commit 7c7dc3d into main Jan 31, 2026
7 checks passed
@satococoa satococoa deleted the fix/copy-hook-from-only branch January 31, 2026 18:50
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.

[Feature Request] Simplify copy hook configuration when source and destination are identical

1 participant

Comments