Created
May 31, 2013 05:02
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bin | |
| packages |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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!"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <packages> | |
| <package id="LibGit2Sharp" version="0.11.0.0" targetFramework="net45" /> | |
| </packages> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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