SVN Server Hook(Unity Meta File)

项目中老是有人漏提交meta文件,这里通过使用svn的hook强制提交meta文件,具体hook怎么写自行百度。这里提供一个笨但是有用的方法

具体过程:编写pre-commit  >> 存放到对应svn服务器仓库中 >> 使用

编写pre-commit

由于我们的服务器是windows下的,所以我这里使用了最简单的.exe进行编写hook文件,内容如下 

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
/// <summary>
/// svn unity meta记录
/// </summary>
namespace pre_commit
{
    class Program
    {
        private static int Main(string[] args)
        {
            string transactionId = args[1];
            string repository_path = args[0];
            bool validateMeta = true;
            //验证日志
            using (var process = new Process())
            {
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.FileName = @"C:\Program Files\VisualSVN Server\bin\svnlook.exe";
                process.StartInfo.Arguments = string.Format("log -t {0} \"{1}\"", transactionId, repository_path);
                process.Start();
                string content = process.StandardOutput.ReadToEnd();
                //强制写标记可以放你一马
                if (content.StartsWith("[meta]")) validateMeta = false;
                if (content.Length < 10)
                {
                    Console.Error.WriteLine("提示:日志数量不足");
                    return 1;
                }
                process.WaitForExit();
            }
            //验证meta
            if (validateMeta)
            {
                using (var process = new Process())
                {
                    process.StartInfo.UseShellExecute = false;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.FileName = @"C:\Program Files\VisualSVN Server\bin\svnlook.exe";
                    process.StartInfo.Arguments = string.Format("changed -t {0} \"{1}\"", transactionId, repository_path);
                    process.Start();
                    string content = process.StandardOutput.ReadToEnd();
                    string[] lines = content.Split('\n');
                    List<string> sourceList = new List<string>();
                    List<string> metaList = new List<string>();
                    foreach (var v in lines)
                    {
                        if (v.Length <= 0) continue;
                        //只看新增和删除的
                        if (v.StartsWith("D") || v.StartsWith("A"))
                        {
                            string str = Regex.Replace(v, @"\s", "");
                            if (str.Contains(".meta"))
                            {
                                Console.Error.WriteLine("meta: " + str);
                                metaList.Add(str);
                            }
                            else
                            {
                                Console.Error.WriteLine("source: " + str);
                                sourceList.Add(str);
                            }
                        }
                    }
                    int len = sourceList.Count;
                    for (int i= len-1; i>=0; i--)
                    {
                        string metaFileName = sourceList[i] + ".meta";
                        if (!metaList.Contains(metaFileName))
                        {
                            Console.Error.WriteLine("提示:Meta文件不匹配; " + sourceList[i]);
                            return 1;
                        }
                    }
                    process.WaitForExit();
                }
            }
            return 0;
        }
    }
}

提供功能:

  1. 判断日志的长度
  2. 提交的新增文件删除文件是否meta文件和源文件匹配问题
  3. 使用[meta]标签进行忽略meta校验

存放:

将以上文件生成为可执行文件,然后放到服务器仓库的Hooks文件夹子下即可生效

使用:

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值