Skip to content

Commit

Permalink
Merge pull request #246 from edgardmessias/rename_command
Browse files Browse the repository at this point in the history
Added rename with svn in explorer (See #239)
  • Loading branch information
JohnstonCode authored Apr 16, 2018
2 parents 6047189 + 9e5ce5d commit c200a0a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 4 deletions.
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;
}
}

0 comments on commit c200a0a

Please sign in to comment.