C#调用SVN

尊重原创,转载请在文首注明出处:http://blog.csdn.net/cai612781/article/details/79015085

一,语法

项目开发中通常都会使用Subversion(SVN)作为版本控制系统,同时会使用SVN的客户端软件TortoiseSVN。

我们通过TortoiseSVN的TortoiseProc.exe程序添加参数,来实现在C#或bat批处理脚本中调用SVN。
举个栗子: TortoiseProc.exe /command:update /path:xxx /closeonend:0

/command表示SVN的操作命令

/path表示操作的路径,可以有多个,用*分隔

/closeonend用于在执行完毕后关闭对话框:

/closeonend:0不自动关闭对话框

/closeonend:1没有错误,则自动关闭对话框

/closeonend:2没有错误、冲突,则自动关闭对话框

/closeonend:3没有错误、冲突、合并,自动关闭对话框

 

二,代码

 

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UnityEditor;

namespace Assets.Editor.Svn
{
    public class SvnUtil : UnityEditor.Editor
    {
        private static string _svnPath = "";

        public static void DelAndUpdateSvnFile(string path)
        {
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            ExecuteProcess(GetSvnProcPath(), string.Format("/command:update /path:{0} /closeonend:2", path));
        }

        public static void RevertAndUpdateSvnDirectory(string path)
        {
            ExecuteProcess(GetSvnProcPath(), string.Format("/command:revert -r /path:{0} /closeonend:2", path));
            ExecuteProcess(GetSvnProcPath(), string.Format("/command:update /path:{0} /closeonend:2", path));
        }

        public static void UpdateSvnDirectory(string path)
        {
            ExecuteProcess(GetSvnProcPath(), string.Format("/command:update /path:{0} /closeonend:2", path));
        }

        public static void CommitSvnDirectory(string path)
        {
            ExecuteProcess(GetSvnProcPath(), string.Format("/command:commit /path:{0} /closeonend:0", path));
        }

        public static void ProcessSvnCommand(string command)
        {
            ExecuteProcess(GetSvnProcPath(), command);
        }

        private static List<string> drives = new List<string>() { "c:", "d:", "e:", "f:"};

        private static string svnPath = @"\Program Files\TortoiseSVN\bin\";
        private static string svnProc = @"TortoiseProc.exe";
        private static string svnProcPath = "";

        private static string GetSvnProcPath()
        {
            if (_svnPath != string.Empty)
            {
                return _svnPath;
            }
            foreach (string item in drives)
            {
                string path = string.Concat(item, svnPath, svnProc);
                if (File.Exists(path))
                {
                    _svnPath = path;
                    break;
                }
            }
            if (_svnPath == string.Empty)
            {
                _svnPath = EditorUtility.OpenFilePanel("Select TortoiseProc.exe", "c:\\", "exe");
            }
			//可将路径存到本地注册表
            return _svnPath;
        }

        private static void ExecuteProcess(string filePath, string command, int seconds = 0)
        {
            EditorUtil.ExecuteProcess(filePath, command, "", seconds);//参见文末另一篇:C#调用可执行文件
        }
    }
}

EditorUtil.ExecuteProcess 参见另一篇:C#调用可执行文件

 

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值