用libgit2sharp推送到bitbucket [英] Pushing to bitbucket with libgit2sharp

查看:153
本文介绍了用libgit2sharp推送到bitbucket的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用libgit2sharp推送到我在bitbucket上的回购。我试图这样做:

  repo.Network.Push(repo.Branches [branchName],pushOptions); 

一切看起来都很好,没有任何异常,并且在回调中没有错误,但是当我检查在bitbucket上我的任何提交都没有。其他方法似乎工作正常(即我可以在bitbucket上创建一个新的分支,然后使用libgit2sharp获取并查看我现在在本地有该分支)。有什么我可能会在这里失踪?



编辑:



试图做一个小的示例程序看看我能不能继续工作。我不知道我的代码是否有帮助,但是在这里:

  class程序
{
static void Main(string [] args)
{
PushOptions options = new PushOptions();
Credentials creds = new Credentials();
creds.Username =username;
creds.Password =密码;
options.Credentials = creds;
options.OnPackBuilderProgress = Program.packBuilderProgressHandler;
options.OnPushTransferProgress = Program.pushTransferProgressHandler;
options.OnPushStatusError = Program.pushStatusErrorHandler;
Repository = new Repository(E:/ Ohad / Work / libgitTest);

repo.Network.Push(repo.Branches [origin / master],options);

Console.WriteLine(按回车关闭...);
Console.ReadLine();
}

public static bool packBuilderProgressHandler(PackBuilderStage stage,int current,int total)
{
Console.Out.WriteLine(packBuilder =>+ current +/+ total);
返回true;

public static bool pushTransferProgressHandler(int current,int total,long bytes)
{
Console.Out.WriteLine(pushTransfer =>+ current +/) + total +,+ bytes);
返回true;

public static void pushStatusErrorHandler(PushStatusError error)
{
Console.Out.WriteLine(error =>+ error.Message);


$ / code>

只要在bitbucket上做一个新的回购并添加上面的代码(改变硬编码的东西),它应该是可重现的。我只是做了一个随机的修改,添加并提交了它,然后使用该程序尝试推送到bitbucket。我从上面得到的输出是:

  pushTransfer => 0/0,12 
pushTransfer => 0/0,32
按回车关闭...

0/0的外观对我很可疑,但我不知道我在做什么错误= /。谢谢你的帮助!!



编辑2:
我刚加了这个:

  repo.Branches.Update(repo.Head,delegate(BranchUpdater updater)
{
updater.Remote =origin;
updater.UpstreamBranch = repo.Head.CanonicalName;
})

到之前我推动并解决了问题。不确定的原因,但我会采取它=)。

解决方案

我认为你愿意推动你的本地 master 分支,而不是远程跟踪分支。

  repo.Network.Push(repo.Branches [master],options); 



更新:




* 您尝试推送的分支master(refs / heads / master)不会跟踪上游分支。 * b


如果您没有origin遥控器,则应如下操作。

  Remote remote = localRepo.Network.Remotes.Add(origin,url); 

repo.Branches.Update(repo.Head, - >(A)
b => b.Remote = remote.Name, - >(B)
b = > b.UpstreamBranch = repo.Head.CanonicalName); - > (C)

上面的代码应该被读为HEAD指向的分支默认情况下,此本地存储库上的(A)将配置为跟踪由此远程标识的远程存储库中的同名分支(C) (B)


I'm trying to use libgit2sharp to push to my repo on bitbucket. I'm trying to do this:

repo.Network.Push(repo.Branches[branchName], pushOptions);

Everything seems fine, no exceptions are thrown and I get no errors in the callback, but when I check on bitbucket none of my commits are there. Other methods seem to work fine (ie I can create a new branch on bitbucket and then use libgit2sharp to fetch and see that I now have that branch locally). Is there anything that I might be missing here?

edit:

Tried to just make a small sample program to see if I can get this working no go. I don't know if my code will help but here it is:

 class Program
{
    static void Main(string[] args)
    {
        PushOptions options = new PushOptions();
        Credentials creds = new Credentials();
        creds.Username = "username";
        creds.Password = "password";
        options.Credentials = creds;
        options.OnPackBuilderProgress = Program.packBuilderProgressHandler;
        options.OnPushTransferProgress = Program.pushTransferProgressHandler;
        options.OnPushStatusError = Program.pushStatusErrorHandler;
        Repository repo = new Repository("E:/Ohad/Work/libgitTest");

        repo.Network.Push(repo.Branches["origin/master"], options);

        Console.WriteLine("Press enter to close...");
        Console.ReadLine();
    }

    public static bool packBuilderProgressHandler(PackBuilderStage stage, int current, int total)
    {
    Console.Out.WriteLine("packBuilder => " + current +  " / " + total);
        return true;
   }
    public static bool pushTransferProgressHandler(int current, int total, long bytes)
    {
    Console.Out.WriteLine("pushTransfer => " + current + " / " + total +  " , " + bytes);
    return true;
    }
    public static void pushStatusErrorHandler(PushStatusError error)
    {
        Console.Out.WriteLine("error => " + error.Message);
    }
}

Just make a new repo on bitbucket and add the above code (changing the stuff thats hard coded) and it should be reproducible. I just made a random change, added and commited it and then used the program to try to push to bitbucket. The output that I am getting from the above is:

pushTransfer => 0 / 0 , 12
pushTransfer => 0 / 0 , 32
Press enter to close...

The 0/0 looks suspicious to me but I don't know what I'm doing wrong =/. Thanks for any help!!

edit 2: I just added this:

 repo.Branches.Update(repo.Head, delegate(BranchUpdater updater)
        {
            updater.Remote = "origin";
            updater.UpstreamBranch= repo.Head.CanonicalName;
        })

to before when I push and it fixed the issue. Not sure exactly why but I'll take it =).

解决方案

I think that you're willing to push your local master branch rather than the remote tracking one.

repo.Network.Push(repo.Branches["master"], options);

Update:

*The branch 'master' ("refs/heads/master") that you are trying to push does not track an upstream branch. *

Provided you have no "origin" remote, the following should work.

Remote remote = localRepo.Network.Remotes.Add("origin", url);

repo.Branches.Update(repo.Head,                              -> (A)
    b => b.Remote = remote.Name,                             -> (B)
    b => b.UpstreamBranch = repo.Head.CanonicalName);        -> (C)

The code above should be read as "The branch pointed at by the HEAD (A) on this local repository will be, by default, configured to track a branch bearing the same name (C) in the distant repository identified by this remote (B)."

这篇关于用libgit2sharp推送到bitbucket的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆