Skip to content

Commit 5c9d0e5

Browse files
authored
Merge pull request #120 from edgardmessias/changelists_support
Added support to changelists (Close #95,#99)
2 parents 469ce60 + 9a76654 commit 5c9d0e5

File tree

8 files changed

+282
-35
lines changed

8 files changed

+282
-35
lines changed

icons/dark/remove.svg

Lines changed: 1 addition & 0 deletions
Loading

icons/light/remove.svg

Lines changed: 1 addition & 0 deletions
Loading

package.json

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,24 @@
6060
"dark": "icons/dark/add.svg"
6161
}
6262
},
63+
{
64+
"command": "svn.addChangelist",
65+
"title": "Add to a changelist",
66+
"category": "SVN",
67+
"icon": {
68+
"light": "icons/light/add.svg",
69+
"dark": "icons/dark/add.svg"
70+
}
71+
},
72+
{
73+
"command": "svn.removeChangelist",
74+
"title": "Remove from changelist",
75+
"category": "SVN",
76+
"icon": {
77+
"light": "icons/light/remove.svg",
78+
"dark": "icons/dark/remove.svg"
79+
}
80+
},
6381
{
6482
"command": "svn.commit",
6583
"title": "Commit Selected",
@@ -130,27 +148,58 @@
130148
"scm/resourceState/context": [
131149
{
132150
"command": "svn.add",
133-
"when": "scmProvider == svn && scmResourceGroup == unversioned",
151+
"when":
152+
"config.svn.enabled && scmProvider == svn && scmResourceGroup == unversioned",
153+
"group": "inline"
154+
},
155+
{
156+
"command": "svn.add",
157+
"when":
158+
"config.svn.enabled && scmProvider == svn && scmResourceGroup == unversioned",
159+
"group": "1_modification"
160+
},
161+
{
162+
"command": "svn.addChangelist",
163+
"when":
164+
"config.svn.enabled && scmProvider == svn && scmResourceGroup != external",
165+
"group": "inline"
166+
},
167+
{
168+
"command": "svn.addChangelist",
169+
"when":
170+
"config.svn.enabled && scmProvider == svn && scmResourceGroup != external",
171+
"group": "1_modification"
172+
},
173+
{
174+
"command": "svn.removeChangelist",
175+
"when":
176+
"config.svn.enabled && scmProvider == svn && scmResourceGroup != changes && scmResourceGroup != unversioned && scmResourceGroup != external",
134177
"group": "inline"
135178
},
179+
{
180+
"command": "svn.removeChangelist",
181+
"when":
182+
"config.svn.enabled && scmProvider == svn && scmResourceGroup != changes && scmResourceGroup != unversioned && scmResourceGroup != external",
183+
"group": "1_modification"
184+
},
136185
{
137186
"command": "svn.commit",
138-
"when": "scmProvider == svn && scmResourceGroup == changes",
187+
"when": "scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external",
139188
"group": "1_modification"
140189
},
141190
{
142191
"command": "svn.openDiffHead",
143-
"when": "scmProvider == svn && scmResourceGroup == changes",
192+
"when": "scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external",
144193
"group": "navigation"
145194
},
146195
{
147196
"command": "svn.revert",
148-
"when": "scmProvider == svn && scmResourceGroup == changes",
197+
"when": "scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external",
149198
"group": "1_modification"
150199
},
151200
{
152201
"command": "svn.remove",
153-
"when": "scmProvider == svn && scmResourceGroup == changes",
202+
"when": "scmProvider == svn && scmResourceGroup != unversioned && scmResourceGroup != external",
154203
"group": "2_modification"
155204
}
156205
],

src/commands.ts

Lines changed: 143 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ import {
55
Uri,
66
TextDocumentShowOptions,
77
QuickPickItem,
8-
workspace
8+
workspace,
9+
SourceControlResourceGroup
910
} from "vscode";
1011
import { inputCommitMessage } from "./messages";
11-
import { Svn } from "./svn";
12+
import { Svn, Status } from "./svn";
1213
import { Model } from "./model";
1314
import { Repository } from "./repository";
1415
import { Resource } from "./resource";
1516
import { toSvnUri } from "./uri";
1617
import * as path from "path";
18+
import { start } from "repl";
1719

1820
interface CommandOptions {
1921
repository?: boolean;
@@ -82,6 +84,33 @@ class SwitchBranchItem implements QuickPickItem {
8284
}
8385
}
8486

87+
class ChangeListItem implements QuickPickItem {
88+
constructor(protected group: SourceControlResourceGroup) {}
89+
90+
get label(): string {
91+
return this.group.label;
92+
}
93+
94+
get description(): string {
95+
return this.group.label;
96+
}
97+
get resourceGroup(): SourceControlResourceGroup {
98+
return this.group;
99+
}
100+
}
101+
102+
class NewChangeListItem implements QuickPickItem {
103+
constructor() {}
104+
105+
get label(): string {
106+
return "$(plus) New changelist";
107+
}
108+
109+
get description(): string {
110+
return "Create a new change list";
111+
}
112+
}
113+
85114
export class SvnCommands {
86115
private commands: any[] = [];
87116

@@ -138,22 +167,49 @@ export class SvnCommands {
138167
@command("svn.commitWithMessage", { repository: true })
139168
async commitWithMessage(repository: Repository) {
140169
const message = repository.inputBox.value;
141-
const changes = repository.changes.resourceStates;
142-
let filePaths;
143-
144170
if (!message) {
145171
return;
146172
}
147173

148-
if (changes.length === 0) {
174+
const picks: ChangeListItem[] = [];
175+
176+
if (repository.changes.resourceStates.length) {
177+
picks.push(new ChangeListItem(repository.changes));
178+
}
179+
180+
repository.changelists.forEach((group, changelist) => {
181+
if (group.resourceStates.length) {
182+
picks.push(new ChangeListItem(group));
183+
}
184+
});
185+
186+
if (picks.length === 0) {
149187
window.showInformationMessage("There are no changes to commit.");
150188
return;
151189
}
152190

153-
filePaths = changes.map(state => {
191+
let choice = picks[0];
192+
if (picks.length > 1) {
193+
const selectedChoice = await window.showQuickPick(picks, {});
194+
if (!selectedChoice) {
195+
return;
196+
}
197+
choice = selectedChoice;
198+
}
199+
200+
const filePaths = choice.resourceGroup.resourceStates.map(state => {
154201
return state.resourceUri.fsPath;
155202
});
156203

204+
//If files is renamed, the commit need previous file
205+
choice.resourceGroup.resourceStates.forEach(state => {
206+
if (state instanceof Resource) {
207+
if (state.type === Status.ADDED && state.renameResourceUri) {
208+
filePaths.push(state.renameResourceUri.fsPath);
209+
}
210+
}
211+
});
212+
157213
try {
158214
const result = await repository.repository.commitFiles(
159215
message,
@@ -184,6 +240,78 @@ export class SvnCommands {
184240
}
185241
}
186242

243+
@command("svn.addChangelist")
244+
async addChangelist(resource: Resource) {
245+
const repository = this.model.getRepository(resource.resourceUri.fsPath);
246+
247+
if (!repository) {
248+
return;
249+
}
250+
251+
const picks: QuickPickItem[] = [];
252+
253+
repository.changelists.forEach((group, changelist) => {
254+
if (group.resourceStates.length) {
255+
picks.push(new ChangeListItem(group));
256+
}
257+
});
258+
picks.push(new NewChangeListItem());
259+
260+
const selectedChoice: any = await window.showQuickPick(picks, {});
261+
if (!selectedChoice) {
262+
return;
263+
}
264+
265+
let changelistName = "";
266+
267+
if (selectedChoice instanceof NewChangeListItem) {
268+
const newChangelistName = await window.showInputBox();
269+
if (!newChangelistName) {
270+
return;
271+
}
272+
changelistName = newChangelistName;
273+
} else if (selectedChoice instanceof ChangeListItem) {
274+
changelistName = selectedChoice.resourceGroup.id.replace(
275+
/^changelist-/,
276+
""
277+
);
278+
} else {
279+
return;
280+
}
281+
282+
try {
283+
await repository.addChangelist(
284+
resource.resourceUri.fsPath,
285+
changelistName
286+
);
287+
} catch (error) {
288+
console.log(error);
289+
window.showErrorMessage(
290+
`Unable to add file "${
291+
resource.resourceUri.fsPath
292+
}" to changelist "${changelistName}"`
293+
);
294+
}
295+
}
296+
297+
@command("svn.removeChangelist")
298+
async removeChangelist(resource: Resource) {
299+
const repository = this.model.getRepository(resource.resourceUri.fsPath);
300+
301+
if (!repository) {
302+
return;
303+
}
304+
305+
try {
306+
await repository.removeChangelist(resource.resourceUri.fsPath);
307+
} catch (error) {
308+
console.log(error);
309+
window.showErrorMessage(
310+
`Unable to remove file "${resource.resourceUri.fsPath}" from changelist`
311+
);
312+
}
313+
}
314+
187315
@command("svn.commit", { repository: true })
188316
async commit(
189317
repository: Repository,
@@ -193,6 +321,14 @@ export class SvnCommands {
193321
const paths = resourceStates.map(state => {
194322
return state.resourceUri.fsPath;
195323
});
324+
325+
//If files is renamed, the commit need previous file
326+
resourceStates.forEach(state => {
327+
if (state.type === Status.ADDED && state.renameResourceUri) {
328+
paths.push(state.renameResourceUri.fsPath);
329+
}
330+
});
331+
196332
const message = await inputCommitMessage();
197333

198334
if (message === undefined) {

src/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export class Model {
267267
return liveRepository;
268268
}
269269

270-
if (hint === repository.changes || hint === repository.notTracked) {
270+
if (hint === repository.changes) {
271271
return liveRepository;
272272
}
273273
}

0 commit comments

Comments
 (0)