Skip to content

Instantly share code, notes, and snippets.

@mm201
Created September 4, 2013 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mm201/6439858 to your computer and use it in GitHub Desktop.
Save mm201/6439858 to your computer and use it in GitHub Desktop.
Testcase for push issue with libgit2sharp
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;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment