当我重命名文件时,我运行GetStatus()
方法,在添加/检出/恢复/重命名后,可以更新文件的状态/等等。当我重命名以前检出的文件时,它将返回NewInIndex而不是RenamedInIndex或RenamedInWorkingDir状态。libgit2sharp:在重命名时返回“NewInIndex”的状态(当重命名为“RenameInIndex”时)
这里是我的方法:
public Tuple<SourceControlStatus, LockStatus> Status(string path)
{
try
{
var existingPath = path;
//finds an existing path so we can still get the status of deleted files (repo.Discover will fail if the path does not exist)
while (!File.Exists(path) && !Directory.Exists(path))
{
existingPath = Path.GetDirectoryName(existingPath);
}
var repoPath = Repository.Discover(path);
using (var repo = new Repository(repoPath))
{
var status = repo.RetrieveStatus(path);
return new Tuple<SourceControlStatus, LockStatus>(GetStatus(status), LockStatus.None);
}
}
catch (Exception ex)
{
}
return new Tuple<SourceControlStatus, LockStatus>(SourceControlStatus.Checkin, LockStatus.None);
}
谁能帮助我明白我需要做的就是它准确地返回正确的状态?或者只是修复,如果该项目返回“NewInIndex”,检查整个回购的状态,然后检查重命名文件的列表,并查看是否有任何匹配的问题。