【发布时间】:2019-04-29 00:19:57
【问题描述】:
我有一个 GIT 存储库说“https://github.com/Myname_XXXX/TestGit”。我需要遍历这个存储库的所有提交并获取某些信息,例如提交作者、id、消息等。我使用下面的代码 sn-p 并且它工作正常。
string repoPath = "https://github.com/Myname_XXXX/TestGit";
GitRepositoryManager objTest = new GitRepositoryManager("Userid", "Pwd", repoPath, @"C:\ClonedFolder");
string path = Repository.Clone(objTest._repoSource, objTest._localFolder.ToString());
using (var repo = new Repository(path))
{
int i = 1;
foreach (var Commit in repo.Commits)
{
Console.WriteLine("");
Console.WriteLine("Number : {0}", i);
Console.WriteLine("Author: {0}", Commit.Author.Name);
Console.WriteLine("Message: {0}", Commit.MessageShort);
Console.WriteLine("Commit Id: {0}", Commit.Id.ToString());
Console.WriteLine("Commit Date: {0}", Commit.Author.When.DateTime);
Console.WriteLine("Author Email: {0}", Commit.Committer.ToString());
i = i + 1;
}
Console.WriteLine("Total Commits: {0}", i - 1);
Console.ReadLine();
}
}
}
class GitRepositoryManager
{
public readonly string _repoSource;
public readonly UsernamePasswordCredentials _credentials;
public readonly DirectoryInfo _localFolder;
public GitRepositoryManager(string username, string password, string gitRepoUrl, string localFolder)
{
var folder = new DirectoryInfo(localFolder);
if (!folder.Exists)
{
throw new Exception(string.Format("Source folder '{0}' does not exist.", _localFolder));
}
_localFolder = folder;
_credentials = new UsernamePasswordCredentials
{
Username = username,
Password = password
};
_repoSource = gitRepoUrl;
}
}
我的第一个问题是:
有没有一种简单的方法可以通过提供 GIT 登录凭据(没有克隆-->使用 Repository.Clone())连接到 GIT 存储库:正如我所使用的 在上面的代码(sn-p)中,并在不克隆的情况下遍历存储库的所有提交,因为当我们拥有庞大的代码库时会产生问题
相同的概念是否适用于 Atlassian 存储(因为它也基于 GIT 概念)
【问题讨论】:
标签: git atlassian-sourcetree libgit2sharp