shmuelie / shmuelie/powershell-modules

The worktree predictor emits invalid PowerShell for valid branch names containing apostrophes

Open
#266 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug module:git theme:testing
Dominant language
PowerShell
Stars
0
Forks
0
Avg merge
21m
Merged PRs (30d)
124

Description

Finding

Severity: low. Confidence: 10/10.
Reviewed snapshot: 5c38677469756c69f86678c0b907d82e15d0a539.

Git branch names can contain characters meaningful to PowerShell; suggestions never encode the completed branch as a literal PowerShell argument.

Accepting a suggestion for a valid existing branch such as feature/quote'branch creates a syntactically invalid command. Other shell-sensitive names need equivalent literal preservation. The newer argument completer's quoting does not protect this independent C# suggestion path.

Source

GetSuggestion interpolates the raw branch into a command string: new PredictiveSuggestion($"{prefix}{branch}").

Safe reproduction

  1. Compile the exact current predictor source with equivalent project settings in a fresh pwsh process.
  2. Create a predictor instance and seed its cached worktree branch array with the legal name feature/quote'branch.
  3. Call GetSuggestion for 'Remove-Worktree -BranchName feature/q'.
  4. Parse, but do not execute, the emitted suggestion.

Observed:

{
  "suggestion": "Remove-Worktree -BranchName feature/quote'branch",
  "parseError": "TerminatorExpectedAtEndOfString",
  "message": "The string is missing the terminator: '."
}

Expected: A suggestion retains the command and user flags while completing the branch as one unchanged literal argument that parses successfully.

The reviewer and parent independently replayed the controlled reproduction.
Only owned fixtures, isolated event subscribers or parser-only suggestions were
used; no user repository was updated or real command suggestion executed.

Acceptance criteria

  • Emit literal PowerShell syntax for branch names containing apostrophes or other legal shell-sensitive characters.
  • Test both worktree-branch and checkoutable-branch suggestions through the PowerShell parser.
  • Preserve the typed command, flags, casing, substring matching, and normal simple-branch suggestions.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in modules/Shmuelie.Git/Predictor/WorktreePredictor.cs, especially lines 119-133 and the GetSuggestion path. Reproduce the apostrophe case with the PowerShell parser, then cover both worktree-branch and checkoutable-branch suggestions. Done means shell-sensitive names parse as one unchanged literal argument while preserving the typed command, flags, casing, matching, and simple-branch behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.