Skip to content

fix: use windowsHide for git child processes on Windows#36

Open
700software wants to merge 2 commits intonode-modules:masterfrom
700software:fix/windows-hide-exec-sync
Open

fix: use windowsHide for git child processes on Windows#36
700software wants to merge 2 commits intonode-modules:masterfrom
700software:fix/windows-hide-exec-sync

Conversation

@700software
Copy link
Copy Markdown

@700software 700software commented Mar 31, 2026

Problem I am facing

When last-commit-log runs under pm2 on Windows, there is no visible console. Each execSync can spawn a flashing cmd window, which interferes with typing and is annoying!

Solution

Set windowsHide: true on all child_process.execSync options (shared via baseExecOptions).

Issue

Closes #35

Summary by CodeRabbit

  • Chores
    • Improved Windows user experience by preventing console windows from appearing during background operations.

When running under pm2 there is no visible console; without windowsHide,
Windows spawns flashing cmd windows for each execSync.

close node-modules#35

Made-with: Cursor
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dfb111b7-e8e3-4ccf-8372-4cdd7085af12

📥 Commits

Reviewing files that changed from the base of the PR and between 38de22d and 054db00.

📒 Files selected for processing (1)
  • line-diff.js

📝 Walkthrough

Walkthrough

Adds windowsHide: true option to execSync calls in two files to prevent Windows console windows from appearing when code runs under pm2 process trees.

Changes

Cohort / File(s) Summary
Core git operations
index.js
Added baseExecOptions constant with windowsHide: true and applied it to getLastCommitSync() and getUserNameSync() execSync invocations.
Line diff utility
line-diff.js
Added execOptions constant with windowsHide: true and passed it to the execSync() call.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Behold! The windows shall hide their shameful display,
No more pop-ups dancing whilst pm2 holds sway,
Child processes spawn in silent, peaceful grace,
Developers type uninterrupted in their coding space!

🚥 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 accurately summarizes the main change: adding windowsHide option to git child processes on Windows to prevent cmd window popups.
Linked Issues check ✅ Passed The PR implements all coding requirements from issue #35: adds baseExecOptions with windowsHide, applies it to execSync calls in index.js and line-diff.js consistently.
Out of Scope Changes check ✅ Passed All changes are scoped to the stated objective: adding windowsHide configuration to child_process.execSync calls across the module.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces windowsHide: true to execSync options in index.js to prevent command windows from appearing on Windows. The review feedback suggests extending this change to line-diff.js for completeness and recommends including the cwd option in getUserNameSync to ensure consistency with other git commands.

* Prevents obnoxious cmd window popping up on Windows when process runs via pm2
* instead of via an already visible terminal.
*/
const baseExecOptions = { windowsHide: true };
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The PR description states that windowsHide: true should be set on all execSync options. However, line-diff.js (which is required at the end of this file) also uses execSync but has not been updated in this PR. To ensure the fix is comprehensive, please apply this change to line-diff.js as well.

Copy link
Copy Markdown
Author

@700software 700software Mar 31, 2026

Choose a reason for hiding this comment

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

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
index.js (2)

47-47: Add regression assertions for execSync options.

The current stubs validate command strings/return values but not the second execSync argument, so this PR’s core behavior (windowsHide: true) is not protected by tests. Please add assertions that verify options include windowsHide: true for both paths.

Also applies to: 122-122

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@index.js` at line 47, The tests currently stub execSync but only assert the
command string/return value; update the execSync stubs to also assert the second
argument includes windowsHide: true (i.e., that options object merges/inherits
baseExecOptions with windowsHide: true). Locate the places referencing execSync
and baseExecOptions in index.js (both call paths mentioned) and add assertions
in each stub handler that the options parameter has windowsHide: true (use an
include/deep-equal check against { ...baseExecOptions, windowsHide: true } or
verify options.windowsHide === true) so both execution branches are protected.

121-124: Use this.cwd here to keep repo resolution consistent.

getLastCommitSync runs git commands with cwd: this.cwd, but getUserNameSync still doesn’t. For instances created with a custom directory, this can read user.name from the wrong context.

🔧 Suggested patch
  getUserNameSync() {
-    return execSync(`git ${this.gitDirStr} config user.name`, baseExecOptions)
+    return execSync(`git ${this.gitDirStr} config user.name`, {
+      ...baseExecOptions,
+      cwd: this.cwd,
+    })
      .toString()
      .trim();
  }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@index.js` around lines 121 - 124, getUserNameSync currently calls execSync
with baseExecOptions but not this.cwd, causing repo resolution mismatch; update
the execSync invocation inside getUserNameSync so it runs with cwd: this.cwd
(e.g., merge or pass an options object that includes cwd: this.cwd along with
baseExecOptions) while keeping the existing git command using this.gitDirStr, so
behavior matches getLastCommitSync.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@index.js`:
- Line 47: The tests currently stub execSync but only assert the command
string/return value; update the execSync stubs to also assert the second
argument includes windowsHide: true (i.e., that options object merges/inherits
baseExecOptions with windowsHide: true). Locate the places referencing execSync
and baseExecOptions in index.js (both call paths mentioned) and add assertions
in each stub handler that the options parameter has windowsHide: true (use an
include/deep-equal check against { ...baseExecOptions, windowsHide: true } or
verify options.windowsHide === true) so both execution branches are protected.
- Around line 121-124: getUserNameSync currently calls execSync with
baseExecOptions but not this.cwd, causing repo resolution mismatch; update the
execSync invocation inside getUserNameSync so it runs with cwd: this.cwd (e.g.,
merge or pass an options object that includes cwd: this.cwd along with
baseExecOptions) while keeping the existing git command using this.gitDirStr, so
behavior matches getLastCommitSync.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 973318fe-3ecb-48eb-bfa4-7941d8f5fa30

📥 Commits

Reviewing files that changed from the base of the PR and between 7646c5e and de55da7.

📒 Files selected for processing (1)
  • index.js

@700software 700software force-pushed the fix/windows-hide-exec-sync branch from 38de22d to 054db00 Compare March 31, 2026 21:48
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
test/index-branch.test.js (1)

50-52: Also assert cwd in the deleted-branch fallback stub.

This test currently checks windowsHide only, while the branch-path calls also depend on cwd. Adding the cwd assertion would make this test consistent and catch more regressions.

Suggested patch
     cp.execSync = (cmd, opts) => {
       assert.strictEqual(opts && opts.windowsHide, true, cmd);
+      assert.strictEqual(opts && opts.cwd, process.cwd(), cmd);
       if (cmd.includes('log -1 --pretty=format:')) return Buffer.from(fields.join(splitCharacter));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/index-branch.test.js` around lines 50 - 52, The stub for cp.execSync in
the deleted-branch fallback currently only asserts opts.windowsHide; update that
stub (cp.execSync) to also assert the provided opts.cwd equals the expected
working directory used elsewhere in this test (the repo path variable used for
branch-path calls, e.g., repoPath or the test's cwd variable) so the fallback
call validates both windowsHide and cwd before returning the stubbed Buffer.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/index-branch.test.js`:
- Around line 50-52: The stub for cp.execSync in the deleted-branch fallback
currently only asserts opts.windowsHide; update that stub (cp.execSync) to also
assert the provided opts.cwd equals the expected working directory used
elsewhere in this test (the repo path variable used for branch-path calls, e.g.,
repoPath or the test's cwd variable) so the fallback call validates both
windowsHide and cwd before returning the stubbed Buffer.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 867251c9-6060-4232-a3c2-35027b0bd739

📥 Commits

Reviewing files that changed from the base of the PR and between de55da7 and 38de22d.

📒 Files selected for processing (5)
  • index.js
  • line-diff.js
  • test/index-branch.test.js
  • test/index-config.test.js
  • test/line-diff.mock.test.js
✅ Files skipped from review due to trivial changes (1)
  • index.js

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.

Set windowsHide in case node is executed within a pm2 process tree

1 participant