using (var repo = new Repository(path))
{
//git archive
Commit cm = repo.Lookup<Commit>(hashCode);
String tarpath = outputDir + "\\" + projectName;
String untarpath = outputDir + "\\" + projectName + "\\" + hashCode;
string tarfile = outputDir + "\\" + projectName + "\\" + hashCode+ ".zip";
String tarname = hashCode + ".zip";
if (!Directory.Exists(untarpath))
{
//创建
Directory.CreateDirectory(untarpath);
}
repo.ObjectDatabase.Archive(cm, tarfile);
UnRAR(untarpath, tarpath, tarname);
}
/// <summary>
/// 利用 WinRAR 进行解压缩
/// </summary>
/// <param name="path">文件解压路径(绝对)</param>
/// <param name="rarPath">将要解压缩的 .rar 文件的存放目录(绝对路径)</param>
/// <param name="rarName">将要解压缩的 .rar 文件名(包括后缀)</param>
public void UnRAR(string path, string rarPath, string rarName)
{
ProcessStartInfo startinfo = new ProcessStartInfo(); ;
Process process = new Process();
String rarexe = @"F:\WinRAR\WinRAR.exe"; //WinRAR安装位置
//解压缩命令,相当于在要压缩文件(rarName)上点右键->WinRAR->解压到当前文件夹
String cmd = string.Format("x {0} {1} -y",rarName,path);
startinfo.FileName = rarexe;
startinfo.Arguments = cmd;
startinfo.WindowStyle = ProcessWindowStyle.Hidden;
startinfo.WorkingDirectory = rarPath;
process.StartInfo = startinfo;
process.Start();
process.WaitForExit();
process.Dispose();
process.Close();
}
c#用LibGit2Sharp实现git archive
最新推荐文章于 2024-08-10 07:05:31 发布