我可以编辑使用CheckoutPaths检索的文件并推送到远程分支吗?

时间:2016-01-26 23:38:44

标签: libgit2sharp

没有完整的分支克隆。

是否可以:

  • 使用CheckoutPaths从远程回购中检索文件到本地回购
  • 编辑文件并在本地分支中提交。
  • 将提交推送到远程仓库?

下面的代码提交,但我无法找到推送方式。

string result = Repository.Init(fullLocalPath);

using (var repo = new Repository(result))
{
    Remote remote = repo.Network.Remotes.Add("origin", url);

    //fetch remote
    FetchOptions fo = new FetchOptions { CredentialsProvider = (_url, _usernameFromUrl, _cred)
            => gitUserCred};
    repo.Fetch(remote.Name, fo);

    //reference fetched tracked branch.
    Branch trackedBranch = repo.Branches[trackedBranchName];

    //create a local branch
    var localBranch = repo.CreateBranch(testBranchName, trackedBranch.Tip);

    //map local to tracked.
    repo.Branches.Update(localBranch,
                    b => b.Remote = remote.Name,
                    b => b.UpstreamBranch = localBranch.CanonicalName);

    //switch to local branch
    CheckoutOptions co = new CheckoutOptions { CheckoutModifiers= CheckoutModifiers.Force };
    repo.CheckoutPaths(localBranch.Name, fileList.AsEnumerable<string>(), co);

    foreach (string file in fileList)
    {
        //change files here.
        //then stage
        repo.Stage(localFileFull);
    }

    Commit c =  repo.Commit("Persisting the files locally");

    //commit
    PushOptions po = new PushOptions();
    var pushRefSpec = $"{c.Sha}:refs/heads/master";
    po.CredentialsProvider = (_url, _usernameFromUrl, _cred) => gitUserCred;
    repo.Network.Push(remote, c.Sha, pushRefSpec, po, testSignature, "partial push");
}

0 个答案:

没有答案