Skip to content

Commit 16ad5c0

Browse files
committed
added command patch changelist (fixes #215)
1 parent 7bdac80 commit 16ad5c0

File tree

6 files changed

+93
-3
lines changed

6 files changed

+93
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## What's New
44

55
* @JohnstonCode Added configuration option to disable update message
6+
* @JohnstonCode Added command show patch from changelist
67

78
# **v1.25.0**
89

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@
212212
"command": "svn.cleanup",
213213
"title": "Clean up working copy",
214214
"category": "SVN"
215+
},
216+
{
217+
"command": "svn.patchChangeList",
218+
"title": "Show patch from changelist",
219+
"category": "SVN"
215220
}
216221
],
217222
"menus": {
@@ -339,6 +344,10 @@
339344
{
340345
"command": "svn.cleanup",
341346
"when": "config.svn.enabled && scmProvider == svn"
347+
},
348+
{
349+
"command": "svn.patchChangeList",
350+
"when": "config.svn.enabled && scmProvider == svn"
342351
}
343352
],
344353
"scm/sourceControl": [

src/changelistItems.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,33 @@ export async function inputCommitChangelist(repository: Repository) {
167167

168168
return choice;
169169
}
170+
171+
export function patchChangelistOptions(repository: Repository) {
172+
const picks: QuickPickItem[] = [];
173+
174+
repository.changelists.forEach((group, changelist) => {
175+
if (group.resourceStates.length) {
176+
picks.push(new ChangeListItem(group));
177+
}
178+
});
179+
180+
return picks;
181+
}
182+
183+
export async function getPatchChangelist(repository: Repository) {
184+
const picks: QuickPickItem[] = patchChangelistOptions(repository);
185+
186+
if (!picks.length) {
187+
window.showErrorMessage('No changelists to pick from');
188+
return;
189+
}
190+
191+
const selectedChoice: any = await window.showQuickPick(picks, {
192+
placeHolder: "Select a changelist"
193+
});
194+
if (!selectedChoice) {
195+
return;
196+
}
197+
198+
return selectedChoice.label;
199+
}

src/commands.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ import { getConflictPickOptions } from "./conflictItems";
3030
import { applyLineChanges } from "./lineChanges";
3131
import { IDisposable, hasSupportToRegisterDiffCommand } from "./util";
3232
import {
33-
getChangelistPickOptions,
3433
inputSwitchChangelist,
35-
getCommitChangelistPickOptions,
36-
inputCommitChangelist
34+
inputCommitChangelist,
35+
getPatchChangelist
3736
} from "./changelistItems";
3837
import { configuration } from "./helpers/configuration";
3938
import { selectBranch } from "./branches";
@@ -762,6 +761,47 @@ export class SvnCommands implements IDisposable {
762761
await this.showDiffPath(repository, files);
763762
});
764763
}
764+
765+
@command("svn.patchChangeList", { repository: true })
766+
async patchChangeList(repository: Repository): Promise<void> {
767+
const changelistName = await getPatchChangelist(repository);
768+
769+
if (!changelistName) {
770+
return;
771+
}
772+
773+
//@TODO clean up the try catch below copied code from showDiffPatch
774+
775+
try {
776+
const tempFile = path.join(repository.root, ".svn", "tmp", "svn.patch");
777+
778+
if (fs.existsSync(tempFile)) {
779+
fs.unlinkSync(tempFile);
780+
}
781+
782+
const uri = Uri.file(tempFile).with({
783+
scheme: "untitled"
784+
});
785+
786+
const document = await workspace.openTextDocument(uri);
787+
const textEditor = await window.showTextDocument(document);
788+
789+
const content = await repository.patchChangelist(changelistName);
790+
await textEditor.edit(e => {
791+
// if is opened, clear content
792+
e.delete(
793+
new Range(
794+
new Position(0, 0),
795+
new Position(Number.MAX_SAFE_INTEGER, 0)
796+
)
797+
);
798+
e.insert(new Position(0, 0), content);
799+
});
800+
} catch (error) {
801+
console.error(error);
802+
window.showErrorMessage("Unable to patch");
803+
}
804+
}
765805

766806
@command("svn.remove")
767807
async remove(...resourceStates: SourceControlResourceState[]): Promise<void> {

src/repository.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,10 @@ export class Repository {
667667
async patch(files: string[]) {
668668
return await this.run(Operation.Patch, () => this.repository.patch(files));
669669
}
670+
671+
async patchChangelist(changelistName: string) {
672+
return await this.run(Operation.Patch, () => this.repository.patchChangelist(changelistName));
673+
}
670674

671675
async removeFiles(files: any[], keepLocal: boolean) {
672676
return await this.run(Operation.Remove, () =>

src/svnRepository.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,12 @@ export class Repository {
329329
const message = result.stdout;
330330
return message;
331331
}
332+
333+
async patchChangelist(changelistName: string) {
334+
const result = await this.exec(["diff", "--changelist", changelistName]);
335+
const message = result.stdout;
336+
return message;
337+
}
332338

333339
async removeFiles(files: any[], keepLocal: boolean) {
334340
files = files.map(file => this.removeAbsolutePath(file));

0 commit comments

Comments
 (0)