Skip to content

feat(git): add 'default' option to git.untrackedChanges setting#301016

Open
murataslan1 wants to merge 1 commit intomicrosoft:mainfrom
murataslan1:feat/git-untracked-from-config
Open

feat(git): add 'default' option to git.untrackedChanges setting#301016
murataslan1 wants to merge 1 commit intomicrosoft:mainfrom
murataslan1:feat/git-untracked-from-config

Conversation

@murataslan1
Copy link
Contributor

Summary

Fixes #249351 — Adds a default option to git.untrackedChanges that reads from git's own status.showUntrackedFiles configuration.

Problem

Users managing dotfiles with a bare git repository (a common pattern) set status.showUntrackedFiles=no in their repo's git config to avoid showing every file in the home directory as untracked. VS Code's git.untrackedChanges setting doesn't respect this git configuration, forcing users to manually set it to hidden — which then applies to all repositories.

Solution

Add a 4th enum value "default" to the git.untrackedChanges setting. When selected:

  1. Reads status.showUntrackedFiles from the repository's effective git config
  2. If no → behaves like "hidden" (uses -uno flag)
  3. Otherwise → behaves like "mixed" (uses -uall flag)

The resolution happens at the start of getStatus(), so all downstream logic (resource grouping, count badge, unstaging) works transparently.

Files changed

File Change
package.json Add "default" to enum + enumDescriptions
package.nls.json Add description string for new option
repository.ts Resolve "default" via git config, update type annotations

Add a 'default' option for git.untrackedChanges that reads the value
from git's own status.showUntrackedFiles configuration. When the git
config is set to 'no', behaves like 'hidden'. Otherwise, behaves like
'mixed'.

This enables dotfiles bare repository workflows where
status.showUntrackedFiles=no is set in the repo's git config to avoid
showing every untracked file in the home directory.

Fixes microsoft#249351
Copilot AI review requested due to automatic review settings March 12, 2026 05:04
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

Adds a new "default" value to the Git extension’s git.untrackedChanges setting so it can follow each repository’s effective status.showUntrackedFiles configuration, improving the dotfiles/bare-repo workflow without forcing a global VS Code setting.

Changes:

  • Extends the git.untrackedChanges setting schema with a new "default" enum value and description.
  • Adds localization for the new enum description.
  • Resolves "default" inside Repository.getStatus() by reading status.showUntrackedFiles and mapping it to "hidden" or "mixed".

Reviewed changes

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

File Description
extensions/git/src/repository.ts Adds "default" to the untrackedChanges type and resolves it via git config during status computation.
extensions/git/package.nls.json Adds the localized description string for the new "default" option.
extensions/git/package.json Updates the configuration schema enum/enumDescriptions to include "default".

Comment on lines 1350 to +1352
const config = workspace.getConfiguration('git', Uri.file(this.repository.root));
const untrackedChanges = config.get<'mixed' | 'separate' | 'hidden'>('untrackedChanges');
const untrackedChangesResourceGroupType = untrackedChanges === 'mixed' ? ResourceGroupType.WorkingTree : ResourceGroupType.Untracked;
const untrackedChanges = config.get<'mixed' | 'separate' | 'hidden' | 'default'>('untrackedChanges');
const untrackedChangesResourceGroupType = untrackedChanges === 'mixed' || untrackedChanges === 'default' ? ResourceGroupType.WorkingTree : ResourceGroupType.Untracked;
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

In this optimistic update path, untrackedChanges === 'default' is treated the same as 'mixed' when deciding which resource group untracked files should go to. However, 'default' is later resolved in getStatus() based on status.showUntrackedFiles and can effectively behave like 'hidden', in which case these untracked resources should be omitted (or at least not placed into WorkingTree). Consider reusing the resolved/effective untracked-changes mode (e.g., cache the resolved value from getStatus() on the Repository) instead of branching directly on the raw setting value here, to avoid UI inconsistencies for repos with status.showUntrackedFiles=no.

Copilot uses AI. Check for mistakes.
Comment on lines 1374 to 1377
// Add resource(s) to working group
const workingTreeGroup = untrackedChanges === 'mixed' ?
const workingTreeGroup = untrackedChanges === 'mixed' || untrackedChanges === 'default' ?
[...this.workingTreeGroup.resourceStates, ...trackedResources, ...untrackedResources] :
[...this.workingTreeGroup.resourceStates, ...trackedResources];
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

Same issue as above: this treats 'default' as 'mixed' when computing the optimistic workingTreeGroup. If status.showUntrackedFiles=no, getStatus() will later resolve 'default' to 'hidden' and these untracked resources should not appear at all. Using a cached resolved value (from the last getStatus() run) would keep optimistic updates aligned with the actual status behavior.

Copilot uses AI. Check for mistakes.
Comment on lines +2684 to +2687
const gitConfig = await this.repository.config('get', '', 'status.showUntrackedFiles');
untrackedChanges = gitConfig.trim() === 'no' ? 'hidden' : 'mixed';
}

Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

getStatus() supports cancellation via cancellationToken, but the extra git config --get status.showUntrackedFiles invocation for the 'default' case doesn't pass that token through. Consider passing { cancellationToken } (and optionally early-checking cancellation again after the config call) so a canceled status refresh can promptly terminate the spawned process.

Suggested change
const gitConfig = await this.repository.config('get', '', 'status.showUntrackedFiles');
untrackedChanges = gitConfig.trim() === 'no' ? 'hidden' : 'mixed';
}
const gitConfig = await this.repository.config('get', '', 'status.showUntrackedFiles', { cancellationToken });
untrackedChanges = gitConfig.trim() === 'no' ? 'hidden' : 'mixed';
}
if (cancellationToken && cancellationToken.isCancellationRequested) {
throw new CancellationError();
}

Copilot uses AI. Check for mistakes.
"config.untrackedChanges.mixed": "All changes, tracked and untracked, appear together and behave equally.",
"config.untrackedChanges.separate": "Untracked changes appear separately in the Source Control view. They are also excluded from several actions.",
"config.untrackedChanges.hidden": "Untracked changes are hidden and excluded from several actions.",
"config.untrackedChanges.default": "Use the value of git's `status.showUntrackedFiles` configuration. When set to `no`, behaves like \"hidden\". Otherwise, behaves like \"mixed\".",
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

Consider capitalizing “Git” in this user-facing description (it’s treated as a proper noun elsewhere in the Git extension’s settings descriptions).

Suggested change
"config.untrackedChanges.default": "Use the value of git's `status.showUntrackedFiles` configuration. When set to `no`, behaves like \"hidden\". Otherwise, behaves like \"mixed\".",
"config.untrackedChanges.default": "Use the value of Git's `status.showUntrackedFiles` configuration. When set to `no`, behaves like \"hidden\". Otherwise, behaves like \"mixed\".",

Copilot uses AI. Check for mistakes.
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.

Git - Add option for git.untrackedChanges to accept current git repo setting for git's status.showUntrackedFiles

3 participants