Skip to content

Instantly share code, notes, and snippets.

@mm201
Created September 4, 2013 17:06

Revisions

  1. mm201 created this gist Sep 4, 2013.
    48 changes: 48 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    using System;
    using System.IO;
    using LibGit2Sharp;

    namespace PushTestcase
    {
    class Program
    {
    static void Main(string[] args)
    {
    String wd = Directory.GetCurrentDirectory();

    String path = wd + "\\test-repo";
    Directory.CreateDirectory(path);
    Repository.Init(path);
    Console.WriteLine("Initialized test-repo");
    StreamWriter sw = File.CreateText(path + "\\test.txt");
    sw.Write("This is a test document which will be committed.");
    Console.WriteLine("Wrote file.");
    Repository repo = new Repository(path);
    repo.Index.Stage("test.txt");
    Console.WriteLine("Staged file.");
    repo.Commit("Test commit.");
    Console.WriteLine("Committed.");
    repo.Dispose();
    repo = null;

    String clone_path = wd + "\\clone-repo";
    Directory.CreateDirectory(clone_path);
    Repository.Clone(path, clone_path);
    Console.WriteLine("Cloned repository.");

    repo = new Repository(path);
    repo.Branches.Add("otherBranch", repo.Head.Tip);
    Console.WriteLine("Created secondary branch.");
    repo.Branches["otherBranch"].Checkout(); // checkout a different branch so we can push master
    Console.WriteLine("Checked out secondary branch.");
    repo.Dispose();
    repo = null;

    Repository clone = new Repository(clone_path);
    clone.Network.Push(clone.Head);
    Console.WriteLine("Pushed.");
    clone.Dispose();
    clone = null;
    }
    }
    }