PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Mercurial.Net/Gui/CloneGuiCommand.cs

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