Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add rename by git context menu
  • Loading branch information
Kingwl committed May 11, 2020
commit b24cb8b47d4ed3703e5018f6c45f5feee70d2095
13 changes: 13 additions & 0 deletions extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@
"category": "Git",
"icon": "$(discard)"
},
{
"command": "git.rename",
"title": "%command.rename%",
"category": "Git",
"icon": "$(discard)"
},
{
"command": "git.cleanAll",
"title": "%command.cleanAll%",
Expand Down Expand Up @@ -1296,6 +1302,13 @@
"group": "5_copy@2",
"when": "config.git.enabled && !git.missing && timelineItem =~ /git:file:commit\\b/"
}
],
"explorer/context": [
{
"command": "git.rename",
"group": "7_modification",
"when": "config.git.enabled && !git.missing && !explorerResourceIsRoot"
}
]
},
"configuration": {
Expand Down
1 change: 1 addition & 0 deletions extensions/git/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"command.unstage": "Unstage Changes",
"command.unstageAll": "Unstage All Changes",
"command.unstageSelectedRanges": "Unstage Selected Ranges",
"command.rename": "Rename (Git)",
"command.clean": "Discard Changes",
"command.cleanAll": "Discard All Changes",
"command.cleanAllTracked": "Discard All Tracked Changes",
Expand Down
21 changes: 21 additions & 0 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { grep, isDescendant, pathEquals } from './util';
import { Log, LogLevel } from './log';
import { GitTimelineItem } from './timelineProvider';
import { throttle, debounce } from './decorators';
import { URI } from 'vscode-uri';

const localize = nls.loadMessageBundle();

Expand Down Expand Up @@ -930,6 +931,26 @@ export class CommandCenter {
}
}

@command('git.rename', { repository: true })
async rename(repository: Repository, fromUri: URI): Promise<void> {
this.outputChannel.appendLine(`git.rename ${fromUri.fsPath}`);

const rootPath = workspace.rootPath;
const fromPath = workspace.asRelativePath(fromUri);
const fromBasename = path.basename(fromPath);
const toPath = await window.showInputBox({
value: fromPath,
valueSelection: [fromPath.length - fromBasename.length, fromPath.length]
});
if (!toPath?.trim()) {
return;
}

const fullToPath = path.join(rootPath || '', toPath);
this.outputChannel.appendLine(`git.rename from ${fromPath} to ${fullToPath}`);
await repository.move(fromPath, fullToPath);
}

@command('git.stage')
async stage(...resourceStates: SourceControlResourceState[]): Promise<void> {
this.outputChannel.appendLine(`git.stage ${resourceStates.length}`);
Expand Down
5 changes: 5 additions & 0 deletions extensions/git/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,11 @@ export class Repository {
await this.run(args);
}

async move(from: string, to: string): Promise<void> {
const args = ['mv', from, to];
await this.run(args);
}

async setBranchUpstream(name: string, upstream: string): Promise<void> {
const args = ['branch', '--set-upstream-to', upstream, name];
await this.run(args);
Expand Down
6 changes: 6 additions & 0 deletions extensions/git/src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ export const enum Operation {
Blame = 'Blame',
Log = 'Log',
LogFile = 'LogFile',

Move = 'Move'
}

function isReadOnly(operation: Operation): boolean {
Expand Down Expand Up @@ -1045,6 +1047,10 @@ export class Repository implements Disposable {
await this.run(Operation.RenameBranch, () => this.repository.renameBranch(name));
}

async move(from: string, to: string): Promise<void> {
await this.run(Operation.Move, () => this.repository.move(from, to));
}

async getBranch(name: string): Promise<Branch> {
return await this.run(Operation.GetBranch, () => this.repository.getBranch(name));
}
Expand Down
4 changes: 2 additions & 2 deletions extensions/types/lib.textEncoder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
//
// Proper fix: https://github.com/microsoft/TypeScript/issues/31535

declare var TextDecoder: typeof import('util').TextDecoder;
declare var TextEncoder: typeof import('util').TextEncoder;
declare let TextDecoder: typeof import('util').TextDecoder;
declare let TextEncoder: typeof import('util').TextEncoder;