%%
%% This is file `gitstatus.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% gitstatus.dtx  (with options: `package')
%% Copyright (C) 2022 by Maximilian Gruber
%% 
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3 of this license or (at your option) any later
%% version. The latest version of this license is in:
%% 
%% http://www.latex-project.org/lppl.txt
%% 
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
\NeedsTeXFormat{LaTeX2e}[2005/12/01]
\ProvidesPackage{gitstatus}
    [2022/10/06 v1.1 Watermark Git Information Package]
\RequirePackage{kvoptions}
\RequirePackage{catchfile}
\RequirePackage{xstring}
\DeclareStringOption[.git/]{gitdir}                    % custom git dir (can be relative)
\DeclareBoolOption[false]{watermark}                   % watermark with branch + hash on top of page
\DeclareComplementaryOption{nowatermark}{watermark}
\DeclareBoolOption[false]{novariables}                 % disable creation of variables
\ProcessKeyvalOptions*
\def\gitstatus@headpath{\gitstatus@gitdir HEAD}
\IfFileExists{\gitstatus@headpath}{
    \CatchFileDef{\gitstatus@headfull}{\gitstatus@headpath}{}
    \StrGobbleRight{\gitstatus@headfull}{1}[\gitstatus@head]
    \StrBehind[2]{\gitstatus@head}{/}[\gitstatus@branch]
}{
    \def\gitstatus@branch{NOT AVAILABLE}
    \PackageWarning{gitstatus}{Can't find HEAD (maybe check specified gitdir).}
}
\def\gitstatus@branchpath{\gitstatus@gitdir refs/heads/\gitstatus@branch}
\IfFileExists{\gitstatus@branchpath}{
    \CatchFileDef{\gitstatus@commit}{\gitstatus@branchpath}{}
}{
    \def\gitstatus@commit{NOT AVAILABLE}
    \PackageWarning{gitstatus}{Can't read commit hash (maybe check specified gitdir).}
}
\ifgitstatus@novariables
\else
    \def\gitdir{\gitstatus@gitdir}
    \def\gitbranch{\gitstatus@branch}
    \def\gitcommit{\gitstatus@commit}
\fi
\ifgitstatus@watermark
    \RequirePackage{xcolor}
    \RequirePackage[printwatermark]{xwatermark}
    \newwatermark
        [allpages,color=black!20,angle=0,scale=0.5,align=left,xpos=-2cm,ypos=13cm]
        {On branch: \texttt{\gitstatus@branch}\\ Commit: \texttt{\gitstatus@commit}}
\fi
\endinput
%%
%% End of file `gitstatus.sty'.
