PageRenderTime 54ms CodeModel.GetById 24ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 1ms

/Mercurial.Net/Gui/CloneGuiCommand.cs

#
C# | 380 lines | 177 code | 37 blank | 166 comment | 13 complexity | a04b4ca0531ee377fcec3ba35d15ceef MD5 | raw file
  1using System;
  2using System.Collections.Generic;
  3using System.ComponentModel;
  4using System.Linq;
  5using Mercurial.Attributes;
  6
  7namespace Mercurial.Gui
  8{
  9    /// <summary>
 10    /// Implements the TortoiseHg "clone" command (<see href="http://tortoisehg.bitbucket.org/manual/2.0/clone.html#from-command-line"/>):
 11    /// Clone a repository.
 12    /// </summary>
 13    public sealed class CloneGuiCommand : GuiCommandBase<CloneGuiCommand>
 14    {
 15        /// <summary>
 16        /// This is the backing field for the <see cref="UpdateToRevision"/> property.
 17        /// </summary>
 18        private RevSpec _UpdateToRevision;
 19
 20        /// <summary>
 21        /// This is the backing field for the <see cref="IncludeRevision"/> property.
 22        /// </summary>
 23        private RevSpec _IncludeRevision;
 24
 25        /// <summary>
 26        /// This is the backing field for the <see cref="Source"/> property.
 27        /// </summary>
 28        private string _Source = string.Empty;
 29
 30        /// <summary>
 31        /// This is the backing field for the <see cref="Branch"/> property.
 32        /// </summary>
 33        private string _Branch = string.Empty;
 34
 35        /// <summary>
 36        /// This is the backing field for the <see cref="CompressedTransfer"/> property.
 37        /// </summary>
 38        private bool _CompressedTransfer = true;
 39
 40        /// <summary>
 41        /// This is the backing field for the <see cref="Update"/> property.
 42        /// </summary>
 43        private bool _Update = true;
 44
 45        /// <summary>
 46        /// This is the backing field for the <see cref="UsePullProtocol"/> property.
 47        /// </summary>
 48        private bool _UsePullProtocol;
 49
 50        /// <summary>
 51        /// Initializes a new instance of the <see cref="CloneGuiCommand"/> class.
 52        /// </summary>
 53        public CloneGuiCommand()
 54            : base("clone")
 55        {
 56            // Do nothing here
 57        }
 58
 59        /// <summary>
 60        /// Gets or sets the source path or Uri to clone from.
 61        /// </summary>
 62        [DefaultValue("")]
 63        public string Source
 64        {
 65            get
 66            {
 67                return _Source;
 68            }
 69
 70            set
 71            {
 72                _Source = (value ?? string.Empty).Trim();
 73            }
 74        }
 75
 76        /// <summary>
 77        /// Gets or sets a value indicating whether to update the clone with a working folder.
 78        /// Default is <c>true</c>.
 79        /// </summary>
 80        /// <remarks>
 81        /// This property is only available for the <see cref="GuiClientType.PyQT"/> client type.
 82        /// </remarks>
 83        [BooleanArgument(FalseOption = "--noupdate")]
 84        [DefaultValue(true)]
 85        public bool Update
 86        {
 87            get
 88            {
 89                return _Update;
 90            }
 91
 92            set
 93            {
 94                if (_Update == value)
 95                    return;
 96                
 97                EnsurePropertyAvailability("Update", GuiClientType.PyQT);
 98                _Update = value;
 99            }
100        }
101
102        /// <summary>
103        /// Gets or sets a value indicating whether to use the pull protocol to copy metadata.
104        /// Default is <c>false</c>.
105        /// </summary>
106        /// <remarks>
107        /// This property is only available for the <see cref="GuiClientType.PyQT"/> client type.
108        /// </remarks>
109        [BooleanArgument(TrueOption = "--pull")]
110        [DefaultValue(false)]
111        public bool UsePullProtocol
112        {
113            get
114            {
115                return _UsePullProtocol;
116            }
117
118            set
119            {
120                if (_UsePullProtocol == value)
121                    return;
122                
123                EnsurePropertyAvailability("UsePullProtocol", GuiClientType.PyQT);
124                _UsePullProtocol = value;
125            }
126        }
127
128        /// <summary>
129        /// Gets or sets the <see cref="UpdateToRevision"/> to update the working
130        /// folder to, or <c>null</c> to update to the tip. Default is <c>null</c>.
131        /// </summary>
132        /// <remarks>
133        /// This property is only available for the <see cref="GuiClientType.PyQT"/> client type.
134        /// </remarks>
135        [NullableArgument(NonNullOption = "--updaterev")]
136        [DefaultValue(null)]
137        public RevSpec UpdateToRevision
138        {
139            get
140            {
141                return _UpdateToRevision;
142            }
143
144            set
145            {
146                if (_UpdateToRevision == value)
147                    return;
148                
149                EnsurePropertyAvailability("UpdateToRevision", GuiClientType.PyQT);
150                _UpdateToRevision = value;
151            }
152        }
153
154        /// <summary>
155        /// Gets or sets a value indicating whether to use compressed transfer or not. Over LAN, uncompressed is faster, otherwise
156        /// compressed is most likely faster. Default is <c>true</c>.
157        /// </summary>
158        /// <remarks>
159        /// This property is only available for the <see cref="GuiClientType.PyQT"/> client type.
160        /// </remarks>
161        [BooleanArgument(FalseOption = "--uncompressed")]
162        [DefaultValue(true)]
163        public bool CompressedTransfer
164        {
165            get
166            {
167                return _CompressedTransfer;
168            }
169
170            set
171            {
172                if (_CompressedTransfer == value)
173                    return;
174                
175                EnsurePropertyAvailability("CompressedTransfer", GuiClientType.PyQT);
176                _CompressedTransfer = value;
177            }
178        }
179
180        /// <summary>
181        /// Gets or sets the revision to include in the clone. If <c>null</c>, include every changeset
182        /// from the source repository.
183        /// Default is <c>null</c>.
184        /// </summary>
185        /// <remarks>
186        /// This property is only available for the <see cref="GuiClientType.PyQT"/> client type.
187        /// </remarks>
188        [NullableArgument(NonNullOption = "--rev")]
189        [DefaultValue(null)]
190        public RevSpec IncludeRevision
191        {
192            get
193            {
194                return _IncludeRevision;
195            }
196
197            set
198            {
199                if (_IncludeRevision == value)
200                    return;
201                
202                EnsurePropertyAvailability("IncludeRevision", GuiClientType.PyQT);
203                _IncludeRevision = value;
204            }
205        }
206
207        /// <summary>
208        /// Gets or sets the branch to include in the clone. If empty, include every branch
209        /// from the source repository. Default is empty.
210        /// </summary>
211        /// <remarks>
212        /// This property is only available for the <see cref="GuiClientType.PyQT"/> client type.
213        /// </remarks>
214        [RepeatableArgument(Option = "--branch")]
215        [DefaultValue("")]
216        public string Branch
217        {
218            get
219            {
220                return _Branch;
221            }
222
223            set
224            {
225                if (_Branch == value)
226                    return;
227                
228                EnsurePropertyAvailability("Branch", GuiClientType.PyQT);
229                _Branch = (value ?? string.Empty).Trim();
230            }
231        }
232
233        /// <summary>
234        /// Gets all the arguments to the <see cref="CommandBase{T}.Command"/>, or an
235        /// empty array if there are none.
236        /// </summary>
237        /// <value></value>
238        public override IEnumerable<string> Arguments
239        {
240            get
241            {
242                return base.Arguments.Concat(
243                    new[]
244                    {
245                        "\"" + Source + "\"", ".",
246                    });
247            }
248        }
249
250        /// <summary>
251        /// Sets the <see cref="Source"/> property to the specified value and
252        /// returns this <see cref="CloneGuiCommand"/> instance.
253        /// </summary>
254        /// <param name="value">
255        /// The new value for the <see cref="Source"/> property.
256        /// </param>
257        /// <returns>
258        /// This <see cref="CloneGuiCommand"/> instance.
259        /// </returns>
260        /// <remarks>
261        /// This method is part of the fluent interface.
262        /// </remarks>
263        public CloneGuiCommand WithSource(string value)
264        {
265            Source = value;
266            return this;
267        }
268
269        /// <summary>
270        /// Sets the <see cref="Update"/> property to the specified value and
271        /// returns this <see cref="CloneGuiCommand"/> instance.
272        /// </summary>
273        /// <param name="value">
274        /// The new value for the <see cref="Update"/> property.
275        /// </param>
276        /// <returns>
277        /// This <see cref="CloneGuiCommand"/> instance.
278        /// </returns>
279        /// <remarks>
280        /// This method is part of the fluent interface.
281        /// </remarks>
282        public CloneGuiCommand WithUpdate(bool value)
283        {
284            Update = value;
285            return this;
286        }
287
288        /// <summary>
289        /// Sets the <see cref="UpdateToRevision"/> property to the specified value and
290        /// returns this <see cref="CloneGuiCommand"/> instance.
291        /// </summary>
292        /// <param name="value">
293        /// The new value for the <see cref="UpdateToRevision"/> property.
294        /// </param>
295        /// <returns>
296        /// This <see cref="CloneGuiCommand"/> instance.
297        /// </returns>
298        /// <remarks>
299        /// This method is part of the fluent interface.
300        /// </remarks>
301        public CloneGuiCommand WithUpdateToRevision(RevSpec value)
302        {
303            UpdateToRevision = value;
304            return this;
305        }
306
307        /// <summary>
308        /// Sets the <see cref="CompressedTransfer"/> property to the specified value and
309        /// returns this <see cref="CloneGuiCommand"/> instance.
310        /// </summary>
311        /// <param name="value">
312        /// The new value for the <see cref="CompressedTransfer"/> property.
313        /// </param>
314        /// <returns>
315        /// This <see cref="CloneGuiCommand"/> instance.
316        /// </returns>
317        /// <remarks>
318        /// This method is part of the fluent interface.
319        /// </remarks>
320        public CloneGuiCommand WithCompressedTransfer(bool value)
321        {
322            CompressedTransfer = value;
323            return this;
324        }
325
326        /// <summary>
327        /// Sets the <see cref="IncludeRevision"/> property to the specified value and
328        /// returns this <see cref="CloneGuiCommand"/> instance.
329        /// </summary>
330        /// <param name="value">
331        /// The new value for the <see cref="IncludeRevision"/> property.
332        /// </param>
333        /// <returns>
334        /// This <see cref="CloneGuiCommand"/> instance.
335        /// </returns>
336        /// <remarks>
337        /// This method is part of the fluent interface.
338        /// </remarks>
339        public CloneGuiCommand WithIncludeRevision(RevSpec value)
340        {
341            IncludeRevision = value;
342            return this;
343        }
344
345        /// <summary>
346        /// Sets the <see cref="Branch"/> property to the specified value and
347        /// returns this <see cref="CloneGuiCommand"/> instance.
348        /// </summary>
349        /// <param name="value">
350        /// The new value for the <see cref="Branch"/> property.
351        /// </param>
352        /// <returns>
353        /// This <see cref="CloneGuiCommand"/> instance.
354        /// </returns>
355        /// <remarks>
356        /// This method is part of the fluent interface.
357        /// </remarks>
358        public CloneGuiCommand WithBranch(string value)
359        {
360            Branch = value;
361            return this;
362        }
363
364        /// <summary>
365        /// Validates the command configuration. This method should throw the necessary
366        /// exceptions to signal missing or incorrect configuration (like attempting to
367        /// add files to the repository without specifying which files to add.)
368        /// </summary>
369        /// <exception cref="InvalidOperationException">
370        /// The 'clone' command requires <see cref="Source"/> to be specified.
371        /// </exception>
372        public override void Validate()
373        {
374            base.Validate();
375
376            if (StringEx.IsNullOrWhiteSpace(Source))
377                throw new InvalidOperationException("The 'clone' command requires Source to be specified");
378        }
379    }
380}