Skip to content

git-branch-clean: abort on git fetch --prune failure#7

Closed
Copilot wants to merge 1 commit intomainfrom
copilot/fix-git-fetch-prune-error-again
Closed

git-branch-clean: abort on git fetch --prune failure#7
Copilot wants to merge 1 commit intomainfrom
copilot/fix-git-fetch-prune-error-again

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 14, 2026

Without a fetch error guard, a failed git fetch --prune (network down, bad remote) would silently continue, leaving remote-tracking refs stale and potentially causing the script to delete local branches that are not actually gone.

Change

Added a fatal exit guard to the fetch call:

# Before
git fetch --prune

# After
git fetch --prune || { echo "fatal: failed to fetch from origin"; exit 1; }

Ensures the script never proceeds to branch deletion with outdated remote tracking data.

Original prompt

git-branch-clean: fix git fetch --prune error handling

File to modify: git-branch-clean

Problem

If git fetch --prune fails (e.g. no network, bad remote), the script silently continues and may incorrectly delete local branches based on stale data.

Fix

Change line 32 from:

git fetch --prune

To:

git fetch --prune || { echo "fatal: failed to fetch from origin"; exit 1; }

This ensures the script aborts immediately if the fetch fails, rather than proceeding to delete branches based on potentially outdated remote tracking info.

No other changes to the file.

The following is the prior conversation context from the user's chat exploration (may be truncated):

Assistant: Good — latest main SHA is 1da8d9f06dcededbe51882b26df4da9b085dfab2. 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:

  • GitHub Copilot Pro
  • GitHub Copilot Pro+
  • GitHub Copilot Business
  • GitHub Copilot Enterprise

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/utils is 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:

  1. Go to github.com/settings/copilot
  2. Look for the "Coding agent" section
  3. Make sure it is set to Enabled

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:

  1. Go to https://github.com/mlutonsky/utils/settings/actions
  2. Under "Actions permissions", select "Allow all actions and reusable workflows" (or at minimum allow GitHub Actions to run)

After 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:

# PR Title What it does
1 Add MIT license Adds a LICENSE file so users know they can freely use and adapt the scripts
2 Add ShellCheck CI workflow Adds .github/workflows/shellcheck.yml to automatically lint all shell scripts on every push and PR
3 git-branch-clean: safer branch deletion and fetch error handling Switches git branch -Dgit branch -d and adds an exit guard on git fetch --prune
4 git-co: fix expensive per-branch python3 Levenshtein loop Batches all branch names into a single python3 call instead of spawning one process per branch
5 git-co: remove unnecessary git pull --all Removes the redundant git pull --all after git switch -c, which already sets up tracking
6 git-co: validate branch selection input is numeric Adds [[ "$selection" =~ ^[0-9]+$ ]] guard to prevent a cryptic Bash error on non-numeric input
7 idle-power-manager: add log rotation Adds a rotate_log function and MAX_LOG_LINES env var to cap the log file at 10,000 lines
8 idle-power-manager: fix fragile switch_profile success detection Checks the gdbus call exit code directly instead of grepping stdout for the string "true"
9 idle-power-manager: add DBUS_SESSION_BUS_ADDRESS fallback Exports a fallback socket path so the script works reliably as a systemd user service
10 Add install.sh Adds a one-shot install script that symlinks all scripts to ~/.local/bin/, with README and CLAUDE.md updates

You can review them all at github.com/mlutonsky/utils/pulls and merge whichever you find useful.

User: @copilot Accepted Confirmation: Are you sure?

Assistant: All 10 pull requests have been queued with the coding agent. Here's the full list to track — yo...

This pull request was created from Copilot chat.


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Copilot AI changed the title [WIP] Fix git fetch --prune error handling git-branch-clean: abort on git fetch --prune failure Mar 14, 2026
Copilot AI requested a review from mlutonsky March 14, 2026 18:24
@mlutonsky mlutonsky marked this pull request as ready for review March 14, 2026 18:28
Copilot AI review requested due to automatic review settings March 14, 2026 18:28
Copy link
Copy Markdown

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.

Copilot wasn't able to review any files in this pull request.


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

@mlutonsky mlutonsky closed this Mar 14, 2026
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.

3 participants