0

I'm having a hard time pushing my commits to a remote repository with libgit2sharp. Using the git bash it works fine.

The remote is addressed via UNC like "//computer_name/remote.git". So it's a folder on a machine in the local network which has an accessible folder.

Cloning it to a local repo with libgit2sharp worked just fine and constructing a remote was successful too with

Remote remote = localrepo.Network.Remotes["origin"];

Now when I try pushing to the remote with:

localrepo.Network.Push(remote, "HEAD", "origin");

I get the exception in git_push_add_refspec() in Proxy.cs

An error was raised by libgit2. Category = Invalid (Error).
Not a valid reference 'origin'

So then I tried:

repo.Network.Push(remote, "HEAD", @"refs/remotes/origin/master");

and got the exception in git_push_finish() in Proxy.cs

An error was raised by libgit2. Category = Net (Error).
Remote transport doesn't support push.

Is there a right way to do this or is there a support problem for my usecase? Thanks in advance!

[UPDATE]

Now my command looks like this

repo.Network.Push(remote, "HEAD", @"refs/remote/origin/master", pushStErrHnd, null);

The PushStatusErrorHandler has only one line of code in which it should write the PushErrorStatus to console. But console remains blank and then the above exception occurs.

[UPDATE 2]

The static variable Repository.Version was 0.9.5 when I experienced the above.

Luca
  • 25
  • 5
  • 1
    Which version of LibGit2Sharp are you using? Can you please update your question with the output of `Repository.Version`? – nulltoken Mar 27 '13 at 15:44
  • (Firstly: sorry for late reply, I was abroad for a week) `Version.Repository` was "0.9.5". After updating to recent LibGit2Sharp it shows "0.10.0" and the pushing works as described by jamill in his answer. So I was using a feature under construction it seems, thx for the support! – Luca Apr 08 '13 at 13:06

2 Answers2

2

As nulltoken has already mentioned, local push has just recently been added. You will need to make sure that you have a recent LibGit2Sharp build (you will need LibGit2Sharp containing commit 547a6bd, committed on March 12)

Also, there is a slight mistake in the API usage. The destination reference should be the reference to update on the remote (e.g. @"refs/remote/origin/master" should probably be @"refs/heads/master").

jamill
  • 1,682
  • 13
  • 9
  • (Firstly: sorry for late reply, I was abroad for a week) Thanks, I updated my LibGit2Sharp code and now it works just fine. I'm also using your recommended reference now. Thanks again for the support! – Luca Apr 08 '13 at 13:08
1

Push to a local repository has been recently added to libgit2 (see PR #1406) and eventually embedded in LibGit2Sharp. However, this feature hasn't been properly tested yet.

In order to try and help you, could you please update your questions with the answers to the few questions below:

  • Push accept an additional parameter to give more information about issues: onPushStatusError. Could you please provide the output of each potential PushStatusErrors?
  • You state "Cloning it to a local repo worked". How did you perform the clone? Through git? Through LibGit2Sharp?
  • What happens if you change the url of the remote to a file URI format (eg. file://computer_name/remote.git)?

UPDATE

The amazing @yorah is working on a Pull Request to enhance the test coverage regarding your scenario.

  • Cloning from a local repository
  • Adding a new Commit
  • Pushing the newly created commit
  • Retrieving the list of the remote references
Community
  • 1
  • 1
nulltoken
  • 64,429
  • 20
  • 138
  • 130
  • 1. I wrote a Method which should write the PushStatusErrors to console but the console remains blank and then the exception occurs. Seems like the Push() doesn't reach that point where it triggers the event 'onPushStatusError'. – Luca Mar 27 '13 at 15:07
  • 2. I cloned the repository through libgit2sharp – Luca Mar 27 '13 at 15:14
  • 3. if I add "file:" in front of the remote path it again runs into the exception: "An error was raised by libgit2. Category = Net (Error). Remote transport doesn't support push" – Luca Mar 27 '13 at 15:19