Skip to content

Viir/GitCore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitCore

Pure managed C# implementation for reading from Git repositories.

Features

  • Portable and simple
    • No dependencies on native code.
  • Reading from local Git repositories
    • Resolve HEAD and other references to commit SHAs.
    • Load all files from any commit's tree.
    • Supports both loose objects and pack files.
  • Cloning via Git Smart HTTP
    • Efficient partial cloning of subdirectories.
    • Configurable API for caching git objects to make cloning more efficient.

Usage

NuGet: https://www.nuget.org/packages/GitCore/

dotnet  add  package  GitCore

Load files from a local Git repository

var gitDir = Path.Combine(repoRootDir, ".git");

// Load all files from the current HEAD commit
var filesAtHead = GitCore.LoadFromLocalFiles.LoadTreeContentsFromHead(gitDir);

// Or resolve HEAD and load from a specific commit
var commitSha = GitCore.LoadFromLocalFiles.ResolveHead(gitDir);
var filesAtCommit = GitCore.LoadFromLocalFiles.LoadTreeContentsFromCommit(gitDir, commitSha);

// Resolve any reference (branch, tag, etc.)
var branchSha = GitCore.LoadFromLocalFiles.ResolveReference(gitDir, "refs/heads/main");

// Load the full in-memory object store
var repository = GitCore.LoadFromLocalFiles.LoadRepository(gitDir);

Load files from a remote Git repository

var subdirectoryContents =
    await GitCore.LoadFromUrl.LoadSubdirectoryContentsFromGitUrlAsync(
        gitUrl: "https://github.com/pine-vm/pine.git",
        commitSha: "c837c8199f38aab839c40019a50055e16d100c74",
        subdirectoryPath: ["guide"]);

History

In the past, I had used LibGit2Sharp to clone Git repositories and read their files. That often works, but the native dependencies of such a solution have caused many problems.

For any app that's hosted in .NET anyway, a pure managed implementation seems the natural way to simplify builds and operations.

About

Pure managed C# implementation for reading from Git repositories.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

 
 
 

Contributors

Languages