我试图在SharpSvn的帮助下将文件/目录恢复到特定版本。我目前的方法几乎完美。问题是,当我要求SVN向我提供有关最近恢复的文件的一些信息时,它总是声称它是最新版本。
这是相关的代码:
public override bool Revert(ICollection<string> fileNamesWithPath, long revision = -1)
{
Console.Write("Reverting changes on file {0}... ", GetListOfFilesAsString(fileNamesWithPath));
SvnRevertArgs revertArgs = new SvnRevertArgs()
{
Depth = SvnDepth.Infinity
};
bool result = svnClient.Revert(fileNamesWithPath, revertArgs);
Console.WriteLine(result ? "done" : "failed");
if (result && revision > -1)
{
foreach (string fileNameWithPath in fileNamesWithPath)
{
Console.Write("Reverting changes on file {0} to revision {1}... ", fileNameWithPath, revision);
SvnMergeArgs mergeArgs = new SvnMergeArgs()
{
Depth = SvnDepth.Infinity
};
SvnRevisionRange revisionRange = new SvnRevisionRange(SvnRevision.Head, revision);
result = result && svnClient.Merge(fileNameWithPath, SvnTarget.FromString(fileNameWithPath), revisionRange, mergeArgs);
Console.WriteLine(result ? "done" : "failed");
Console.Write("Resolve any eventually unresolved merge issues by taking 'theirs' on file {0}... ", fileNameWithPath);
SvnResolveArgs resolveArgs = new SvnResolveArgs()
{
Depth = SvnDepth.Infinity
};
result = result && svnClient.Resolve(fileNameWithPath, SvnAccept.TheirsFull, resolveArgs);
Console.WriteLine(result ? "done" : "failed");
}
}
Console.WriteLine();
return result;
}
无论我之后使用GetStatus()
还是GetInfo()
,都会返回最新的修订号。
这种方法有什么问题?
我还尝试使用svnClient.Update()
并指定修订版。但是,如果我尝试提交此文件,它会告诉我“File 'D:\test.svn\1.txt' is out of date
”。所以我想,这不是要走的路。
祝你好运, 卡斯滕