Скрипт автоматического мерзавца-клона с C # и битовой корзиной - PullRequest
1 голос
/ 10 июля 2019

Я пытаюсь написать программу на C #, которая может клонировать множество репозиториев git из auto-magic-ally bitbucket.

В настоящее время у меня проблемы с подключением по 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 #, чтобы попытаться добиться этого. Я не уверен, какую оболочку использовать из множества установленных с помощью gitbash для Windows. Ниже приведен блок кода, который доставляет мне неприятности.

/// <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
}
...