Skip to content

Commit 6b60917

Browse files
UziTecheamodio
authored andcommitted
Closes #600 - adds (un)stage directory support
1 parent d063337 commit 6b60917

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,6 +2257,15 @@
22572257
"title": "Unset as Default",
22582258
"category": "GitLens"
22592259
},
2260+
{
2261+
"command": "gitlens.views.stageDirectory",
2262+
"title": "Stage All Changes",
2263+
"category": "GitLens",
2264+
"icon": {
2265+
"dark": "images/dark/icon-add.svg",
2266+
"light": "images/light/icon-add.svg"
2267+
}
2268+
},
22602269
{
22612270
"command": "gitlens.views.stageFile",
22622271
"title": "Stage Changes",
@@ -2266,6 +2275,15 @@
22662275
"light": "images/light/icon-add.svg"
22672276
}
22682277
},
2278+
{
2279+
"command": "gitlens.views.unstageDirectory",
2280+
"title": "Unstage All Changes",
2281+
"category": "GitLens",
2282+
"icon": {
2283+
"dark": "images/dark/icon-minus.svg",
2284+
"light": "images/light/icon-minus.svg"
2285+
}
2286+
},
22692287
{
22702288
"command": "gitlens.views.unstageFile",
22712289
"title": "Unstage Changes",
@@ -3051,10 +3069,18 @@
30513069
"command": "gitlens.views.unsetAsDefault",
30523070
"when": "false"
30533071
},
3072+
{
3073+
"command": "gitlens.views.stageDirectory",
3074+
"when": "false"
3075+
},
30543076
{
30553077
"command": "gitlens.views.stageFile",
30563078
"when": "false"
30573079
},
3080+
{
3081+
"command": "gitlens.views.unstageDirectory",
3082+
"when": "false"
3083+
},
30583084
{
30593085
"command": "gitlens.views.unstageFile",
30603086
"when": "false"
@@ -4431,6 +4457,16 @@
44314457
"when": "view =~ /^gitlens\\.views\\./ && viewItem =~ /gitlens:(compare|folder|results|search|status:files)\\b/",
44324458
"group": "8_gitlens@1"
44334459
},
4460+
{
4461+
"command": "gitlens.views.stageDirectory",
4462+
"when": "view =~ /^gitlens\\.views\\./ && viewItem =~ /gitlens:folder\\b/",
4463+
"group": "7_gitlens@1"
4464+
},
4465+
{
4466+
"command": "gitlens.views.unstageDirectory",
4467+
"when": "view =~ /^gitlens\\.views\\./ && viewItem =~ /gitlens:folder\\b/",
4468+
"group": "7_gitlens@2"
4469+
},
44344470
{
44354471
"command": "gitlens.views.refreshNode",
44364472
"when": "view =~ /^gitlens\\.views\\./ && viewItem =~ /gitlens:(?!file\\b)/",

src/git/gitService.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,16 @@ export class GitService implements Disposable {
21322132
);
21332133
}
21342134

2135+
stageDirectory(repoPath: string, directory: string): Promise<string>;
2136+
stageDirectory(repoPath: string, uri: Uri): Promise<string>;
2137+
@log()
2138+
stageDirectory(repoPath: string, directoryOrUri: string | Uri): Promise<string> {
2139+
return Git.add(
2140+
repoPath,
2141+
typeof directoryOrUri === 'string' ? directoryOrUri : Git.splitPath(directoryOrUri.fsPath, repoPath)[0]
2142+
);
2143+
}
2144+
21352145
unStageFile(repoPath: string, fileName: string): Promise<string>;
21362146
unStageFile(repoPath: string, uri: Uri): Promise<string>;
21372147
@log()
@@ -2142,6 +2152,16 @@ export class GitService implements Disposable {
21422152
);
21432153
}
21442154

2155+
unStageDirectory(repoPath: string, directory: string): Promise<string>;
2156+
unStageDirectory(repoPath: string, uri: Uri): Promise<string>;
2157+
@log()
2158+
unStageDirectory(repoPath: string, directoryOrUri: string | Uri): Promise<string> {
2159+
return Git.reset(
2160+
repoPath,
2161+
typeof directoryOrUri === 'string' ? directoryOrUri : Git.splitPath(directoryOrUri.fsPath, repoPath)[0]
2162+
);
2163+
}
2164+
21452165
@log()
21462166
stashApply(repoPath: string, stashName: string, deleteAfter: boolean = false) {
21472167
return Git.stash_apply(repoPath, stashName, deleteAfter);

src/views/nodes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export * from './nodes/commitFileNode';
88
export * from './nodes/commitNode';
99
export * from './nodes/fileHistoryNode';
1010
export * from './nodes/fileHistoryTrackerNode';
11+
export * from './nodes/folderNode';
1112
export * from './nodes/lineHistoryNode';
1213
export * from './nodes/lineHistoryTrackerNode';
1314
export * from './nodes/remoteNode';

src/views/viewCommands.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
canDismissNode,
2424
CommitFileNode,
2525
CommitNode,
26+
FolderNode,
2627
RemoteNode,
2728
RepositoryNode,
2829
ResultsFileNode,
@@ -98,7 +99,9 @@ export class ViewCommands implements Disposable {
9899
commands.registerCommand('gitlens.views.checkout', this.checkout, this);
99100

100101
commands.registerCommand('gitlens.views.stageFile', this.stageFile, this);
102+
commands.registerCommand('gitlens.views.stageDirectory', this.stageDirectory, this);
101103
commands.registerCommand('gitlens.views.unstageFile', this.unstageFile, this);
104+
commands.registerCommand('gitlens.views.unstageDirectory', this.unstageDirectory, this);
102105

103106
commands.registerCommand('gitlens.views.compareAncestryWithWorking', this.compareAncestryWithWorking, this);
104107
commands.registerCommand('gitlens.views.compareWithHead', this.compareWithHead, this);
@@ -464,12 +467,24 @@ export class ViewCommands implements Disposable {
464467
return;
465468
}
466469

470+
private async stageDirectory(node: FolderNode) {
471+
if (!(node instanceof FolderNode) || !node.relativePath) return;
472+
473+
void (await Container.git.stageDirectory(node.repoPath, node.relativePath));
474+
}
475+
467476
private async stageFile(node: CommitFileNode | StatusFileNode) {
468477
if (!(node instanceof CommitFileNode) && !(node instanceof StatusFileNode)) return;
469478

470479
void (await Container.git.stageFile(node.repoPath, node.file.fileName));
471480
}
472481

482+
private async unstageDirectory(node: FolderNode) {
483+
if (!(node instanceof FolderNode) || !node.relativePath) return;
484+
485+
void (await Container.git.unStageDirectory(node.repoPath, node.relativePath));
486+
}
487+
473488
private async unstageFile(node: CommitFileNode | StatusFileNode) {
474489
if (!(node instanceof CommitFileNode) && !(node instanceof StatusFileNode)) return;
475490

0 commit comments

Comments
 (0)