SharpSvn

作者:追风剑情 发布于:2016-8-4 17:33 分类:C#

利用SharpSvn操作SVN

一、下载SharpSvn

https://sharpsvn.open.collab.net/

目标框架
.NET Framework 2.0

测试代码

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Text;
  5. using SharpSvn;
  6. using SharpSvn.Remote;
  7. using SharpSvn.Security;
  8.  
  9. namespace SharpSVNTest
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. SVN.Checkout();
  16. SVN.Update();
  17. SVN.Commit();
  18. SVN.GetStatus();
  19. SVN.TraversalSvnRemoteStat();
  20.  
  21. Console.WriteLine("按任意键退出...");
  22. Console.Read();
  23. }
  24. }
  25.  
  26. public class SVN
  27. {
  28. public static string path = @"https://zwwx-svn/svn/sanguo/branches/res/2015-12-21_res_korea/android_res/resource";
  29.  
  30. public static void Checkout()
  31. {
  32. using (SvnClient client = new SvnClient())
  33. {
  34. client.CheckOut(new Uri(path),
  35. "c:\\sharpsvn");
  36. Console.WriteLine("Checkout Finish!");
  37. }
  38. }
  39.  
  40. public static void Update()
  41. {
  42. using (SvnClient client = new SvnClient())
  43. {
  44. client.Update("c:\\sharpsvn");
  45. Console.WriteLine("Update Finish!");
  46. }
  47. }
  48.  
  49. public static void Commit()
  50. {
  51. using (SvnClient client = new SvnClient())
  52. {
  53. SvnCommitArgs ca = new SvnCommitArgs();
  54. ca.LogMessage = "没做任何修改......";
  55. client.Commit("c:\\sharpsvn", ca);
  56.  
  57. Console.WriteLine("Commit Finish!");
  58. }
  59. }
  60.  
  61. public static void GetStatus()
  62. {
  63. using (SvnClient client = new SvnClient())
  64. {
  65. SvnStatusArgs args = new SvnStatusArgs();
  66. args.Depth = SvnDepth.Empty;
  67. args.RetrieveRemoteStatus = false;
  68. Collection<SvnStatusEventArgs> list = new Collection<SvnStatusEventArgs>();
  69. client.GetStatus(@"c:\\sharpsvn", args, out list);
  70. foreach (SvnStatusEventArgs eventArgs in list)
  71. {
  72. //从eventArgs中获取每个变更文件的相关信息
  73. Console.WriteLine("Path={0}, Revision={1}", eventArgs.Path, eventArgs.Revision);
  74. }
  75. }
  76. }
  77.  
  78. //遍历远程svn目录下的文件(非递归)
  79. public static void TraversalSvnRemoteStat()
  80. {
  81. SvnRemoteSession remoteSession = new SvnRemoteSession(new Uri(path));
  82.  
  83. long rev;
  84. remoteSession.GetLatestRevision(out rev);
  85. Console.WriteLine("LatestRevision=" + rev);
  86.  
  87. remoteSession.List(null,
  88. new EventHandler<SvnRemoteListEventArgs>(
  89. delegate(object s, SvnRemoteListEventArgs e)
  90. {
  91. SvnRemoteSession remote = new SvnRemoteSession(new Uri(path + "/" + e.Name));
  92. SvnRemoteStatEventArgs stat;
  93. remote.GetStat("", out stat);
  94. Console.WriteLine("Name={0}, Revision={1}, FileSize={2}", e.Name, stat.Entry.Revision, stat.Entry.FileSize);
  95. }));
  96. Console.WriteLine("遍历完成!");
  97. }
  98. }
  99. }

 

运行效果

1111111.png

 

标签: C#

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号