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

Added rename with svn in explorer (See #239) #246

Merged
merged 1 commit into from
Apr 16, 2018
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
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@
"command": "svn.addToIgnoreExplorer",
"title": "Ignore file/ext from SVN (svn:ignore)",
"category": "SVN"
},
{
"command": "svn.renameExplorer",
"title": "Rename with SVN",
"category": "SVN"
}
],
"menus": {
Expand Down Expand Up @@ -318,6 +323,10 @@
{
"command": "svn.addToIgnoreExplorer",
"when": "false"
},
{
"command": "svn.renameExplorer",
"when": "false"
}
],
"scm/title": [
Expand Down Expand Up @@ -497,6 +506,12 @@
"command": "svn.addToIgnoreExplorer",
"group": "9_svn",
"when": "config.svn.enabled && svnOpenRepositoryCount != 0"
},
{
"command": "svn.renameExplorer",
"group": "7_modification",
"when":
"config.svn.enabled && svnOpenRepositoryCount != 0 && explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !inputFocus"
}
]
},
Expand Down
39 changes: 38 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import * as path from "path";
import { start } from "repl";
import { getConflictPickOptions } from "./conflictItems";
import { applyLineChanges } from "./lineChanges";
import { IDisposable, hasSupportToRegisterDiffCommand } from "./util";
import {
IDisposable,
hasSupportToRegisterDiffCommand,
fixPathSeparator
} from "./util";
import {
inputSwitchChangelist,
inputCommitChangelist,
Expand Down Expand Up @@ -1100,6 +1104,39 @@ export class SvnCommands implements IDisposable {
});
}

@command("svn.renameExplorer", { repository: true })
async renameExplorer(repository: Repository, mainUri?: Uri, allUris?: Uri[]) {
if (!mainUri) {
return;
}

const oldName = mainUri.fsPath;

return await this.rename(repository, oldName);
}

@command("svn.rename", { repository: true })
async rename(repository: Repository, oldFile: string, newName?: string) {
oldFile = fixPathSeparator(oldFile);

if (!newName) {
const root = fixPathSeparator(repository.workspaceRoot);
const oldName = path.relative(root, oldFile);
newName = await window.showInputBox({
value: path.basename(oldFile),
prompt: `New name name for ${oldName}`
});
}
if (!newName) {
return;
}

const basepath = path.dirname(oldFile);
newName = path.join(basepath, newName);

await repository.rename(oldFile, newName);
}

private getSCMResource(uri?: Uri): Resource | undefined {
uri = uri
? uri
Expand Down
11 changes: 9 additions & 2 deletions src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,21 @@ export enum Operation {
CleanUp = "CleanUp",
Commit = "Commit",
CurrentBranch = "CurrentBranch",
Ignore = "Ignore",
Log = "Log",
NewBranch = "NewBranch",
NewCommits = "NewCommits",
Patch = "Patch",
Remove = "Remove",
RemoveChangelist = "RemoveChangelist",
Rename = "Rename",
Resolve = "Resolve",
Resolved = "Resolved",
Revert = "Revert",
Show = "Show",
Status = "Status",
SwitchBranch = "SwitchBranch",
Update = "Update",
Ignore = "Ignore"
Update = "Update"
}

function isReadOnly(operation: Operation): boolean {
Expand Down Expand Up @@ -717,6 +718,12 @@ export class Repository {
);
}

async rename(oldFile: string, newFile: string) {
return await this.run(Operation.Rename, () =>
this.repository.rename(oldFile, newFile)
);
}

async promptAuth(): Promise<boolean | undefined> {
// Prevent multiple prompts for auth
if (this.lastPromptAuth) {
Expand Down
18 changes: 17 additions & 1 deletion src/svnRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,13 @@ export class Repository {

async log() {
const logLength = configuration.get<string>("log.length") || "50";
const result = await this.exec(["log", "-r", "HEAD:1", "--limit", logLength]);
const result = await this.exec([
"log",
"-r",
"HEAD:1",
"--limit",
logLength
]);

return result.stdout;
}
Expand Down Expand Up @@ -457,4 +463,14 @@ export class Repository {

return result.stdout;
}

async rename(oldName: string, newName: string): Promise<string> {
oldName = this.removeAbsolutePath(oldName);
newName = this.removeAbsolutePath(newName);
const args = ["rename", oldName, newName];

const result = await this.exec(args);

return result.stdout;
}
}