c# - 带有 C# 和位桶的自动 git 克隆脚本
问题描述
我正在尝试编写一个可以从 bitbucket auto-magic-ally 克隆许多 git 存储库的 C# 程序。
我目前在使用此代码的 ssh 连接部分时遇到问题,并不断收到以下错误:
Cloning into 'reponame'...
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我正在使用System.Diagnostics.Process
C# 来尝试实现这一目标。在 Windows 的 gitbash 安装的众多 shell 中,我不确定使用哪个 shell。下面是给我带来麻烦的代码块。
/// <summary>
/// Takes tokens and execute git cloning process for each token automatically..
/// </summary>
/// <param name="tokens"></param>
private static void GitCloneProcessExecutor(string[] tokens)
{
#region Creating a process for git cloning
foreach (string repoNameToken in tokens)
{
string workingDirectory = @"C:\path\to\working\directory";
string repoName = FormatTokens(repoNameToken); //Reformats tokens from a csv and gets rid of the commas
var gitCloneCommand = $"git clone git@bitbucket.org:username/{repoName}.git";
var gitCloneProcess = new Process { EnableRaisingEvents = true };
var gitCloneProcessStartInfo = new ProcessStartInfo
{
WorkingDirectory = workingDirectory,
FileName = @"C:\Program Files\Git\bin\bash.exe",
Verb = "runas",
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
CreateNoWindow = false,
WindowStyle = ProcessWindowStyle.Normal,
};
gitCloneProcess.StartInfo = gitCloneProcessStartInfo;
gitCloneProcess.Start();
using (var so = gitCloneProcess.StandardOutput)
{
using (var si = gitCloneProcess.StandardInput)
{
string newDirectory = "GitRepositories";
si.WriteLine($"cd {BashFormatDirectory(workingDirectory)}"); //Reformats working driectory from cmd readable format to bash friendly format.
si.WriteLine($"mkdir {newDirectory}");
si.WriteLine($"cd {newDirectory}");
si.WriteLine($"{gitCloneCommand} -v --progress");
}
}
}
#endregion
}
解决方案
推荐阅读
- java - 如何将适配器附加到 RecyclerView
- javascript - 将标题字段与数组进行比较时避免错误
- netlogo - NetLogo:让乌龟记住它的起始位置
- web-scraping - 如何不重试 Scrapy 请求?
- python - Python语音识别器将系统扬声器语音作为输入而不是麦克风怎么办?
- r - 使用 rselenium 和 rvest 通过 while 循环从多个表中跨多个页面提取数据
- php - Ajax 调用返回当前页面整页 HTML 而不是预期的数据
- php - 在 ACF Image Caption 中添加链接
- c# - Visual Studio 中的数据集
- javascript - 汉森表中的日期格式