From 4292a115d05d5234f232ce4a3dea1505e8d05cf2 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 18 Dec 2018 13:42:22 -0600 Subject: [PATCH 1/3] WIP: stage directory --- package.json | 36 ++++++++++++++++++++++++++++++++++++ src/views/viewCommands.ts | 22 ++++++++++++++++++++++ 2 files changed, 58 insertions(+) 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/views/viewCommands.ts b/src/views/viewCommands.ts index 55fe30002af26..849cae1fdb4d1 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -98,7 +98,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 +466,32 @@ export class ViewCommands implements Disposable { return; } + private async stageDirectory(node: ViewNode) { + + // TODO: get fileNodes from node + const fileNodes: (CommitFileNode | StatusFileNode)[] = []; + + for (const fileNode of fileNodes) { + void (await this.stageFile(fileNode)); + } + } + 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: ViewNode) { + + // TODO: get fileNodes from node + const fileNodes: (CommitFileNode | StatusFileNode)[] = []; + + for (const fileNode of fileNodes) { + void (await this.unstageFile(fileNode)); + } + } + private async unstageFile(node: CommitFileNode | StatusFileNode) { if (!(node instanceof CommitFileNode) && !(node instanceof StatusFileNode)) return; From d314bb414f8e1bd9ada6d7ec09d302658ae4f0b2 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Sat, 22 Dec 2018 00:32:05 -0600 Subject: [PATCH 2/3] add (un)stageDirectory --- src/git/gitService.ts | 20 ++++++++++++++++++++ src/views/viewCommands.ts | 16 ++++------------ 2 files changed, 24 insertions(+), 12 deletions(-) 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/viewCommands.ts b/src/views/viewCommands.ts index 849cae1fdb4d1..8167d56d638a2 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -467,13 +467,9 @@ export class ViewCommands implements Disposable { } private async stageDirectory(node: ViewNode) { + if (!node.uri.repoPath) return; - // TODO: get fileNodes from node - const fileNodes: (CommitFileNode | StatusFileNode)[] = []; - - for (const fileNode of fileNodes) { - void (await this.stageFile(fileNode)); - } + void (await Container.git.stageDirectory(node.uri.repoPath, node.uri)); } private async stageFile(node: CommitFileNode | StatusFileNode) { @@ -483,13 +479,9 @@ export class ViewCommands implements Disposable { } private async unstageDirectory(node: ViewNode) { + if (!node.uri.repoPath) return; - // TODO: get fileNodes from node - const fileNodes: (CommitFileNode | StatusFileNode)[] = []; - - for (const fileNode of fileNodes) { - void (await this.unstageFile(fileNode)); - } + void (await Container.git.unStageDirectory(node.uri.repoPath, node.uri)); } private async unstageFile(node: CommitFileNode | StatusFileNode) { From e6146c2c6b14e93f3fbee9bc566d2891864fe528 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Thu, 27 Dec 2018 10:11:27 -0600 Subject: [PATCH 3/3] use FolderNode --- src/views/nodes.ts | 1 + src/views/viewCommands.ts | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) 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 8167d56d638a2..b6a502729ac10 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -23,6 +23,7 @@ import { canDismissNode, CommitFileNode, CommitNode, + FolderNode, RemoteNode, RepositoryNode, ResultsFileNode, @@ -466,10 +467,10 @@ export class ViewCommands implements Disposable { return; } - private async stageDirectory(node: ViewNode) { - if (!node.uri.repoPath) return; + private async stageDirectory(node: FolderNode) { + if (!(node instanceof FolderNode) || !node.relativePath) return; - void (await Container.git.stageDirectory(node.uri.repoPath, node.uri)); + void (await Container.git.stageDirectory(node.repoPath, node.relativePath)); } private async stageFile(node: CommitFileNode | StatusFileNode) { @@ -478,10 +479,10 @@ export class ViewCommands implements Disposable { void (await Container.git.stageFile(node.repoPath, node.file.fileName)); } - private async unstageDirectory(node: ViewNode) { - if (!node.uri.repoPath) return; + private async unstageDirectory(node: FolderNode) { + if (!(node instanceof FolderNode) || !node.relativePath) return; - void (await Container.git.unStageDirectory(node.uri.repoPath, node.uri)); + void (await Container.git.unStageDirectory(node.repoPath, node.relativePath)); } private async unstageFile(node: CommitFileNode | StatusFileNode) {