Skip to content
This repository

How to perform a push #104

Closed
nmartin867 opened this Issue January 30, 2012 · 27 comments

9 participants

Nick nulltoken Jonathan Channon Michael Schubert Carlos Martín Nieto Artem Smirnov Jameson Miller Mariana Silva teammixture
Nick

Does this library provide support for push?

nulltoken
Collaborator

It's not implemented yet by libgit2. However, Fetch() should not be that far away :)

Nick

I see. So I can only fetch changes from a remote but I cannot push changes back? Thanks for the info.

nulltoken
Collaborator

I'll keep this issue opened and will update it as soon as Push() is about to land.

Nick nmartin867 closed this January 30, 2012
Nick nmartin867 reopened this January 30, 2012
Jonathan Channon

Thought I was being blind but I guess this is still an issue? I'm assuming the commit therefore should be done on the remote repository server?

nulltoken
Collaborator

@jchannon

Thought I was being blind but I guess this is still an issue?

  • Fetch is available in libgit2. LibGit2Sharp might expose it in the next release.
  • Push is not available yet in libgit2. It should be developed as part of a GSoC project

/cc @schu @carlosmn

I'm assuming the commit therefore should be done on the remote repository server?

I'm not sure to clearly understand your question.

Current Version of LibGit2Sharp allows one to commit against a standard repository or to directly create commits in the object database without involving the working directory nor the index.

Basically, you can "commit" against a bare or a non-bare repository.

Jonathan Channon

I'm a newbie so go gentle. I'm trying to import commit history from another source control system into Git. I have this working on my local repo which I was then going to push and other users could pull the repo down or clone it from the remote. I'm guessing the best bet is to run my program on the server where the remote repo is and users can clone it when my import is complete.

At the moment my logic simply loops over the files in the other source control system, then loops over that file's histoyry and does a repo.Index.Stage and then repo.Commit. I'm assuming that is correct, should I use the object database? Only problem is i'm not sure what you mean by I can create commits to the object database without involving the index. Could you explain a bit more?

Michael Schubert
Collaborator
schu commented May 24, 2012

Push is not available yet in libgit2. It should be developed as part of a GSoC project

Right, no push support yet. Working on it as part of GSoC.

I'm assuming the commit therefore should be done on the remote repository server?

You cannot "commit on the remote repository server". Creating a commit is a local operation (as most Git ops).

I'm trying to import commit history from another source control system into Git

You write your own import tool?

Jonathan Channon

@schu

I understand commit is local so if run my application on the server which effectively is another PC in the room I can commit against that local repo. Users can use this repo as their remote and pull from it once the import / commits have completed??

Yes, I'm trying to write my own import tool as SourceGear has not export tools but they have an API.

nulltoken
Collaborator

I'm guessing the best bet is to run my program on the server where the remote repo is and users can clone it when my import is complete.

Either this or you can still use git to push your local repo.

I'm not sure what you mean by I can create commits to the object database without involving the index. Could you explain a bit more?

As this may turn into a long programming-related answer, maybe could you direct your question to StackOverflow decorating it with the libgit2sharp tag?

Jonathan Channon

Thanks agree about using git to push the repo to the remote.

Here is a StackOverflow question about the object database

Carlos Martín Nieto
Owner

The simplest way to import stuff might be generating a fast-import stream and letting git do all the git work, specially if you're unfamiliar with the underlying data structures.

Jonathan Channon

fast-import stream???

freel free to add it to the SO question

Carlos Martín Nieto
Owner

fast-import has very little to do with that question. It's what allows you not to deal with the repository but tell git what to do.

Artem Smirnov

Just spotted the following piece:
int (*push)(struct git_transport *transport);
in https://github.com/libgit2/libgit2/blob/development/src/transport.h. Does it mean push is (almost) there?

Michael Schubert
Collaborator

The function prototype has been there for quite a while, but push is almost there (overall missing non-fast-forward detection, report-status capability and code cleanup). I'll drop a note as soon as it's finished / merged, which should happen soon-ish.

Artem Smirnov

Thanks, great news!!

Michael Schubert
Collaborator

Update: push (via http(s) and git) finally has been merged (into libgit2) yesterday. Let us know in case you encounter any problems. Thanks.

Jameson Miller
Collaborator

I have started to put in the interop and the ability to push specific branches into LibGit2Sharp - I will submit a PR once the renaming changes go into LibGit2Sharp (#260) and it is updated to use libgit2 binaries with the push logic.

Mariana Silva

It seams that the push is now available to use.
Can anyone give an example of the implementation of the push command?

Jameson Miller
Collaborator

Push is not yet included in LibGit2Sharp - please see #269. I think it is pretty close, but is still waiting on functionality included in the latest libgit2 builds, but not in the version that LibGit2Sharp builds against.

nulltoken nulltoken closed this February 06, 2013
nulltoken
Collaborator

#269 has been merged. This issue can now be closed. Kudos should go to @jamill!

Jameson Miller
Collaborator

Can anyone give an example of the implementation of the push command?

There are a couple of API entry points in the Network and NetworkExtensions namespaces, accessible from the Repositorytype. For a simple example:

using(Repository repo = new Repository(path))
{
    Remote remote = repo.Remotes["origin"];
    PushResult pushResult = repo.Network.Push(remote, "HEAD", "refs/heads/destination_branch");
    if (pushResult.HasErrors)
    {
        Console.WriteLine("Errors:");
        foreach (PushStatusError error in pushResult.FailedPushUpdates)
        {
            Console.WriteLine("\t{0} : {1}", error.Reference, error.Message);
        }
    }
}

Hope this helps.

Mariana Silva

How can I add the option "--tags"?

Jameson Miller
Collaborator

How can I add the option "--tags"?

Good question. Currently, the API does not expose this as a convient flag (although, I agree that would be nice). You would have to add the tag references directly (e.g., the push spec would be something like "refs/tags/mytag:refs/tags/mytag"). Note that I don't think that wildcard patterns are not supported (in libgit2 or LibGit2Sharp).

I do see that this would be a nice option to expose through LibGit2Sharp.

teammixture

Hi - Can you force push - is this supported?

nulltoken
Collaborator

Hi - Can you force push - is this supported?

@teammixture Similarly to the --tags option, the API doesn't expose (yet ?) a easily discoverable option to force push. However, one can still build a push refspec to do this. For instance, +refs/heads/master:refs/heads/master would force push (+ prefix meaning force) the local master branch to the remote master branch.

Although this kind of programming related question would be a better fit for StackOverflow, I've pushed a test which demonstrates how to do this (see e2290f8).

Feel free to get some inspiration from it.

teammixture

@nulltoken I worked it out just before you replied - totally appreciate you taking the time to respond and writing a test :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.