1

How can GitSharp (Git for .NET and Mono) be used to PUSH changes changes to a remote server over SSH?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
ccook
  • 5,869
  • 6
  • 56
  • 81

2 Answers2

3

In theory, yes, the latest GitSharp 0.3 release (June 2010) includes:

bug fixes in the transport code (pushing / fetching via http or ssh)

The GitSharp README.txt does have:

Object transport

  • Fetch via ssh, git, http and bundles.
  • Push via ssh, git. Git# does not yet deltify
    the pushed packs so they may be a lot larger than C Git packs.

You will find an example of such a push (over ssh) in this thread:

Repository repository = new Repository(@"\path\to\my_repos");
repository.Index.Add(@"\path\to\my_file");

Commit commited = repository.Commit("Testing fromGitC#", new Author("Author", "...@aCompany.com"));

if(commited.IsValid) {
    PushCommand pushCommand = new PushCommand {
        RefSpecs = new List<RefSpec> {
           new RefSpec("HEAD", "refs/for/master")
        },
        Force = true,
        Repository = repository
    };
    pushCommand.AddAll();
    pushCommand.Execute();
} 
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you. Two concerns of mine with GitSharp to PUSH at this point 1) It does not yet 'deltify' 2) The SSH library it uses is the v1 library (deprecated) http://www.mentalis.org/soft/projects/seclib/download.qpx – ccook Nov 09 '10 at 14:05
  • @ccook: I completely agree. I am not sure about the degree of activity of that GitSharp project. – VonC Nov 09 '10 at 14:20
  • I accepted this, as it *should* work once things with SSH Transport are resolved... Note that the alternative, NGIT, also has SSH problems. – ccook Nov 12 '10 at 12:06
2

GitSharp is based upon a manual port of JGit from Java to C#. There is another project does this semi-automatically (with the purpose of being added to MonoDevelop)

http://foodformonkeys.blogspot.com/2010/10/ngit.html

https://github.com/slluis/ngit

ABOUT NGIT

NGit is a port of JGit [1] to C#. This port is generated semi-automatically using Sharpen [2], a Java-to-C# conversion utility.

NGit provides all functionality implemented by JGit, including all repository manipulation primitives and transport protocols. SSH support is provided by a port of jsch [3], included in the project.

The project is composed by 4 libraries: - NGit: The git library. - NGit.Test: Unit tests for NGit - NSch: The port of jsch. - Sharpen: Some support classes required by the above libraries.

ccook
  • 5,869
  • 6
  • 56
  • 81