diff --git a/package.json b/package.json index e8ab6ba77d8b5..e2f0a46fe2519 100644 --- a/package.json +++ b/package.json @@ -2257,6 +2257,15 @@ "title": "Unset as Default", "category": "GitLens" }, + { + "command": "gitlens.views.stageDirectory", + "title": "Stage All Changes", + "category": "GitLens", + "icon": { + "dark": "images/dark/icon-add.svg", + "light": "images/light/icon-add.svg" + } + }, { "command": "gitlens.views.stageFile", "title": "Stage Changes", @@ -2266,6 +2275,15 @@ "light": "images/light/icon-add.svg" } }, + { + "command": "gitlens.views.unstageDirectory", + "title": "Unstage All Changes", + "category": "GitLens", + "icon": { + "dark": "images/dark/icon-minus.svg", + "light": "images/light/icon-minus.svg" + } + }, { "command": "gitlens.views.unstageFile", "title": "Unstage Changes", @@ -3051,10 +3069,18 @@ "command": "gitlens.views.unsetAsDefault", "when": "false" }, + { + "command": "gitlens.views.stageDirectory", + "when": "false" + }, { "command": "gitlens.views.stageFile", "when": "false" }, + { + "command": "gitlens.views.unstageDirectory", + "when": "false" + }, { "command": "gitlens.views.unstageFile", "when": "false" @@ -4431,6 +4457,16 @@ "when": "view =~ /^gitlens\\.views\\./ && viewItem =~ /gitlens:(compare|folder|results|search|status:files)\\b/", "group": "8_gitlens@1" }, + { + "command": "gitlens.views.stageDirectory", + "when": "view =~ /^gitlens\\.views\\./ && viewItem =~ /gitlens:folder\\b/", + "group": "7_gitlens@1" + }, + { + "command": "gitlens.views.unstageDirectory", + "when": "view =~ /^gitlens\\.views\\./ && viewItem =~ /gitlens:folder\\b/", + "group": "7_gitlens@2" + }, { "command": "gitlens.views.refreshNode", "when": "view =~ /^gitlens\\.views\\./ && viewItem =~ /gitlens:(?!file\\b)/", diff --git a/src/git/gitService.ts b/src/git/gitService.ts index 80fd9258e63a0..af5df93c9e219 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -2132,6 +2132,16 @@ export class GitService implements Disposable { ); } + stageDirectory(repoPath: string, directory: string): Promise; + stageDirectory(repoPath: string, uri: Uri): Promise; + @log() + stageDirectory(repoPath: string, directoryOrUri: string | Uri): Promise { + return Git.add( + repoPath, + typeof directoryOrUri === 'string' ? directoryOrUri : Git.splitPath(directoryOrUri.fsPath, repoPath)[0] + ); + } + unStageFile(repoPath: string, fileName: string): Promise; unStageFile(repoPath: string, uri: Uri): Promise; @log() @@ -2142,6 +2152,16 @@ export class GitService implements Disposable { ); } + unStageDirectory(repoPath: string, directory: string): Promise; + unStageDirectory(repoPath: string, uri: Uri): Promise; + @log() + unStageDirectory(repoPath: string, directoryOrUri: string | Uri): Promise { + return Git.reset( + repoPath, + typeof directoryOrUri === 'string' ? directoryOrUri : Git.splitPath(directoryOrUri.fsPath, repoPath)[0] + ); + } + @log() stashApply(repoPath: string, stashName: string, deleteAfter: boolean = false) { return Git.stash_apply(repoPath, stashName, deleteAfter); diff --git a/src/views/nodes.ts b/src/views/nodes.ts index 1b05f7a8d5e05..d70377814ea9f 100644 --- a/src/views/nodes.ts +++ b/src/views/nodes.ts @@ -8,6 +8,7 @@ export * from './nodes/commitFileNode'; export * from './nodes/commitNode'; export * from './nodes/fileHistoryNode'; export * from './nodes/fileHistoryTrackerNode'; +export * from './nodes/folderNode'; export * from './nodes/lineHistoryNode'; export * from './nodes/lineHistoryTrackerNode'; export * from './nodes/remoteNode'; diff --git a/src/views/viewCommands.ts b/src/views/viewCommands.ts index 55fe30002af26..b6a502729ac10 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -23,6 +23,7 @@ import { canDismissNode, CommitFileNode, CommitNode, + FolderNode, RemoteNode, RepositoryNode, ResultsFileNode, @@ -98,7 +99,9 @@ export class ViewCommands implements Disposable { commands.registerCommand('gitlens.views.checkout', this.checkout, this); commands.registerCommand('gitlens.views.stageFile', this.stageFile, this); + commands.registerCommand('gitlens.views.stageDirectory', this.stageDirectory, this); commands.registerCommand('gitlens.views.unstageFile', this.unstageFile, this); + commands.registerCommand('gitlens.views.unstageDirectory', this.unstageDirectory, this); commands.registerCommand('gitlens.views.compareAncestryWithWorking', this.compareAncestryWithWorking, this); commands.registerCommand('gitlens.views.compareWithHead', this.compareWithHead, this); @@ -464,12 +467,24 @@ export class ViewCommands implements Disposable { return; } + private async stageDirectory(node: FolderNode) { + if (!(node instanceof FolderNode) || !node.relativePath) return; + + void (await Container.git.stageDirectory(node.repoPath, node.relativePath)); + } + private async stageFile(node: CommitFileNode | StatusFileNode) { if (!(node instanceof CommitFileNode) && !(node instanceof StatusFileNode)) return; void (await Container.git.stageFile(node.repoPath, node.file.fileName)); } + private async unstageDirectory(node: FolderNode) { + if (!(node instanceof FolderNode) || !node.relativePath) return; + + void (await Container.git.unStageDirectory(node.repoPath, node.relativePath)); + } + private async unstageFile(node: CommitFileNode | StatusFileNode) { if (!(node instanceof CommitFileNode) && !(node instanceof StatusFileNode)) return;