Conversation
Co-authored-by: mlutonsky <423848+mlutonsky@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix branch selection input validation to be numeric
git-co: guard numeric validation before integer comparison on branch selection
Mar 14, 2026
mlutonsky
approved these changes
Mar 14, 2026
There was a problem hiding this comment.
Pull request overview
Updates git-co’s interactive branch-selection prompt to avoid Bash “integer expression expected” errors by validating that user input is numeric before performing an integer comparison.
Changes:
- Add a digit-only regex guard (
[[ ... =~ ^[0-9]+$ ]]) before[ "$selection" -gt 0 ]in the branch selection menu.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Non-numeric input at the interactive branch-selection prompt (e.g.
q,abc) causes Bash to emit[: abc: integer expression expectedbecause$selectionis passed directly to[ "$selection" -gt 0 ].Change
Replace the
-nemptiness check with a digit-only regex guard:The
=~ ^[0-9]+$pattern ensures$selectioncontains only digits before the integer comparison is evaluated, silently discarding any non-numeric input rather than surfacing a confusing shell error.Original prompt
git-co: validate branch selection input is numeric
File to modify:
git-coProblem
In the interactive menu (multi-match branch of
co()), user input is used directly in an integer comparison:If the user types a non-numeric string (e.g.
q,abc), Bash will print:Fix
Add a numeric validation guard before the integer comparison. Replace:
with:
This ensures
$selectionis a non-empty string of digits before doing the integer comparison. No other changes.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: @copilot Accepted Confirmation: Are you sure?
Assistant: Since the Copilot coding agent isn't enabled on this repository, I'll create each PR manually by pushing branches and files directly. Let me work through them one by one.
Assistant: Good — latest
mainSHA is1da8d9f06dcededbe51882b26df4da9b085dfab2. I'll now create all the branches and files in parallel where possible, then open the PRs. Let me start creating all the branches.User: How to enable/allo agents so you can create pull requests?
Assistant: Here's what you need to enable the Copilot coding agent so I can create pull requests autonomously:
How to Enable the Copilot Coding Agent
The coding agent is what allows me to write code, create branches, and open PRs on your behalf. It requires a supported Copilot plan and then a one-time settings toggle.
Step 1 — Confirm your Copilot plan
The coding agent is available on:
If you're on the free tier, you'll need to upgrade. You can check or upgrade at github.com/features/copilot/plans.
Step 2 — Enable the agent (personal account)
Since
mlutonsky/utilsis a personal (user-owned) repository, the coding agent should be available to you automatically once you have a qualifying plan. It is enabled by default for all repositories unless explicitly blocked.To verify or toggle it:
Step 3 — Enable GitHub Actions (required for the agent to run)
The coding agent uses GitHub Actions runners to do its work. Make sure Actions are enabled for the repository:
https://github.com/mlutonsky/utils/settings/actionsAfter enabling
Once those are in place, come back here and ask me to create the pull requests again — I'll be able to autonomously create branches, make all the code changes, and open a PR for each improvement for you to review and merge. See the full docs at Asking GitHub Copilot to create a pull request.
User: I have allowed it, so now please re-create these pull requests automatically
Assistant: All 10 pull requests have been submitted to mlutonsky/utils. Here's a summary of what was created:
LICENSEfile so users know they can freely use and adapt the scripts.github/workflows/shellcheck.ymlto automatically lint all shell scripts on every push and PRgit branch -D→git branch -dand adds an exit guard ongit fetch --prunepython3call instead of spawning one process per branchgit pull --allgit pull --allaftergit switch -c, which already sets up tracking[[ "$selection" =~ ^[0-9]+$ ]]guard to prevent a cryptic Bash error on non-numeric inputrotate_logfunction andMAX_LOG_LINESenv var to cap the log file at 10,000 linesgdbus callexit code directly instead of grepping stdout for the string"true"This pull request was created from Copilot chat.
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.