瀏覽代碼

Adds stage/unstage commands to repo explorer

main
Eric Amodio 6 年之前
父節點
當前提交
0c75e4079a
共有 6 個文件被更改,包括 105 次插入9 次删除
  1. +4
    -0
      images/dark/icon-minus.svg
  2. +4
    -0
      images/light/icon-minus.svg
  3. +45
    -0
      package.json
  4. +8
    -0
      src/git/git.ts
  5. +26
    -8
      src/git/gitService.ts
  6. +18
    -1
      src/views/explorerCommands.ts

+ 4
- 0
images/dark/icon-minus.svg 查看文件

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 22">
<rect width="11" height="3" x="2.5" y="9.5" fill="#C5C5C5"/>
</svg>

+ 4
- 0
images/light/icon-minus.svg 查看文件

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 22">
<rect width="11" height="3" x="2.5" y="9.5" fill="#424242"/>
</svg>

+ 45
- 0
package.json 查看文件

@ -1880,6 +1880,24 @@
}
},
{
"command": "gitlens.explorers.stageFile",
"title": "Stage Changes",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-add.svg",
"light": "images/light/icon-add.svg"
}
},
{
"command": "gitlens.explorers.unstageFile",
"title": "Unstage Changes",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-minus.svg",
"light": "images/light/icon-minus.svg"
}
},
{
"command": "gitlens.explorers.openDirectoryDiff",
"title": "Open Directory Compare",
"category": "GitLens"
@ -2456,6 +2474,14 @@
"when": "false"
},
{
"command": "gitlens.explorers.stageFile",
"when": "false"
},
{
"command": "gitlens.explorers.unstageFile",
"when": "false"
},
{
"command": "gitlens.explorers.openChanges",
"when": "false"
},
@ -3200,6 +3226,25 @@
"group": "inline"
},
{
"command": "gitlens.explorers.stageFile",
"when": "viewItem =~ /gitlens:file\\b.*:unstaged\\b/",
"group": "inline"
},
{
"command": "gitlens.explorers.unstageFile",
"when": "viewItem =~ /gitlens:file\\b.*:staged\\b/",
"group": "inline"
},
{
"command": "gitlens.explorers.stageFile",
"when": "viewItem =~ /gitlens:file\\b.*:unstaged\\b/",
"group": "1_gitlens@1"
},
{
"command": "gitlens.explorers.unstageFile",
"when": "viewItem =~ /gitlens:file\\b.*:staged\\b/",
"group": "1_gitlens@1"
},
"command": "gitlens.explorers.openChanges",
"when": "viewItem =~ /gitlens:file\\b/",
"group": "2_gitlens@1"

+ 8
- 0
src/git/git.ts 查看文件

@ -262,6 +262,10 @@ export class Git {
// Git commands
static add(repoPath: string | undefined, fileName: string) {
return git<string>({ cwd: repoPath }, 'add', '-A', '--', fileName);
}
static async blame(
repoPath: string | undefined,
fileName: string,
@ -610,6 +614,10 @@ export class Git {
return git<string>({ cwd: repoPath }, 'remote', 'get-url', remote);
}
static reset(repoPath: string | undefined, fileName: string) {
return git<string>({ cwd: repoPath }, 'reset', '-q', '--', fileName);
}
static async revparse(repoPath: string, ref: string): Promise<string | undefined> {
const data = await git<string>({ cwd: repoPath, exceptionHandler: ignoreExceptionsHandler }, 'rev-parse', ref);
return data === '' ? undefined : data.trim();

+ 26
- 8
src/git/gitService.ts 查看文件

@ -1691,6 +1691,12 @@ export class GitService implements Disposable {
return GitTreeParser.parse(data) || [];
}
getVersionedFileBuffer(repoPath: string, fileName: string, ref: string) {
Logger.log(`getVersionedFileBuffer('${repoPath}', '${fileName}', ${ref})`);
return Git.show<Buffer>(repoPath, fileName, ref, { encoding: 'buffer' });
}
async getVersionedUri(
repoPath: string | undefined,
fileName: string,
@ -1719,12 +1725,6 @@ export class GitService implements Disposable {
return GitUri.toRevisionUri(ref, fileName, repoPath!);
}
getVersionedFileBuffer(repoPath: string, fileName: string, ref: string) {
Logger.log(`getVersionedFileBuffer('${repoPath}', '${fileName}', ${ref})`);
return Git.show<Buffer>(repoPath, fileName, ref, { encoding: 'buffer' });
}
isTrackable(scheme: string): boolean;
isTrackable(uri: Uri): boolean;
isTrackable(schemeOruri: string | Uri): boolean {
@ -1868,8 +1868,26 @@ export class GitService implements Disposable {
return ensuredRef;
}
stopWatchingFileSystem() {
this._repositoryTree.forEach(r => r.stopWatchingFileSystem());
stageFile(repoPath: string, fileName: string): Promise<string>;
stageFile(repoPath: string, uri: Uri): Promise<string>;
stageFile(repoPath: string, fileNameOrUri: string | Uri): Promise<string> {
Logger.log(`stageFile('${repoPath}', '${fileNameOrUri}')`);
return Git.add(
repoPath,
typeof fileNameOrUri === 'string' ? fileNameOrUri : Git.splitPath(fileNameOrUri.fsPath, repoPath)[0]
);
}
unStageFile(repoPath: string, fileName: string): Promise<string>;
unStageFile(repoPath: string, uri: Uri): Promise<string>;
unStageFile(repoPath: string, fileNameOrUri: string | Uri): Promise<string> {
Logger.log(`unStageFile('${repoPath}', '${fileNameOrUri}')`);
return Git.reset(
repoPath,
typeof fileNameOrUri === 'string' ? fileNameOrUri : Git.splitPath(fileNameOrUri.fsPath, repoPath)[0]
);
}
stashApply(repoPath: string, stashName: string, deleteAfter: boolean = false) {

+ 18
- 1
src/views/explorerCommands.ts 查看文件

@ -52,6 +52,7 @@ export class ExplorerCommands implements Disposable {
commands.registerCommand('gitlens.explorers.fetch', this.fetch, this);
commands.registerCommand('gitlens.explorers.pull', this.pull, this);
commands.registerCommand('gitlens.explorers.push', this.push, this);
commands.registerCommand('gitlens.explorers.closeRepository', this.closeRepository, this);
commands.registerCommand('gitlens.explorers.exploreRepoRevision', this.exploreRepoRevision, this);
@ -69,13 +70,17 @@ export class ExplorerCommands implements Disposable {
);
commands.registerCommand('gitlens.explorers.openChangedFileRevisions', this.openChangedFileRevisions, this);
commands.registerCommand('gitlens.explorers.applyChanges', this.applyChanges, this);
commands.registerCommand('gitlens.explorers.closeRepository', this.closeRepository, this);
commands.registerCommand('gitlens.explorers.stageFile', this.stageFile, this);
commands.registerCommand('gitlens.explorers.unstageFile', this.unstageFile, this);
commands.registerCommand('gitlens.explorers.compareAncestryWithWorking', this.compareAncestryWithWorking, this);
commands.registerCommand('gitlens.explorers.compareWithHead', this.compareWithHead, this);
commands.registerCommand('gitlens.explorers.compareWithRemote', this.compareWithRemote, this);
commands.registerCommand('gitlens.explorers.compareWithSelected', this.compareWithSelected, this);
commands.registerCommand('gitlens.explorers.compareWithWorking', this.compareWithWorking, this);
commands.registerCommand('gitlens.explorers.selectForCompare', this.selectForCompare, this);
commands.registerCommand('gitlens.explorers.terminalCheckoutBranch', this.terminalCheckoutBranch, this);
commands.registerCommand('gitlens.explorers.terminalCreateBranch', this.terminalCreateBranch, this);
commands.registerCommand('gitlens.explorers.terminalDeleteBranch', this.terminalDeleteBranch, this);
@ -361,6 +366,18 @@ export class ExplorerCommands implements Disposable {
} as OpenFileInRemoteCommandArgs);
}
stageFile(node: CommitFileNode | StatusFileNode) {
if (!(node instanceof CommitFileNode) && !(node instanceof StatusFileNode)) return;
Container.git.stageFile(node.repoPath, node.file.fileName);
}
unstageFile(node: CommitFileNode | StatusFileNode) {
if (!(node instanceof CommitFileNode) && !(node instanceof StatusFileNode)) return;
Container.git.unStageFile(node.repoPath, node.file.fileName);
}
async terminalCheckoutBranch(node: ExplorerNode) {
if (!(node instanceof BranchNode)) return;

Loading…
取消
儲存