GitStore 1.4.0

dotnet add package GitStore --version 1.4.0                
NuGet\Install-Package GitStore -Version 1.4.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GitStore" Version="1.4.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GitStore --version 1.4.0                
#r "nuget: GitStore, 1.4.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install GitStore as a Cake Addin
#addin nuget:?package=GitStore&version=1.4.0

// Install GitStore as a Cake Tool
#tool nuget:?package=GitStore&version=1.4.0                

A dotnet library leverage Git repository as store.

master

Note: it's not a replacement of Git operations, actually it only implements git clone and git push. Basic idea is clone remoting git repository to local and store data as text or bytes, commit and push to remote. The core operations are file reads and writes.

Usage

Install from NuGet

dotnet add package GitStore

This library supports .NET 7 and version onwards.

Basic usage

Provide required option parameters manually.

var option = new GitStoreOption
{
    Branch = "unit-test",
    Author = "test_committer",
    Password = "",
    CommitterEmail = "test_committer@test.com",
    UserName = <Personal Access Token>,
    LocalDirectory = Path.Combine(Path.GetTempPath(), "gitstore_unittest"),
    RemoteGitUrl = "https://github.com/JerryBian/gitstore-dotnet"
};
var store = new GitStore(Options.Create(option));
await store.PullFromRemoteAsync();

var content = await store.GetTextAsync(Path.Combine(option.LocalDirectory, "dummy.txt"));
Assert.Equal("test", content);

var path1 = Path.Combine(option.LocalDirectory, "data", Path.GetRandomFileName());
var content1 = Guid.NewGuid().ToString();
await store.InsertOrUpdateAsync(path1, content1);

var path2 = Path.Combine(option.LocalDirectory, "data", Path.GetRandomFileName());
var content2 = Guid.NewGuid().ToByteArray();
await store.InsertOrUpdateAsync(path2, content2);

await store.PushToRemoteAsync("commit by GitStore.");
await store.PullFromRemoteAsync();

Assert.Equal(File.ReadAllText(path1), content1);
Assert.True(content2.SequenceEqual(File.ReadAllBytes(path2)));

For GitHub repository, you can request PAT here here. Please note you cannot use traditional username/password method to operate GitHub anymore, see the announcement.

Dependency injection / Options pattern

For modern applications, you can register GitStore via DI.

var builder = Host.CreateApplicationBuilder();
builder.Services.AddGitStore();

using IHost host = builder.Build();
var store = host.Services.GetRequiredService<IGitStore>();
var option = host.Services.GetRequiredService<IOptions<GitStoreOption>>().Value;
await store.PullFromRemoteAsync();

The option parameters are configured as standard way.

For example, set environment variable as GitStore__Branch=master.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.4.0 1,045 11/24/2023
1.3.0 262 10/22/2023
1.2.1 170 10/17/2023
1.2.0 144 10/17/2023
1.1.0 160 10/14/2023
1.0.0 220 10/14/2023
0.9.0 148 10/13/2023
0.2.1-alpha 111 10/13/2023
0.2.0 154 10/13/2023
0.1.6-alpha 117 10/10/2023
0.1.1-alpha 110 10/10/2023
0.1.0-alpha 104 10/10/2023