Skip to content

Commit 1f92653

Browse files
committed
Added support to commit changelist (#95);
1 parent 469ce60 commit 1f92653

File tree

3 files changed

+87
-30
lines changed

3 files changed

+87
-30
lines changed

src/commands.ts

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
Uri,
66
TextDocumentShowOptions,
77
QuickPickItem,
8-
workspace
8+
workspace,
9+
SourceControlResourceGroup
910
} from "vscode";
1011
import { inputCommitMessage } from "./messages";
1112
import { Svn } from "./svn";
@@ -82,6 +83,21 @@ class SwitchBranchItem implements QuickPickItem {
8283
}
8384
}
8485

86+
class ChangeListItem implements QuickPickItem {
87+
constructor(protected group: SourceControlResourceGroup) {}
88+
89+
get label(): string {
90+
return this.group.label;
91+
}
92+
93+
get description(): string {
94+
return this.group.label;
95+
}
96+
get resourceGroup(): SourceControlResourceGroup {
97+
return this.group;
98+
}
99+
}
100+
85101
export class SvnCommands {
86102
private commands: any[] = [];
87103

@@ -138,19 +154,37 @@ export class SvnCommands {
138154
@command("svn.commitWithMessage", { repository: true })
139155
async commitWithMessage(repository: Repository) {
140156
const message = repository.inputBox.value;
141-
const changes = repository.changes.resourceStates;
142-
let filePaths;
143-
144157
if (!message) {
145158
return;
146159
}
147160

148-
if (changes.length === 0) {
161+
const picks: ChangeListItem[] = [];
162+
163+
if (repository.changes.resourceStates.length) {
164+
picks.push(new ChangeListItem(repository.changes));
165+
}
166+
167+
repository.changelists.forEach((group, changelist) => {
168+
if (group.resourceStates.length) {
169+
picks.push(new ChangeListItem(group));
170+
}
171+
});
172+
173+
if (picks.length === 0) {
149174
window.showInformationMessage("There are no changes to commit.");
150175
return;
151176
}
152177

153-
filePaths = changes.map(state => {
178+
let choice = picks[0];
179+
if (picks.length > 1) {
180+
const selectedChoice = await window.showQuickPick(picks, {});
181+
if (!selectedChoice) {
182+
return;
183+
}
184+
choice = selectedChoice;
185+
}
186+
187+
const filePaths = choice.resourceGroup.resourceStates.map(state => {
154188
return state.resourceUri.fsPath;
155189
});
156190

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
}

src/repository.ts

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export class Repository {
2626
public watcher: FileSystemWatcher;
2727
public sourceControl: SourceControl;
2828
public changes: SourceControlResourceGroup;
29-
public notTracked: SourceControlResourceGroup;
3029
public external: SourceControlResourceGroup;
30+
public changelists: Map<string, SourceControlResourceGroup> = new Map();
3131
private disposables: Disposable[] = [];
3232
public currentBranch = "";
3333
public isSwitchingBranch: boolean = false;
@@ -124,17 +124,12 @@ export class Repository {
124124
updateBranchName();
125125

126126
this.changes = this.sourceControl.createResourceGroup("changes", "Changes");
127-
this.notTracked = this.sourceControl.createResourceGroup(
128-
"unversioned",
129-
"Not Tracked"
130-
);
131127
this.external = this.sourceControl.createResourceGroup(
132128
"external",
133129
"External"
134130
);
135131

136132
this.changes.hideWhenEmpty = true;
137-
this.notTracked.hideWhenEmpty = true;
138133
this.external.hideWhenEmpty = true;
139134

140135
this.disposables.push(
@@ -160,8 +155,9 @@ export class Repository {
160155
@debounce(1000)
161156
async update() {
162157
let changes: any[] = [];
163-
let notTracked: any[] = [];
164158
let external: any[] = [];
159+
let changelists: Map<string, Resource[]> = new Map();
160+
165161
const statuses = (await this.repository.getStatus()) || [];
166162

167163
const fileConfig = workspace.getConfiguration("files");
@@ -187,28 +183,55 @@ export class Repository {
187183

188184
if (status.status === Status.EXTERNAL) {
189185
external.push(new Resource(uri, status.status, renameUri));
190-
} else if (status.status === Status.UNVERSIONED) {
191-
const matches = status.path.match(
192-
/(.+?)\.(mine|working|merge-\w+\.r\d+|r\d+)$/
193-
);
194-
195-
//If file end with (mine, working, merge, etc..) and has file without extension
196-
if (
197-
matches &&
198-
matches[1] &&
199-
statuses.some(s => s.path === matches[1])
200-
) {
201-
return;
186+
} else {
187+
if (status.status === Status.UNVERSIONED) {
188+
const matches = status.path.match(
189+
/(.+?)\.(mine|working|merge-\w+\.r\d+|r\d+)$/
190+
);
191+
192+
//If file end with (mine, working, merge, etc..) and has file without extension
193+
if (
194+
matches &&
195+
matches[1] &&
196+
statuses.some(s => s.path === matches[1])
197+
) {
198+
return;
199+
}
202200
}
203201

204-
notTracked.push(new Resource(uri, status.status, renameUri));
205-
} else {
206-
changes.push(new Resource(uri, status.status, renameUri));
202+
if (!status.changelist) {
203+
changes.push(new Resource(uri, status.status, renameUri));
204+
} else {
205+
let changelist = changelists.get(status.changelist);
206+
if (!changelist) {
207+
changelist = [];
208+
}
209+
changelist.push(new Resource(uri, status.status, renameUri));
210+
changelists.set(status.changelist, changelist);
211+
}
207212
}
208213
});
209214

210215
this.changes.resourceStates = changes;
211-
this.notTracked.resourceStates = notTracked;
216+
217+
this.changelists.forEach((group, changelist) => {
218+
group.resourceStates = [];
219+
});
220+
221+
changelists.forEach((resources, changelist) => {
222+
let group = this.changelists.get(changelist);
223+
if (!group) {
224+
group = this.sourceControl.createResourceGroup(
225+
`changelist-${changelist}`,
226+
`Changelist "${changelist}"`
227+
);
228+
group.hideWhenEmpty = true;
229+
230+
this.changelists.set(changelist, group);
231+
}
232+
233+
group.resourceStates = resources;
234+
});
212235

213236
if (svnConfig.get<boolean>("sourceControl.showExternal")) {
214237
this.external.resourceStates = external;

0 commit comments

Comments
 (0)