Created
March 28, 2011 16:18
-
-
Save tclem/890753 to your computer and use it in GitHub Desktop.
API design thoughts for libgit2sharp
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 (var repo = new Repository("path\to\repo.git")) | |
{ | |
// Object lookup | |
var obj = repo.Lookup("sha"); | |
var commit = repo.Lookup<Commit>("sha"); | |
var tree = repo.Lookup<Tree>("sha"); | |
var tag = repo.Lookup<Tag>("sha"); | |
// Rev walking | |
foreach (var c in repo.Commits.Walk("sha")) { } | |
var commits = repo.Commits.StartingAt("sha").Where(c => c).ToList(); | |
var sortedCommits = repo.Commits.StartingAt("sha").SortBy(SortMode.Topo).ToList(); | |
// Refs | |
var reference = repo.Refs["refs/heads/master"]; | |
var allRefs = repo.Refs.ToList(); | |
foreach (var c in repo.Refs["HEAD"].Commits) { } | |
foreach (var c in repo.Head.Commits) { } | |
var headCommit = repo.Head.Commits.First(); | |
var allCommits = repo.Refs["HEAD"].Commits.ToList(); | |
var newRef = repo.Refs.CreateFrom(reference); | |
var anotherNewRef = repo.Refs.CreateFrom("sha"); | |
// Branches | |
// special kind of reference | |
var allBranches = repo.Branches.ToList(); | |
var branch = repo.Branches["master"]; | |
var remoteBranch = repo.Branches["origin/master"]; | |
var localBranches = repo.Branches.Where(p => p.Type == BranchType.Local).ToList(); | |
var remoteBranches = repo.Branches.Where(p => p.Type == BranchType.Remote).ToList(); | |
var newBranch = repo.Branches.CreateFrom("sha"); | |
var anotherNewBranch = repo.Branches.CreateFrom(newBranch); | |
repo.Branches.Delete(anotherNewBranch); | |
// Tags | |
// really another special kind of reference | |
var aTag = repo.Tags["refs/tags/v1.0"]; | |
var allTags = repo.Tags.ToList(); | |
var newTag = repo.Tags.CreateFrom("sha"); | |
var newTag2 = repo.Tags.CreateFrom(commit); | |
var newTag3 = repo.Tags.CreateFrom(reference); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment