Skip to content

aviationexam/git-reader-source-generator

Repository files navigation

Build Status NuGet MyGet feedz.io

GitReader.SourceGenerator

This library build on top of kekyo/GitReader, which is "Lightweight Git local repository traversal library".

Install

<ItemGroup>
    <PackageReference Include="GitReader.SourceGenerator" Version="0.1.4" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="all" />
</ItemGroup>

How to configure library

<PropertyGroup Label="Configure GitInfo">
    <!-- optional, default value: $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), '.gitignore')) -->
    <GitInfo_RootDirectory>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'My.Project.sln'))\..\.git</GitInfo_RootDirectory>

    <GitInfo_Namespace>My.Project.GitInfoNamespace</GitInfo_Namespace>

    <!-- optional, default value 9 -->
    <GitInfo_CommitAbbreviatedLength>9</GitInfo_CommitAbbreviatedLength>

    <!-- optional, default value true -->
    <GitInfo_UseCache>true</GitInfo_UseCache>

    <!-- optional, default value false -->
    <!-- it check only cache existence, not that HEAD equals HEAD in cache -->
    <GitInfo_UseAggressiveCache>true</GitInfo_UseAggressiveCache>
</PropertyGroup>

How to use library

using My.Project.GitInfoNamespace;

Console.WriteLine(GitInfo.Branch);
Console.WriteLine(GitInfo.CommitAbbreviatedHash);
Console.WriteLine(GitInfo.CommitHash);
Console.WriteLine(GitInfo.CommitDate);
Console.WriteLine(GitInfo.TagName);
Console.WriteLine(GitInfo.Tag);
Console.WriteLine(GitInfo.TagMajor);
Console.WriteLine(GitInfo.TagMinor);
Console.WriteLine(GitInfo.TagBuild);
Console.WriteLine(GitInfo.TagRevision);