【发布时间】:2021-10-08 02:54:39
【问题描述】:
我目前正在开发一个包含一些 git 子模块的 git repo。我正在尝试编写一个 C# 控制台应用程序来更新子模块指向的提交。
这是我迄今为止尝试过的。
- 使用GitRefUpdate类创建分支
// Create a new branch for PR
GitRefUpdate newBranch = new GitRefUpdate
{
Name = $"refs/heads/{branchName}",
OldObjectId = branchRef.ObjectId,
IsLocked = false,
RepositoryId = _repository.Id
};
- 创建GitItem进行更新
GitItem commitChangeItem = new GitItem()
{
GitObjectType = GitObjectType.Commit,
ObjectId = TargetCommit,
OriginalObjectId = commitItem.ObjectId, //commitItem is the GitItem representing current version of the commit
Path = "path/to/the/commit/file"
};
- 创建一个GitChange 对象
GitChange commitChange = new GitChange()
{
ChangeType = VersionControlChangeType.Edit,
Item = commitChangeItem,
OriginalPath = commitItem.Path
};
- 创建GitCommitRef 和GitPush 对象
var changeCounts = new ChangeCountDictionary();
changeCounts.Add(VersionControlChangeType.Edit, 1);
var commit = new GitCommitRef
{
Comment = commitMessage,
Changes = gitChanges,
ChangeCounts = changeCounts
};
var push = new GitPush
{
RefUpdates = new[] { newBranch },
Commits = new[] { commit },
Repository = _repository,
};
- 使用GitHttpClient对象推送推送对象
pushResult = await _gitHttpClient.CreatePushAsync(push, project:"Project_Name", _repository.Id);
但是,当我按照这些步骤操作时,它告诉我提供给推送的参数无效。error message
有谁知道我需要什么参数来创建这个推送。
谢谢你,祝你有美好的一天!
【问题讨论】:
标签: c# azure asp.net-web-api libgit2sharp