Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config option to separate or hide untracked files (addresses #35480) #80083

Merged
merged 2 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,61 @@
"command": "git.ignore",
"when": "scmProvider == git && scmResourceGroup == workingTree",
"group": "1_modification@3"
},
{
"command": "git.openChange",
"when": "scmProvider == git && scmResourceGroup == workingTree",
"group": "navigation"
},
{
"command": "git.openChange",
"when": "scmProvider == git && scmResourceGroup == untracked",
"group": "navigation"
},
{
"command": "git.openHEADFile",
"when": "scmProvider == git && scmResourceGroup == untracked",
"group": "navigation"
},
{
"command": "git.openFile",
"when": "scmProvider == git && scmResourceGroup == untracked",
"group": "navigation"
},
{
"command": "git.stage",
"when": "scmProvider == git && scmResourceGroup == untracked",
"group": "1_modification"
},
{
"command": "git.clean",
"when": "scmProvider == git && scmResourceGroup == untracked && !gitFreshRepository",
"group": "1_modification"
},
{
"command": "git.clean",
"when": "scmProvider == git && scmResourceGroup == untracked && !gitFreshRepository",
"group": "inline"
},
{
"command": "git.stage",
"when": "scmProvider == git && scmResourceGroup == untracked",
"group": "inline"
},
{
"command": "git.openFile2",
"when": "scmProvider == git && scmResourceGroup == untracked && config.git.showInlineOpenFileAction && config.git.openDiffOnClick",
"group": "inline0"
},
{
"command": "git.openChange",
"when": "scmProvider == git && scmResourceGroup == untracked && config.git.showInlineOpenFileAction && !config.git.openDiffOnClick",
"group": "inline0"
},
{
"command": "git.ignore",
"when": "scmProvider == git && scmResourceGroup == untracked",
"group": "1_modification@3"
}
],
"editor/title": [
Expand Down Expand Up @@ -1363,6 +1418,21 @@
],
"default": "committerdate",
"description": "%config.branchSortOrder%"
},
"git.handleUntracked": {
"type": "string",
"enum": [
"withchanges",
"separate",
"hide"
],
"enumDescriptions": [
"%config.handleUntracked.withchanges%",
"%config.handleUntracked.separate%",
"%config.handleUntracked.hide%"
],
"default": "withchanges",
"description": "%config.handleUntracked%"
}
}
},
Expand Down
8 changes: 6 additions & 2 deletions extensions/git/package.nls.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"displayName": "Git",
"description": "Git SCM Integration",
"displayName": "Hide Untracked Files (Git)",
"description": "Copy of the built-in Git extension which hides untracked files",
Copy link
Member

Choose a reason for hiding this comment

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

These seem leftover changes.

"command.clone": "Clone",
"command.init": "Initialize Repository",
"command.openRepository": "Open Repository",
Expand Down Expand Up @@ -128,6 +128,10 @@
"config.openDiffOnClick": "Controls whether the diff editor should be opened when clicking a change. Otherwise the regular editor will be opened.",
"config.supportCancellation": "Controls whether a notification comes up when running the Sync action, which allows the user to cancel the operation.",
"config.branchSortOrder": "Controls the sort order for branches.",
"config.handleUntracked": "Controls how untracked files are presented in the activity bar.",
"config.handleUntracked.withchanges": "Show with other unstaged changes, commit under \"Commit All\"",
"config.handleUntracked.separate": "Separate in list and badge counter, don't commit under \"Commit All\"",
"config.handleUntracked.hide": "Exclude from list and badge counter, don't commit under \"Commit All\"",
"colors.added": "Color for added resources.",
"colors.modified": "Color for modified resources.",
"colors.deleted": "Color for deleted resources.",
Expand Down
72 changes: 58 additions & 14 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Uri, commands, Disposable, window, workspace, QuickPickItem, OutputChannel, Range, WorkspaceEdit, Position, LineChange, SourceControlResourceState, TextDocumentShowOptions, ViewColumn, ProgressLocation, TextEditor, MessageOptions, WorkspaceFolder } from 'vscode';
import { Git, CommitOptions, Stash, ForcePushMode } from './git';
import { Repository, Resource, ResourceGroupType } from './repository';
import { Model } from './model';
import { toGitUri, fromGitUri } from './uri';
import { grep, isDescendant, pathEquals } from './util';
import { applyLineChanges, intersectDiffWithRange, toLineRanges, invertLineChange, getModifiedRange } from './staging';
import * as path from 'path';
import { lstat, Stats } from 'fs';
import * as os from 'os';
import * as path from 'path';
import { commands, Disposable, LineChange, MessageOptions, OutputChannel, Position, ProgressLocation, QuickPickItem, Range, SourceControlResourceState, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit, WorkspaceFolder } from 'vscode';
import TelemetryReporter from 'vscode-extension-telemetry';
import * as nls from 'vscode-nls';
import { Ref, RefType, Branch, GitErrorCodes, Status } from './api/git';
import { Branch, GitErrorCodes, Ref, RefType, Status } from './api/git';
import { CommitOptions, ForcePushMode, Git, Stash } from './git';
import { Model } from './model';
import { Repository, Resource, ResourceGroupType } from './repository';
import { applyLineChanges, getModifiedRange, intersectDiffWithRange, invertLineChange, toLineRanges } from './staging';
import { fromGitUri, toGitUri } from './uri';
import { grep, isDescendant, pathEquals } from './util';

const localize = nls.loadMessageBundle();

Expand Down Expand Up @@ -852,7 +852,8 @@ export class CommandCenter {
}

const workingTree = selection.filter(s => s.resourceGroupType === ResourceGroupType.WorkingTree);
const scmResources = [...workingTree, ...resolved, ...unresolved];
const untracked = selection.filter(s => s.resourceGroupType === ResourceGroupType.Untracked);
const scmResources = [...workingTree, ...untracked, ...resolved, ...unresolved];

this.outputChannel.appendLine(`git.stage.scmResources ${scmResources.length}`);
if (!scmResources.length) {
Expand Down Expand Up @@ -893,7 +894,49 @@ export class CommandCenter {
}
}

await repository.add([]);
const handleUntracked =
workspace
.getConfiguration('git', Uri.file(repository.root))
.get<'withchanges' | 'separate' | 'hide'>('handleUntracked') ||
'withchanges';
let includeUntracked;
Copy link
Member

Choose a reason for hiding this comment

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

This misses a type.

switch (handleUntracked) {
case 'withchanges':
includeUntracked = true;
break;
case 'separate':
if (repository.untrackedGroup.resourceStates.length > 0) {
const message = localize(
'also add untracked files',
'Would you like to also add and stage untracked files?'
);

const yes = localize('yes', "Yes");
const no = localize('no', 'No');
const pick = await window.showInformationMessage(
message,
{ modal: true },
yes,
no
);

if (pick === yes) {
includeUntracked = true;
} else if (pick === no) {
includeUntracked = false;
} else {
return;
}
} else {
// Doesn't matter
includeUntracked = false;
}
break;
case 'hide':
includeUntracked = false;
break;
}
await repository.add([], includeUntracked ? undefined : { update: true });
}

private async _stageDeletionConflict(repository: Repository, uri: Uri): Promise<void> {
Expand Down Expand Up @@ -1117,8 +1160,8 @@ export class CommandCenter {
resourceStates = [resource];
}

const scmResources = resourceStates
.filter(s => s instanceof Resource && s.resourceGroupType === ResourceGroupType.WorkingTree) as Resource[];
const scmResources = resourceStates.filter(s => s instanceof Resource
&& (s.resourceGroupType === ResourceGroupType.WorkingTree || s.resourceGroupType === ResourceGroupType.Untracked)) as Resource[];

if (!scmResources.length) {
return;
Expand Down Expand Up @@ -2070,7 +2113,8 @@ export class CommandCenter {
}

private async _stash(repository: Repository, includeUntracked = false): Promise<void> {
const noUnstagedChanges = repository.workingTreeGroup.resourceStates.length === 0;
const noUnstagedChanges = repository.workingTreeGroup.resourceStates.length === 0
&& (!includeUntracked || repository.untrackedGroup.resourceStates.length === 0);
const noStagedChanges = repository.indexGroup.resourceStates.length === 0;

if (noUnstagedChanges && noStagedChanges) {
Expand Down
Loading