Skip to content

Feat/v1/apply patches#12

Merged
RohitRavindra-dev merged 5 commits into
mainfrom
feat/v1/apply-patches
Jul 6, 2026
Merged

Feat/v1/apply patches#12
RohitRavindra-dev merged 5 commits into
mainfrom
feat/v1/apply-patches

Conversation

@RohitRavindra-dev

@RohitRavindra-dev RohitRavindra-dev commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added support for a dedicated patches directory during local setup.
    • The app can now apply configured patches before continuing with the rest of the startup flow.
    • Patch reversion is now performed during the revert flow (before overlook processing).
  • Bug Fixes

    • Added validation to detect missing or invalid patch setup and provide a clear recovery message.
    • Patch application/reversion skips missing/invalid items and continues processing remaining patches, with progress/warning messaging.

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c3cb2329-3517-4dfe-b9f1-8f3a760c894e

📥 Commits

Reviewing files that changed from the base of the PR and between bcb4bcb and a56d0de.

📒 Files selected for processing (5)
  • internal/filesystem/initialization.go
  • internal/git/patches.go
  • internal/service/apply/applicator.go
  • internal/service/revert/reverter.go
  • todos.md

📝 Walkthrough

Walkthrough

This PR adds patch-directory setup, shared git command helpers, patch apply/revert operations, and service wiring so apply and revert now process patch files before overlook handling.

Changes

Patches setup and application

Layer / File(s) Summary
Patches directory setup
internal/config/constants.go, internal/filesystem/initialization.go
Adds PATCHES_DIR, creates the patches directory during initialization, and validates its presence before patch operations.
Shared git command helpers
internal/git/utils.go, internal/git/worktrees.go
Moves executeGitCommand and isFileTracked into utils.go and removes their local definitions from worktrees.go.
Patch apply and revert commands
internal/git/patches.go
Adds patch/revert validation helpers plus ApplyPatches and RevertPatches loops that log failures and continue processing.
Apply and revert service wiring
internal/service/apply/applicator.go, internal/service/revert/reverter.go, todos.md
Wires patch handling into apply/revert Run() flows before overlook processing and adds the checklist entries in todos.md.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ApplyRun as apply.Run
  participant Validate as filesystem.ValidatePatchesSetup
  participant ApplyPatches as git.ApplyPatches
  participant GitCLI as git command
  participant RevertRun as revert.Run
  participant RevertPatches as git.RevertPatches

  ApplyRun->>Validate: validate patch setup
  Validate-->>ApplyRun: ok / error
  ApplyRun->>ApplyPatches: apply patch files
  loop each patch file
    ApplyPatches->>GitCLI: git apply --check
    GitCLI-->>ApplyPatches: success / failure
    ApplyPatches->>GitCLI: git apply
    GitCLI-->>ApplyPatches: success / failure
  end
  ApplyPatches-->>ApplyRun: nil

  RevertRun->>Validate: validate patch setup
  Validate-->>RevertRun: ok / error
  RevertRun->>RevertPatches: revert patch files
  loop each patch file
    RevertPatches->>GitCLI: git apply --check --reverse
    GitCLI-->>RevertPatches: success / failure
    RevertPatches->>GitCLI: git apply --reverse
    GitCLI-->>RevertPatches: success / failure
  end
  RevertPatches-->>RevertRun: nil
Loading

Possibly related PRs

  • RohitRavindra-dev/devlocal#4: This PR extends the same internal/service/apply/applicator.go execution path with patch handling before overlook processing.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is directly related to the main change: adding patch application support.
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 feat/v1/apply-patches

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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
internal/git/utils.go (1)

9-9: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Use exec.CommandContext per lint hint.

golangci-lint's noctx rule flags bare exec.Command. Since this is now a shared helper invoked from multiple call sites (including patch generation), adding a context with a sane timeout would also guard against hung git processes.

🤖 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 `@internal/git/utils.go` at line 9, The shared git helper currently uses a bare
exec.Command, which triggers the noctx lint and can hang without cancellation.
Update the command निर्माण in the git utility helper to use exec.CommandContext
with a context that has a reasonable timeout, and thread that context through
the helper’s callers so git invocations can be cancelled cleanly. Keep the fix
localized around the helper that builds the git command so all call sites
benefit, including patch generation.

Source: Linters/SAST tools

🤖 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.

Inline comments:
In `@internal/filesystem/initialization.go`:
- Around line 119-128: In ValidatePatchesSetup, the error returned by the
os.Stat/config.PATCHES_DIR check violates ST1005 because the string ends with
newline/punctuation and starts with a capitalized sentence. Update the
fmt.Errorf message to use lowercase, remove the trailing newline characters, and
keep it as a clean wrapped error string. Make sure the fix is applied in the
ValidatePatchesSetup function without changing the validation logic.

In `@internal/git/utils.go`:
- Around line 8-18: The shared executeGitCommand helper is returning a hardcoded
“Failed to run Skip Worktree” error, which is misleading for callers like
isFileTracked and future git usages from Generate. Update executeGitCommand to
accept a caller-specific operation/context string and use that in the error
returned from cmd.CombinedOutput, so the message matches the actual git command
being run instead of always mentioning Skip Worktree.

---

Nitpick comments:
In `@internal/git/utils.go`:
- Line 9: The shared git helper currently uses a bare exec.Command, which
triggers the noctx lint and can hang without cancellation. Update the command
निर्माण in the git utility helper to use exec.CommandContext with a context that
has a reasonable timeout, and thread that context through the helper’s callers
so git invocations can be cancelled cleanly. Keep the fix localized around the
helper that builds the git command so all call sites benefit, including patch
generation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ffcb82d5-5b49-4eae-8300-e73dafe2b137

📥 Commits

Reviewing files that changed from the base of the PR and between d583e2f and 42cbed2.

📒 Files selected for processing (7)
  • cmd/apply.go
  • internal/config/constants.go
  • internal/filesystem/initialization.go
  • internal/git/patches.go
  • internal/git/utils.go
  • internal/git/worktrees.go
  • internal/service/apply/applicator.go
💤 Files with no reviewable changes (1)
  • internal/git/worktrees.go

Comment thread internal/filesystem/initialization.go
Comment thread internal/git/utils.go

@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.

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (1)
internal/git/patches.go (1)

28-40: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

ApplyPatches always returns nil, silently swallowing failures.

Both checkPatchValidity and patchFile failures are only logged with fmt.Printf; the loop always continues or falls through, and the function unconditionally returns nil at Line 39. This makes the error return type misleading — the caller's if err := git.ApplyPatches(patchFiles); err != nil { return err } in internal/service/apply/applicator.go (Line 23) is effectively dead code. Any patch that fails to apply or fails --check validation will be silently ignored, and Run() will continue on to applyOverlook and print a completion message despite the failure.

🐛 Proposed fix: propagate patch errors
+import "errors"
+
 func ApplyPatches(filesToPatch []string) error {
+	var errs []error
 	for _, filePath := range filesToPatch {
 		if err := checkPatchValidity(filePath); err != nil {
 			fmt.Printf("\t[Error] while trying to patch file %s : %s\n", filePath, err.Error())
+			errs = append(errs, err)
 			continue
 		}
 		if err := patchFile(filePath); err != nil {
 			fmt.Printf("\t[Error] while trying to patch file %s : %s\n", filePath, err.Error())
+			errs = append(errs, err)
 		}
 	}

-	return nil
+	return errors.Join(errs...)
 }
🤖 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 `@internal/git/patches.go` around lines 28 - 40, `ApplyPatches` currently logs
`checkPatchValidity` and `patchFile` failures but always returns nil, so callers
like the one in `applicator.go` never see patch errors. Update `ApplyPatches` to
propagate failures instead of continuing silently: keep the first error (or wrap
with file context) and return it after the loop, and only continue when that
behavior is explicitly intended. Use the existing `checkPatchValidity` and
`patchFile` calls in `internal/git/patches.go` to ensure any validation or apply
failure causes the function’s error return to be non-nil.
🧹 Nitpick comments (1)
internal/git/utils.go (1)

9-9: 🩺 Stability & Availability | 🔵 Trivial | ⚖️ Poor tradeoff

Consider exec.CommandContext instead of exec.Command.

Static analysis flags this as missing a context/timeout, which could let a hung git subprocess block the caller indefinitely on this shared helper.

🤖 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 `@internal/git/utils.go` at line 9, The git command helper currently uses
exec.Command without any cancellation or timeout, which can leave a hung
subprocess blocking callers indefinitely. Update the shared helper in
internal/git/utils.go to accept and use a context, and switch the command
creation at the cmd := exec.Command("git", args...) call site to
exec.CommandContext so callers can enforce cancellation and timeouts; keep the
rest of the git invocation behavior unchanged.

Source: Linters/SAST tools

🤖 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.

Inline comments:
In `@internal/service/apply/applicator.go`:
- Line 19: The warning message in applicator.go contains typos in the string
printed by the apply logic. Update the message in the relevant print statement
so “patche” becomes “patch” and “devloca” becomes “devlocal”, keeping the rest
of the warning text unchanged.

---

Outside diff comments:
In `@internal/git/patches.go`:
- Around line 28-40: `ApplyPatches` currently logs `checkPatchValidity` and
`patchFile` failures but always returns nil, so callers like the one in
`applicator.go` never see patch errors. Update `ApplyPatches` to propagate
failures instead of continuing silently: keep the first error (or wrap with file
context) and return it after the loop, and only continue when that behavior is
explicitly intended. Use the existing `checkPatchValidity` and `patchFile` calls
in `internal/git/patches.go` to ensure any validation or apply failure causes
the function’s error return to be non-nil.

---

Nitpick comments:
In `@internal/git/utils.go`:
- Line 9: The git command helper currently uses exec.Command without any
cancellation or timeout, which can leave a hung subprocess blocking callers
indefinitely. Update the shared helper in internal/git/utils.go to accept and
use a context, and switch the command creation at the cmd := exec.Command("git",
args...) call site to exec.CommandContext so callers can enforce cancellation
and timeouts; keep the rest of the git invocation behavior unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a7d6cc94-5ab1-4129-ab98-58b20da201e6

📥 Commits

Reviewing files that changed from the base of the PR and between 42cbed2 and bcb4bcb.

📒 Files selected for processing (3)
  • internal/git/patches.go
  • internal/git/utils.go
  • internal/service/apply/applicator.go

Comment thread internal/service/apply/applicator.go Outdated
@RohitRavindra-dev RohitRavindra-dev merged commit bfcea3f into main Jul 6, 2026
1 of 2 checks passed
@RohitRavindra-dev RohitRavindra-dev deleted the feat/v1/apply-patches branch July 6, 2026 18:25
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