Skip to content

Commit 84536d2

Browse files
committed
Closes #599 - adds (un)stage directory support
Limits stage/unstage to working tree folders Adds stage/unstage to the folder's inline toolbar Adds recognition for Tony Brix's contribution
1 parent 6b60917 commit 84536d2

File tree

7 files changed

+43
-14
lines changed

7 files changed

+43
-14
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1111
- Adds favoriting of repositories and branches in the _Repositories_ view to allow for better (user-customized) sorting
1212
- Adds _Set as Default_ and _Unset as Default_ commands to remotes in the _Repositories_ view to specify the default remote selection when using the _Open \* in Remote_ commands — closes [#504](https://github.com/eamodio/vscode-gitlens/issues/504)
1313
- Adds the ability to turn on file annotations (blame, heatmap, and recent changes) via user-defined modes — closes [#542](https://github.com/eamodio/vscode-gitlens/issues/542)
14+
- Adds the ability to stage and unstage files by folders in the _Repositories_ view — closes [#599](https://github.com/eamodio/vscode-gitlens/issues/599) thanks to [PR #600](https://github.com/eamodio/vscode-gitlens/pull/600) by Tony Brix ([@UziTech](https://github.com/UziTech))
15+
- Adds _Stage All Changes_ and _Unstage All Changes_ commands to folders in the _Repositories_ view
1416

1517
## [9.2.4] - 2018-12-26
1618

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ Add [`"gitlens.insiders": true`](#general-settings- 'Jump to GitLens settings')
896896
A big thanks to the people that have contributed to this project:
897897

898898
- Loris Bettazza ([@Pustur](https://github.com/Pustur)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=Pustur)
899+
- Tony Brix ([@UziTech](https://github.com/UziTech)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=UziTech)
899900
- Amanda Cameron ([@AmandaCameron](https://github.com/AmandaCameron)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=AmandaCameron)
900901
- Brett Cannon ([@brettcannon](https://github.com/brettcannon)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=brettcannon)
901902
- Ash Clarke ([@ashclarke](https://github.com/ashclarke)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=ashclarke)

package.json

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4453,23 +4453,33 @@
44534453
"group": "8_gitlens"
44544454
},
44554455
{
4456-
"command": "gitlens.views.expandNode",
4457-
"when": "view =~ /^gitlens\\.views\\./ && viewItem =~ /gitlens:(compare|folder|results|search|status:files)\\b/",
4458-
"group": "8_gitlens@1"
4456+
"command": "gitlens.views.stageDirectory",
4457+
"when": "viewItem =~ /gitlens:folder\\b.*?\\+working\\b.*?/",
4458+
"group": "inline@1"
4459+
},
4460+
{
4461+
"command": "gitlens.views.unstageDirectory",
4462+
"when": "viewItem =~ /gitlens:folder\\b.*?\\+working\\b.*?/",
4463+
"group": "inline@2"
44594464
},
44604465
{
44614466
"command": "gitlens.views.stageDirectory",
4462-
"when": "view =~ /^gitlens\\.views\\./ && viewItem =~ /gitlens:folder\\b/",
4463-
"group": "7_gitlens@1"
4467+
"when": "viewItem =~ /gitlens:folder\\b.*?\\+working\\b.*?/",
4468+
"group": "1_gitlens@1"
44644469
},
44654470
{
44664471
"command": "gitlens.views.unstageDirectory",
4467-
"when": "view =~ /^gitlens\\.views\\./ && viewItem =~ /gitlens:folder\\b/",
4468-
"group": "7_gitlens@2"
4472+
"when": "viewItem =~ /gitlens:folder\\b.*?\\+working\\b.*?/",
4473+
"group": "1_gitlens@2"
4474+
},
4475+
{
4476+
"command": "gitlens.views.expandNode",
4477+
"when": "viewItem =~ /gitlens:(compare|folder|results|search|status:files)\\b/",
4478+
"group": "8_gitlens@1"
44694479
},
44704480
{
44714481
"command": "gitlens.views.refreshNode",
4472-
"when": "view =~ /^gitlens\\.views\\./ && viewItem =~ /gitlens:(?!file\\b)/",
4482+
"when": "viewItem =~ /gitlens:(?!file\\b)/",
44734483
"group": "9_gitlens@1"
44744484
}
44754485
]

src/git/git.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ export class Git {
315315

316316
// Git commands
317317

318-
static add(repoPath: string | undefined, fileName: string) {
319-
return git<string>({ cwd: repoPath }, 'add', '-A', '--', fileName);
318+
static add(repoPath: string | undefined, pathspec: string) {
319+
return git<string>({ cwd: repoPath }, 'add', '-A', '--', pathspec);
320320
}
321321

322322
static apply(repoPath: string | undefined, patch: string, options: { allowConflicts?: boolean } = {}) {

src/views/nodes/folderNode.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class FolderNode extends ViewNode<ViewWithFiles> {
2323
public readonly repoPath: string,
2424
public readonly folderName: string,
2525
public readonly root: Arrays.IHierarchicalItem<FileNode>,
26+
private readonly containsWorkingFiles?: boolean,
2627
public readonly relativePath?: string
2728
) {
2829
super(GitUri.fromRepoPath(repoPath), view, parent);
@@ -43,7 +44,15 @@ export class FolderNode extends ViewNode<ViewWithFiles> {
4344
for (const folder of Objects.values(this.root.children)) {
4445
if (folder.value === undefined) {
4546
children.push(
46-
new FolderNode(this.view, this, this.repoPath, folder.name, folder, folder.relativePath)
47+
new FolderNode(
48+
this.view,
49+
this,
50+
this.repoPath,
51+
folder.name,
52+
folder,
53+
this.containsWorkingFiles,
54+
folder.relativePath
55+
)
4756
);
4857
continue;
4958
}
@@ -72,6 +81,9 @@ export class FolderNode extends ViewNode<ViewWithFiles> {
7281
// TODO: Change this to expanded once https://github.com/Microsoft/vscode/issues/30918 is fixed
7382
const item = new TreeItem(this.label, TreeItemCollapsibleState.Collapsed);
7483
item.contextValue = ResourceType.Folder;
84+
if (this.containsWorkingFiles) {
85+
item.contextValue += `+working`;
86+
}
7587
item.iconPath = ThemeIcon.Folder;
7688
item.tooltip = this.label;
7789
return item;

src/views/nodes/statusFilesNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class StatusFilesNode extends ViewNode<RepositoriesView> {
9898
this.view.config.files.compact
9999
);
100100

101-
const root = new FolderNode(this.view, this, repoPath, '', hierarchy);
101+
const root = new FolderNode(this.view, this, repoPath, '', hierarchy, true);
102102
children = (await root.getChildren()) as FileNode[];
103103
}
104104
else {

src/views/viewCommands.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ export class ViewCommands implements Disposable {
9898
commands.registerCommand('gitlens.views.applyChanges', this.applyChanges, this);
9999
commands.registerCommand('gitlens.views.checkout', this.checkout, this);
100100

101-
commands.registerCommand('gitlens.views.stageFile', this.stageFile, this);
102101
commands.registerCommand('gitlens.views.stageDirectory', this.stageDirectory, this);
103-
commands.registerCommand('gitlens.views.unstageFile', this.unstageFile, this);
102+
commands.registerCommand('gitlens.views.stageFile', this.stageFile, this);
104103
commands.registerCommand('gitlens.views.unstageDirectory', this.unstageDirectory, this);
104+
commands.registerCommand('gitlens.views.unstageFile', this.unstageFile, this);
105105

106106
commands.registerCommand('gitlens.views.compareAncestryWithWorking', this.compareAncestryWithWorking, this);
107107
commands.registerCommand('gitlens.views.compareWithHead', this.compareWithHead, this);
@@ -471,24 +471,28 @@ export class ViewCommands implements Disposable {
471471
if (!(node instanceof FolderNode) || !node.relativePath) return;
472472

473473
void (await Container.git.stageDirectory(node.repoPath, node.relativePath));
474+
void node.triggerChange();
474475
}
475476

476477
private async stageFile(node: CommitFileNode | StatusFileNode) {
477478
if (!(node instanceof CommitFileNode) && !(node instanceof StatusFileNode)) return;
478479

479480
void (await Container.git.stageFile(node.repoPath, node.file.fileName));
481+
void node.triggerChange();
480482
}
481483

482484
private async unstageDirectory(node: FolderNode) {
483485
if (!(node instanceof FolderNode) || !node.relativePath) return;
484486

485487
void (await Container.git.unStageDirectory(node.repoPath, node.relativePath));
488+
void node.triggerChange();
486489
}
487490

488491
private async unstageFile(node: CommitFileNode | StatusFileNode) {
489492
if (!(node instanceof CommitFileNode) && !(node instanceof StatusFileNode)) return;
490493

491494
void (await Container.git.unStageFile(node.repoPath, node.file.fileName));
495+
void node.triggerChange();
492496
}
493497

494498
private star(node: BranchNode | RepositoryNode) {

0 commit comments

Comments
 (0)