【问题标题】:Updating git submodule through ADO libraries通过 ADO 库更新 git 子模块
【发布时间】:2021-10-08 02:54:39
【问题描述】:

我目前正在开发一个包含一些 git 子模块的 git repo。我正在尝试编写一个 C# 控制台应用程序来更新子模块指向的提交。

这是我迄今为止尝试过的。

  1. 使用GitRefUpdate类创建分支
            // Create a new branch for PR
            GitRefUpdate newBranch = new GitRefUpdate
            {
                Name = $"refs/heads/{branchName}",
                OldObjectId = branchRef.ObjectId,
                IsLocked = false,
                RepositoryId = _repository.Id
            };

  1. 创建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"
            };
  1. 创建一个GitChange 对象
            GitChange commitChange = new GitChange()
            {
                ChangeType = VersionControlChangeType.Edit,
                Item = commitChangeItem,
                OriginalPath = commitItem.Path
            };
  1. 创建GitCommitRefGitPush 对象
            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,
                
            };

  1. 使用GitHttpClient对象推送推送对象
pushResult = await _gitHttpClient.CreatePushAsync(push, project:"Project_Name", _repository.Id);

但是,当我按照这些步骤操作时,它告诉我提供给推送的参数无效。error message

有谁知道我需要什么参数来创建这个推送。

谢谢你,祝你有美好的一天!

【问题讨论】:

    标签: c# azure asp.net-web-api libgit2sharp


    【解决方案1】:

    下面是如何使用 Git Push 子模块的示例代码

    _git push_ [--all | --mirror | --tags] [--follow-tags] [--atomic] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
           [--repo=<repository>] [-f | --force] [-d | --delete] [--prune] [-v | --verbose]
           [-u | --set-upstream] [-o <string> | --push-option=<string>]
           [--[no-]signed|--signed=(true|false|if-asked)]
           [--force-with-lease[=<refname>[:<expect>]] [--force-if-includes]]
           [--no-verify] [<repository> [<refspec>…​]]
    

    如需更多信息,请关注Git Push 文档。 另请查看SO 的相关信息。

    【讨论】:

      猜你喜欢
      • 2012-07-09
      • 1970-01-01
      • 2018-12-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-18
      • 2014-12-08
      • 1970-01-01
      • 2012-04-27
      相关资源
      最近更新 更多