【发布时间】:2021-02-21 04:08:28
【问题描述】:
我正在 Visual Studio 中使用 Windows Forms C# 开发(非常新)一个应用程序,我需要从 GitLab 项目中获得特定的提交。
我看过很多关于 GitHub 的例子。我试过这种方式(不知道是否正确):
使用 7 位 SHA1 在特定提交处下载存储库:
var Token = "xxxx";
var url = "http://{my_domain}/{user}/{project_name}/repository/archive/{shor_id}.zip";
var path = @"C:\GitLab\My_Projects";
try
{
using (var client = new System.Net.Http.HttpClient())
{
var credentials = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:", Token);
credentials = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(credentials));
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", credentials);
var contents = client.GetByteArrayAsync(url).Result;
System.IO.File.WriteAllBytes(path, contents);
}
}
catch (System.UnauthorizedAccessException)
{
backgroundWorker1.CancelAsync();
Console.WriteLine("Problem downloading");
}
但我收到此错误:
'System.UnauthorizedAccessException' in mscorlib.dll. Access denied to 'C:\GitLab\My_Projects'.
正如我之前所说,我是新手,可能说了一些愚蠢的话,提前抱歉。 如果有人知道这个主题,我很乐意解释或帮助我了解这个概念。
【问题讨论】:
-
Access denied to 'C:\GitLab\My_Projects'显然是 local 权限问题,与 GitHub 或 GitLab 无关。 -
迂腐:你没有下载提交;您正在下载存储库的存档 at 特定提交。此外,尝试“克隆”提交也没有任何意义。您克隆了一个包含大量提交的项目。
-
是的,我知道我正在获取某个提交的存储库,如果我克隆,我将获得所有包含所有提交的项目。
-
对不起,我想你不明白,因为你编的这个网址是无效的,甚至概念也不合逻辑:
$"http://{my_domain}/{user}/{project_name}/{short_id_commit}.git -
您知道如何解决权限问题吗?我正在使用令牌,但我不明白为什么会出现访问问题。
标签: c# .net gitlab commit windows-forms-designer