@@ -5,15 +5,17 @@ import {
55 Uri ,
66 TextDocumentShowOptions ,
77 QuickPickItem ,
8- workspace
8+ workspace ,
9+ SourceControlResourceGroup
910} from "vscode" ;
1011import { inputCommitMessage } from "./messages" ;
11- import { Svn } from "./svn" ;
12+ import { Svn , Status } from "./svn" ;
1213import { Model } from "./model" ;
1314import { Repository } from "./repository" ;
1415import { Resource } from "./resource" ;
1516import { toSvnUri } from "./uri" ;
1617import * as path from "path" ;
18+ import { start } from "repl" ;
1719
1820interface 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+
85114export 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+ / ^ c h a n g e l i s t - / ,
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 ) {
0 commit comments