PageRenderTime 80ms CodeModel.GetById 62ms app.highlight 11ms RepoModel.GetById 3ms app.codeStats 0ms

/Mercurial.Net/RemoteInitCommand.cs

#
C# | 215 lines | 98 code | 19 blank | 98 comment | 3 complexity | ac103afcf361a7303e973f64f06c0cf0 MD5 | raw file
  1using System;
  2using System.ComponentModel;
  3using Mercurial.Attributes;
  4
  5namespace Mercurial
  6{
  7    /// <summary>
  8    /// This class implements the "hg init" command (<see href="http://www.selenic.com/mercurial/hg.1.html#init"/>):
  9    /// create a new repository at the given remote location.
 10    /// </summary>
 11    public sealed class RemoteInitCommand : MercurialCommandBase<RemoteInitCommand>
 12    {
 13        /// <summary>
 14        /// This is the backing field for the <see cref="SshCommand"/> property.
 15        /// </summary>
 16        private string _SshCommand = string.Empty;
 17
 18        /// <summary>
 19        /// This is the backing field for the <see cref="RemoteCommand"/> property.
 20        /// </summary>
 21        private string _RemoteCommand = string.Empty;
 22
 23        /// <summary>
 24        /// This is the backing field for the <see cref="VerifyServerCertificate"/> property.
 25        /// </summary>
 26        private bool _VerifyServerCertificate = true;
 27
 28        /// <summary>
 29        /// This is the backing field for the <see cref="Location"/> property.
 30        /// </summary>
 31        private string _Location = string.Empty;
 32
 33        /// <summary>
 34        /// Initializes a new instance of the <see cref="RemoteInitCommand"/> class.
 35        /// </summary>
 36        public RemoteInitCommand()
 37            : base("init")
 38        {
 39            // Do nothing here
 40        }
 41
 42        /// <summary>
 43        /// Gets or sets the ssh command to use when cloning.
 44        /// Default is <see cref="string.Empty"/>.
 45        /// </summary>
 46        [NullableArgument(NonNullOption = "--ssh")]
 47        [DefaultValue("")]
 48        public string SshCommand
 49        {
 50            get
 51            {
 52                return _SshCommand;
 53            }
 54
 55            set
 56            {
 57                _SshCommand = (value ?? string.Empty).Trim();
 58            }
 59        }
 60
 61        /// <summary>
 62        /// Gets or sets the hg command to run on the remote side.
 63        /// Default is <see cref="string.Empty"/>.
 64        /// </summary>
 65        [NullableArgument(NonNullOption = "--remotecmd")]
 66        [DefaultValue("")]
 67        public string RemoteCommand
 68        {
 69            get
 70            {
 71                return _RemoteCommand;
 72            }
 73
 74            set
 75            {
 76                _RemoteCommand = (value ?? string.Empty).Trim();
 77            }
 78        }
 79
 80        /// <summary>
 81        /// Gets or sets a value indicating whether to verify the server certificate. If set to <c>false</c>, will ignore web.cacerts configuration.
 82        /// Default value is <c>true</c>.
 83        /// </summary>
 84        [BooleanArgument(FalseOption = "--insecure")]
 85        [DefaultValue(true)]
 86        public bool VerifyServerCertificate
 87        {
 88            get
 89            {
 90                return _VerifyServerCertificate;
 91            }
 92
 93            set
 94            {
 95                RequiresVersion(new Version(1, 7, 5), "VerifyServerCertificate property of the PullCommand class");
 96                _VerifyServerCertificate = value;
 97            }
 98        }
 99
100        /// <summary>
101        /// Gets or sets the Url of the remote location to initialize a repository.
102        /// Default value is <see cref="string.Empty"/>.
103        /// </summary>
104        [NullableArgument]
105        [DefaultValue("")]
106        public string Location
107        {
108            get
109            {
110                return _Location;
111            }
112
113            set
114            {
115                _Location = (value ?? string.Empty).Trim();
116            }
117        }
118
119        /// <summary>
120        /// Sets the <see cref="SshCommand"/> property to the specified value and
121        /// returns this <see cref="RemoteInitCommand"/> instance.
122        /// </summary>
123        /// <param name="value">
124        /// The new value for the <see cref="SshCommand"/> property.
125        /// </param>
126        /// <returns>
127        /// This <see cref="RemoteInitCommand"/> instance.
128        /// </returns>
129        /// <remarks>
130        /// This method is part of the fluent interface.
131        /// </remarks>
132        public RemoteInitCommand WithSshCommand(string value)
133        {
134            SshCommand = value;
135            return this;
136        }
137
138        /// <summary>
139        /// Sets the <see cref="RemoteCommand"/> property to the specified value and
140        /// returns this <see cref="RemoteInitCommand"/> instance.
141        /// </summary>
142        /// <param name="value">
143        /// The new value for the <see cref="RemoteCommand"/> property.
144        /// </param>
145        /// <returns>
146        /// This <see cref="RemoteInitCommand"/> instance.
147        /// </returns>
148        /// <remarks>
149        /// This method is part of the fluent interface.
150        /// </remarks>
151        public RemoteInitCommand WithRemoteCommand(string value)
152        {
153            RemoteCommand = value;
154            return this;
155        }
156
157        /// <summary>
158        /// Sets the <see cref="VerifyServerCertificate"/> property to the specified value and
159        /// returns this <see cref="RemoteInitCommand"/> instance.
160        /// </summary>
161        /// <param name="value">
162        /// The new value for the <see cref="VerifyServerCertificate"/> property.
163        /// </param>
164        /// <returns>
165        /// This <see cref="RemoteInitCommand"/> instance.
166        /// </returns>
167        /// <remarks>
168        /// This method is part of the fluent interface.
169        /// </remarks>
170        public RemoteInitCommand WithVerifyServerCertificate(bool value)
171        {
172            VerifyServerCertificate = value;
173            return this;
174        }
175
176        /// <summary>
177        /// Sets the <see cref="VerifyServerCertificate"/> property to the specified value and
178        /// returns this <see cref="RemoteInitCommand"/> instance.
179        /// </summary>
180        /// <param name="value">
181        /// The new value for the <see cref="VerifyServerCertificate"/> property.
182        /// </param>
183        /// <returns>
184        /// This <see cref="RemoteInitCommand"/> instance.
185        /// </returns>
186        /// <remarks>
187        /// This method is part of the fluent interface.
188        /// </remarks>
189        public RemoteInitCommand WithLocation(string value)
190        {
191            Location = value;
192            return this;
193        }
194
195        /// <summary>
196        /// Validates the command configuration. This method should throw the necessary
197        /// exceptions to signal missing or incorrect configuration (like attempting to
198        /// add files to the repository without specifying which files to add.)
199        /// </summary>
200        /// <exception cref="InvalidOperationException">
201        /// <para>The <see cref="VerifyServerCertificate"/> command was used with Mercurial 1.7.4 or older.</para>
202        /// <para>- or -</para>
203        /// <para>The <see cref="Location"/> property was blank.</para>
204        /// </exception>
205        public override void Validate()
206        {
207            base.Validate();
208
209            if (StringEx.IsNullOrWhiteSpace(Location))
210                throw new InvalidOperationException("The Location property must be set before executing a RemoteInitCommand");
211            if (!VerifyServerCertificate && ClientExecutable.CurrentVersion < new Version(1, 7, 5))
212                throw new InvalidOperationException("The 'VerifyServerCertificate' property is only available in Mercurial 1.7.5 and newer");
213        }
214    }
215}