Skip to content

Commit 45ab2d1

Browse files
authored
Merge pull request #156 from edgardmessias/save_patches
Added ability to save patches (Close #155)
2 parents e6c8c7a + 55f6575 commit 45ab2d1

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

src/commands.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -733,16 +733,29 @@ export class SvnCommands implements IDisposable {
733733
@command("svn.patch", { repository: true })
734734
async patch(repository: Repository) {
735735
try {
736-
const resource = toSvnUri(
737-
Uri.file(repository.workspaceRoot),
738-
SvnUriAction.PATCH
739-
);
740-
const uri = resource.with({
741-
path: path.join(resource.path, "svn.patch") // change document title
736+
const tempFile = path.join(repository.root, ".svn", "tmp", "svn.patch");
737+
738+
if (fs.existsSync(tempFile)) {
739+
fs.unlinkSync(tempFile);
740+
}
741+
742+
const uri = Uri.file(tempFile).with({
743+
scheme: "untitled"
742744
});
743745

744-
await commands.executeCommand<void>("vscode.open", uri, {
745-
preview: true
746+
const document = await workspace.openTextDocument(uri);
747+
const textEditor = await window.showTextDocument(document);
748+
749+
const content = await repository.patch();
750+
await textEditor.edit(e => {
751+
// if is opened, clear content
752+
e.delete(
753+
new Range(
754+
new Position(0, 0),
755+
new Position(Number.MAX_SAFE_INTEGER, 0)
756+
)
757+
);
758+
e.insert(new Position(0, 0), content);
746759
});
747760
} catch (error) {
748761
console.error(error);
@@ -836,9 +849,7 @@ export class SvnCommands implements IDisposable {
836849
path: path.join(resource.path, "svn.log") // change document title
837850
});
838851

839-
await commands.executeCommand<void>("vscode.open", uri, {
840-
preview: true
841-
});
852+
await commands.executeCommand<void>("vscode.open", uri);
842853
} catch (error) {
843854
console.error(error);
844855
window.showErrorMessage("Unable to log");

src/repository.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
filterEvent,
2323
toDisposable,
2424
timeout,
25-
eventToPromise
25+
eventToPromise,
26+
isDescendant
2627
} from "./util";
2728
import * as path from "path";
2829
import * as micromatch from "micromatch";
@@ -509,6 +510,11 @@ export class Repository {
509510
return;
510511
}
511512

513+
// Not has original resource for content of ".svn" folder
514+
if (isDescendant(path.join(this.root, ".svn"), uri.fsPath)) {
515+
return;
516+
}
517+
512518
return toSvnUri(uri, SvnUriAction.SHOW);
513519
}
514520

0 commit comments

Comments
 (0)