From 6b60917da724f0876ff945dc54aaab69aea655ae Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 2 Jan 2019 01:12:18 -0600 Subject: [PATCH] Closes #600 - adds (un)stage directory support --- package.json | 36 ++++++++++++++++++++++++++++++++++++ src/git/gitService.ts | 20 ++++++++++++++++++++ src/views/nodes.ts | 1 + src/views/viewCommands.ts | 15 +++++++++++++++ 4 files changed, 72 insertions(+) diff --git a/package.json b/package.json index e8ab6ba..e2f0a46 100644 --- a/package.json +++ b/package.json @@ -2258,6 +2258,15 @@ "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", "category": "GitLens", @@ -2267,6 +2276,15 @@ } }, { + "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", "category": "GitLens", @@ -3052,10 +3070,18 @@ "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" }, @@ -4432,6 +4458,16 @@ "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)/", "group": "9_gitlens@1" diff --git a/src/git/gitService.ts b/src/git/gitService.ts index 80fd925..af5df93 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 1b05f7a..d703778 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 55fe300..b6a5027 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;