Skip to content

Fix get_changed_files sourceControlState ignored (#269452)#3383

Open
pedrocostadev wants to merge 2 commits intomicrosoft:mainfrom
pedrocostadev:fix/269452-changes-stale-reference
Open

Fix get_changed_files sourceControlState ignored (#269452)#3383
pedrocostadev wants to merge 2 commits intomicrosoft:mainfrom
pedrocostadev:fix/269452-changes-stale-reference

Conversation

@pedrocostadev
Copy link

Problem

get_changed_files returns stale/empty results for unstaged changes because the changes object in RepoContextImpl captures array references at construction time rather than fetching fresh values.

When the Git extension updates repo state, it creates NEW arrays. The changes object still references the OLD arrays.

Root Cause

File: src/platform/git/vscode/gitServiceImpl.ts

// Before: Static object - arrays captured once
public readonly changes = {
    mergeChanges: this._repo.state.mergeChanges,
    indexChanges: this._repo.state.indexChanges,
    workingTree: this._repo.state.workingTreeChanges,
    untrackedChanges: this._repo.state.untrackedChanges
};

Fix

Convert changes from a static property to a getter so fresh values are fetched from _repo.state each access:

// After: Getter fetches fresh values each access
public get changes() {
    return {
        mergeChanges: this._repo.state.mergeChanges,
        indexChanges: this._repo.state.indexChanges,
        workingTree: this._repo.state.workingTreeChanges,
        untrackedChanges: this._repo.state.untrackedChanges
    };
}

Testing

  • TypeScript compiles without errors
  • All git-related unit tests pass (npm run test:unit -- src/platform/git)
  • Interface RepoContext unchanged (getter is compatible with readonly property)

Fixes microsoft/vscode#269452

Copilot AI review requested due to automatic review settings February 2, 2026 22:32
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

This PR fixes a bug where get_changed_files returns stale results for unstaged changes because the changes property was capturing array references at construction time instead of fetching fresh values from the Git repository state.

Changes:

  • Convert changes from a static readonly property to a getter in RepoContextImpl to ensure fresh repository state is retrieved on each access

Convert `changes` from static property to getter so fresh values
are fetched from repo state each access.

Fixes microsoft/vscode#269452

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@pedrocostadev pedrocostadev force-pushed the fix/269452-changes-stale-reference branch from 2929615 to fc7587f Compare February 3, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copilot Chat: get_changed_files sourceControlState ignored

2 participants