/GitSharp/Remote.cs

http://github.com/henon/GitSharp · C# · 293 lines · 128 code · 32 blank · 133 comment · 0 complexity · ea978fa571ad1b92d56ce423fc1425fa MD5 · raw file

  1. //
  2. // Remote.cs
  3. //
  4. // Author:
  5. // Lluis Sanchez Gual <lluis@novell.com>
  6. //
  7. // Copyright (c) 2010 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. using System;
  27. using System.Collections.Generic;
  28. using GitSharp.Core.Transport;
  29. using System.Collections;
  30. namespace GitSharp
  31. {
  32. public class Remote
  33. {
  34. RemoteConfig _config;
  35. Repository _repo;
  36. internal Remote (Repository repo, RemoteConfig config)
  37. {
  38. _config = config;
  39. _repo = repo;
  40. }
  41. public void Update ()
  42. {
  43. _config.Update (_repo._internal_repo.Config);
  44. _repo.Config.Persist ();
  45. }
  46. internal void Delete ()
  47. {
  48. _config.Delete (_repo._internal_repo.Config);
  49. _repo.Config.Persist ();
  50. }
  51. /// <summary>
  52. /// local name this remote configuration is recognized as
  53. /// </summary>
  54. public string Name {
  55. get { return _config.Name; }
  56. set { _config.Name = value; }
  57. }
  58. /// <summary>
  59. /// all configured URIs under this remote
  60. /// </summary>
  61. public IEnumerable<URIish> URIs {
  62. get { return _config.URIs; }
  63. }
  64. /// <summary>
  65. /// all configured push-only URIs under this remote.
  66. /// </summary>
  67. public IEnumerable<URIish> PushURIs {
  68. get { return _config.PushURIs; }
  69. }
  70. /// <summary>
  71. /// Remembered specifications for fetching from a repository.
  72. /// </summary>
  73. public IEnumerable<RefSpec> Fetch {
  74. get { return _config.Fetch; }
  75. }
  76. /// <summary>
  77. /// Remembered specifications for pushing to a repository.
  78. /// </summary>
  79. public IEnumerable<RefSpec> Push {
  80. get { return _config.Push; }
  81. }
  82. /// <summary>
  83. /// Override for the location of 'git-upload-pack' on the remote system.
  84. /// <para/>
  85. /// This value is only useful for an SSH style connection, where Git is
  86. /// asking the remote system to execute a program that provides the necessary
  87. /// network protocol.
  88. /// <para/>
  89. /// returns location of 'git-upload-pack' on the remote system. If no
  90. /// location has been configured the default of 'git-upload-pack' is
  91. /// returned instead.
  92. /// </summary>
  93. public string UploadPack {
  94. get { return _config.UploadPack; }
  95. }
  96. /// <summary>
  97. /// Override for the location of 'git-receive-pack' on the remote system.
  98. /// <para/>
  99. /// This value is only useful for an SSH style connection, where Git is
  100. /// asking the remote system to execute a program that provides the necessary
  101. /// network protocol.
  102. /// <para/>
  103. /// returns location of 'git-receive-pack' on the remote system. If no
  104. /// location has been configured the default of 'git-receive-pack' is
  105. /// returned instead.
  106. /// </summary>
  107. public string ReceivePack {
  108. get { return _config.ReceivePack; }
  109. }
  110. /// <summary>
  111. /// Get the description of how annotated tags should be treated during fetch.
  112. /// <para/>
  113. /// returns option indicating the behavior of annotated tags in fetch.
  114. /// </summary>
  115. public TagOpt TagOpt {
  116. get { return _config.TagOpt; }
  117. set { _config.SetTagOpt (value); }
  118. }
  119. /// <summary>
  120. /// mirror flag to automatically delete remote refs.
  121. /// <para/>
  122. /// true if pushing to the remote automatically deletes remote refs
  123. /// </summary>
  124. public bool Mirror {
  125. get { return _config.Mirror; }
  126. }
  127. /// <summary>
  128. /// timeout before willing to abort an IO call.
  129. /// <para/>
  130. /// number of seconds to wait (with no data transfer occurring)
  131. /// before aborting an IO read or write operation with this
  132. /// remote. A timeout of 0 will block indefinitely.
  133. /// </summary>
  134. public int Timeout {
  135. get { return _config.Timeout; }
  136. set { _config.Timeout = value; }
  137. }
  138. /// <summary>
  139. /// Add a new URI to the end of the list of URIs.
  140. /// </summary>
  141. /// <param name="toAdd">the new URI to add to this remote.</param>
  142. /// <returns>true if the URI was added; false if it already exists.</returns>
  143. public bool AddURI(URIish toAdd)
  144. {
  145. return _config.AddURI (toAdd);
  146. }
  147. /// <summary>
  148. /// Remove a URI from the list of URIs.
  149. /// </summary>
  150. /// <param name="toRemove">the URI to remove from this remote.</param>
  151. /// <returns>true if the URI was added; false if it already exists.</returns>
  152. public bool RemoveURI(URIish toRemove)
  153. {
  154. return _config.RemoveURI (toRemove);
  155. }
  156. /// <summary>
  157. /// Add a new push-only URI to the end of the list of URIs.
  158. /// </summary>
  159. /// <param name="toAdd">the new URI to add to this remote.</param>
  160. /// <returns>true if the URI was added; false if it already exists.</returns>
  161. public bool AddPushURI(URIish toAdd)
  162. {
  163. return _config.AddPushURI (toAdd);
  164. }
  165. /// <summary>
  166. /// Remove a push-only URI from the list of URIs.
  167. /// </summary>
  168. /// <param name="toRemove">the URI to remove from this remote.</param>
  169. /// <returns>true if the URI was added; false if it already exists.</returns>
  170. public bool RemovePushURI(URIish toRemove)
  171. {
  172. return _config.RemovePushURI (toRemove);
  173. }
  174. /// <summary>
  175. /// Add a new fetch RefSpec to this remote.
  176. /// </summary>
  177. /// <param name="s">the new specification to add.</param>
  178. /// <returns>true if the specification was added; false if it already exists.</returns>
  179. public bool AddFetchRefSpec(RefSpec s)
  180. {
  181. return _config.AddFetchRefSpec (s);
  182. }
  183. /// <summary>
  184. /// Override existing fetch specifications with new ones.
  185. /// </summary>
  186. /// <param name="specs">
  187. /// list of fetch specifications to set. List is copied, it can be
  188. /// modified after this call.
  189. /// </param>
  190. public void SetFetchRefSpecs(List<RefSpec> specs)
  191. {
  192. _config.SetFetchRefSpecs(specs);
  193. }
  194. /// <summary>
  195. /// Override existing push specifications with new ones.
  196. /// </summary>
  197. /// <param name="specs">
  198. /// list of push specifications to set. List is copied, it can be
  199. /// modified after this call.
  200. /// </param>
  201. public void SetPushRefSpecs(List<RefSpec> specs)
  202. {
  203. _config.SetPushRefSpecs(specs);
  204. }
  205. /// <summary>
  206. /// Remove a fetch RefSpec from this remote.
  207. /// </summary>
  208. /// <param name="s">the specification to remove.</param>
  209. /// <returns>true if the specification existed and was removed.</returns>
  210. public bool RemoveFetchRefSpec(RefSpec s)
  211. {
  212. return _config.RemoveFetchRefSpec(s);
  213. }
  214. /// <summary>
  215. /// Add a new push RefSpec to this remote.
  216. /// </summary>
  217. /// <param name="s">the new specification to add.</param>
  218. /// <returns>true if the specification was added; false if it already exists.</returns>
  219. public bool AddPushRefSpec(RefSpec s)
  220. {
  221. return _config.AddPushRefSpec(s);
  222. }
  223. /// <summary>
  224. /// Remove a push RefSpec from this remote.
  225. /// </summary>
  226. /// <param name="s">the specification to remove.</param>
  227. /// <returns>true if the specification existed and was removed.</returns>
  228. public bool RemovePushRefSpec(RefSpec s)
  229. {
  230. return _config.RemovePushRefSpec(s);
  231. }
  232. }
  233. public class RemoteCollection: IEnumerable<Remote>
  234. {
  235. Repository _repo;
  236. internal RemoteCollection (Repository repo)
  237. {
  238. _repo = repo;
  239. }
  240. public IEnumerator<Remote> GetEnumerator ()
  241. {
  242. foreach (RemoteConfig rc in RemoteConfig.GetAllRemoteConfigs (_repo._internal_repo.Config))
  243. yield return new Remote (_repo, rc);
  244. }
  245. public Remote CreateRemote (string name)
  246. {
  247. RemoteConfig rc = new RemoteConfig (_repo._internal_repo.Config, name);
  248. _repo.Config.Persist ();
  249. return new Remote (_repo, rc);
  250. }
  251. public void Remove (Remote remote)
  252. {
  253. remote.Delete ();
  254. _repo.Config.Persist ();
  255. }
  256. IEnumerator IEnumerable.GetEnumerator ()
  257. {
  258. return GetEnumerator ();
  259. }
  260. }
  261. }