Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rename by git context menu #97486

Merged
merged 2 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
20 changes: 20 additions & 0 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,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