Example #1
0
        /// <summary>
        /// 比较给定的两个文件,生成patch文件,并应用Patch文件
        /// <remarks>
        /// Patch采用git apply命令实现。
        /// </remarks>
        /// </summary>
        /// <param name="baseText"></param>
        /// <param name="modifiedText"></param>
        public static int ApplyPatch(string baseFile, string modifiedFile)
        {
            var resultFileName = GenerateUniqueTextFileName();
            var patchFile      = string.Format("{0}{1}", BaseFilePath, resultFileName);

            GitUtil.DiffFile(baseFile, modifiedFile, patchFile);
            return(GitUtil.ApplyPatch(patchFile));
        }
Example #2
0
        /// <summary>
        /// 比较给定的两串文本,返回比较结果。
        /// <remarks>
        /// 比较算法采用git diff命令实现。
        /// </remarks>
        /// </summary>
        /// <param name="text1"></param>
        /// <param name="text2"></param>
        public static string DiffText(string text1, string text2)
        {
            var file1          = SaveTextToFile(text1);
            var file2          = SaveTextToFile(text2);
            var resultFileName = GenerateUniqueTextFileName();
            var resultFile     = string.Format("{0}{1}", BaseFilePath, resultFileName);
            var resultCode     = GitUtil.DiffFile(file1, file2, resultFile);

            return(GetFileContent(resultFileName, false));
        }