Skip to content

fix(add-wizard): preserve files and show recovery instructions on commit failure#18489

Merged
dsyme merged 6 commits intomainfrom
copilot/fix-file-commit-error
Feb 26, 2026
Merged

fix(add-wizard): preserve files and show recovery instructions on commit failure#18489
dsyme merged 6 commits intomainfrom
copilot/fix-file-commit-error

Conversation

Copy link
Contributor

Copilot AI commented Feb 26, 2026

  • Update commitChanges in git.go to capture git output for better error messages
  • Update addWorkflowsWithPR in add_workflow_pr.go to not rollback files when commit fails, and print helpful instructions instead
  • Fix unused errors import and trailing newline in error string that caused build failure and lint error
  • Run fmt, build, lint, and tests to validate the changes
Original prompt

This section details on the original issue you should resolve

<issue_title>gh add-wizard: Failed to commit files in a repo</issue_title>
<issue_description>We had a cases where files failed to commit, we're not sure why. githubnext/agentics#204

We should give a better error message and exit, leaving the files uncomitted, exiting with a messsage saying that you should add and commit the files manually and either make a pull request or push them to the repository.

✓ Working directory is clean

✓ Selected engine: copilot
✓ Using existing COPILOT_GITHUB_TOKEN secret in repository

The following workflow files will be added:
• .github/workflows/repo-assist.md
• .github/workflows/repo-assist.lock.yml

✗ failed to add workflow: failed to commit files: failed to commit changes: exit status 1</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

When `git commit` fails during `gh add-wizard` (interactive mode), instead
of rolling back workflow files and showing a cryptic error, the tool now:

1. Leaves the workflow files on disk and staged in git for manual recovery
2. Captures and displays git's actual error output in the error message
3. Shows clear instructions for the user to manually commit/push and
   create a pull request

Fixes: failed to commit files: failed to commit changes: exit status 1

Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve error handling for failed file commit fix(add-wizard): preserve files and show recovery instructions on commit failure Feb 26, 2026
@dsyme dsyme marked this pull request as ready for review February 26, 2026 20:54
Copilot AI review requested due to automatic review settings February 26, 2026 20:54
Copy link
Contributor

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.

Pull request overview

Improves gh add-wizard failure handling when git commit fails, preserving generated workflow files and providing actionable recovery guidance instead of deleting files and returning a cryptic error.

Changes:

  • Capture and surface git commit stderr/stdout in commitChanges errors via CombinedOutput().
  • On commit failure during PR-based workflow add, stop rolling back files and print manual recovery steps.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
pkg/cli/git.go Captures git commit output and includes it in returned errors for better diagnostics.
pkg/cli/add_workflow_pr.go Replaces rollback-on-commit-failure with user guidance and preserves staged files for manual recovery.

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

dsyme and others added 2 commits February 26, 2026 21:14
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

import (
"errors"
"fmt"
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot fix this build error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 55e2360. The "errors" import was left over after switching from errors.New to fmt.Errorf (per the reviewer's suggestion). Also removed the trailing \n from the error format string to satisfy the staticcheck ST1005 rule.

Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
@dsyme dsyme merged commit 8bd960c into main Feb 26, 2026
77 checks passed
@dsyme dsyme deleted the copilot/fix-file-commit-error branch February 26, 2026 22:09
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.

gh add-wizard: Failed to commit files in a repo

3 participants