Skip to content

Remove leftover branch git config when deleting local branches#8832

Open
alexr00 with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-delete-local-branches
Open

Remove leftover branch git config when deleting local branches#8832
alexr00 with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-delete-local-branches

Conversation

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

The "Delete local branches and remotes" command (pr.deleteLocalBranchesNRemotes) listed branches that no longer exist. getBranchDeletionItems builds its picklist from .git/config, and stale [branch "<name>"] sections (left behind when a branch is deleted out-of-band) keep those branches appearing.

Changes

  • deleteBranches config cleanup — after unsetting the PR metadata keys, deleteConfig now also strips any remaining branch.<name>.* entries. This happens in the existing sequential config step (config ops can't be parallelized), scoped to the exact branch prefix so other branches/remotes are untouched, and logs rather than aborts on failure.
  • Test mockMockRepository gains unsetConfig, and deleteBranch now throws a realistic git "not found" error (with stderr) for missing branches.
  • Tests — cover cleanup for both an existing branch and an already-deleted branch with stale config.
if (this.repository.unsetConfig) {
    const prefix = `branch.${branch}.`;
    const remaining = (await this.repository.getConfigs()).filter(config => config.key.startsWith(prefix));
    for (const config of remaining) {
        await this.repository.unsetConfig(config.key);
    }
}

Note: the electron test runner could not execute in the sandbox (VS Code download is network-blocked); tests type-check and the cleanup logic was verified in isolation.

Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with displaying deleted local branches Remove leftover branch git config when deleting local branches Jul 7, 2026
Copilot AI requested a review from alexr00 July 7, 2026 10:21
@alexr00 alexr00 marked this pull request as ready for review July 13, 2026 10:06
Copilot AI review requested due to automatic review settings July 13, 2026 10:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes stale local-branch entries appearing in the “Delete local branches and remotes” flow by cleaning up leftover branch.<name>.* git config entries that can remain when branches are deleted out-of-band (or when providers don’t fully clean config).

Changes:

  • Adds post-deletion cleanup in deleteBranches to remove leftover branch.<name>.* config entries (including retry-by-recreate/delete behavior to let Git remove whole sections).
  • Enhances MockRepository config handling to better model multi-valued git config and adds unsetConfig.
  • Adds unit tests covering cleanup for both an existing branch and an already-deleted branch with stale config.
Show a summary per file
File Description
src/github/folderRepositoryManager.ts Adds branch-config cleanup after branch deletion and introduces a sequential remote deletion helper with failure reporting.
src/test/mocks/mockRepository.ts Updates mock git-config storage to allow duplicates, adds unsetConfig, and simulates git-like “branch not found” stderr.
src/test/github/folderRepositoryManager.test.ts Adds tests validating stale branch config cleanup and remote deletion continuing after a failure.

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Low

Comment thread src/github/folderRepositoryManager.ts
Comment thread src/test/mocks/mockRepository.ts
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.

"Delete local branches" is showing branches that have already been deleted

3 participants