Skip to content

Instantly share code, notes, and snippets.

@aaronpowell
Created May 31, 2013 05:02
Show Gist options
  • Select an option

  • Save aaronpowell/5683026 to your computer and use it in GitHub Desktop.

Select an option

Save aaronpowell/5683026 to your computer and use it in GitHub Desktop.
ScriptCS libgit2 sample. You need to manually copy the NativeBinaries folder from the LibGit2Sharp folder into the bin folder if you're using 0.5.* of ScriptCS
bin
packages
using LibGit2Sharp;
using System.IO;
static Repository InitOrOpen(string path) {
var gitBase = Repository.Discover(path);
if (gitBase == null) {
Console.WriteLine("Creating repo");
return Repository.Init(path);
}
Console.WriteLine("Opening existing");
return new Repository(gitBase);
}
const string path = Environment.CurrentDirectory;
Console.WriteLine("Here... we... go!");
using (var repo = InitOrOpen(path)) {
var file = Path.Combine(path, "sample.txt");
if (!File.Exists(file)) {
File.CreateText(file).Close();
}
using (var sw = new StreamWriter(file)) {
sw.write(DateTimeOffset.Now.ToString());
}
repo.Index.Stage("*");
repo.Commit("Did it for the lulz", new Signature("Awesome Dude", "awesome@dude.io", DateTime.Now));
Console.WriteLine("All done!");
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="LibGit2Sharp" version="0.11.0.0" targetFramework="net45" />
</packages>
@aaronpowell

Copy link
Copy Markdown
Author

It seems when you run this that LibGit2Sharp raises an error about the ignored folders being 'Access Denied'.

Also if you change the output directory to be nested, swap to a new branch and run it creates a nested git repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment