1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
% \iffalse meta-comment
%
% 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.
%
% \fi
%
%
% \iffalse
%<package>\NeedsTeXFormat{LaTeX2e}[2005/12/01]
%<package>\ProvidesPackage{gitstatus}
%<package> [2022/10/06 v1.1 Watermark Git Information Package]
%
%<*driver>
\documentclass{ltxdoc}
\usepackage[watermark]{gitstatus}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
%\OnlyDescription
\begin{document}
\DocInput{gitstatus.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
%
% \changes{v1.1}{2022/10/06}{Initial version}
%
% \DoNotIndex{\CatchFileDef, \DeclareBoolOption, \DeclareComplementaryOption, \DeclareStringOption}
% \DoNotIndex{\\, \def, \else, \fi, \IfFileExists, \iffalse, }
% \DoNotIndex{\newwatermark, \texttt}
% \DoNotIndex{\RequirePackage, \PackageWarning, \ProcessKeyvalOptions, \StrBehind, \StrGobbleRight}
%
% \GetFileInfo{gitstatus.sty}
% \title{The \textsf{gitstatus} package\thanks{This document
% corresponds to \textsf{gitstatus}~\fileversion,
% dated~\filedate.}}
% \author{Maximilian Gruber \\ \texttt{m.gruber@mailbox.org}}
%
% \maketitle
%
% \begin{abstract}
% This package allows to include information about a git-repository into a document.
% This information can be included like the watermark in this document or by the use of variables.
% \end{abstract}
%
% \section{Introduction}
% If your LaTeX-document is version-controlled with git, you might encounter situations, where you want to include some information of your git-repository into your LaTeX-document - e.g. to keep track on who gave you feedback on which version of your document.
%
% \section{Options}
% \DescribeMacro{gitdir}
% custom git dir (can be relative), (default is ".git/", meaning your LaTeX document is in the top level of your repo)
%
% \DescribeMacro{watermark}
% watermark with branch + hash on top of page (default: don't use watermark)
%
% \DescribeMacro{nowatermark}
% same as watermark=false
%
% \DescribeMacro{novariables}
% disable creation of variables (default: false, hence variables are created)
%
%
% \section{Variables}
% Apart from the option to add a watermark at the top of the page that mentions the current commit hash and branch-name, the package also provides variables with the same information for individual use.
% These variables are:
% \DescribeMacro{\gitdir}
% The directory of the git repository.
%
% \DescribeMacro{\gitcommit}
% The hash of the most recent commit of the current branch.
%
% \DescribeMacro{\gitbranch}
% The name of the current branch.
%
%
% \StopEventually{\PrintChanges}
%
% \section{Implementation}
%
% \subsection{Required Packages}
% The package relies on five other packages. Three are listed here, the other two are only required if a watermark is created.
% \begin{macrocode}
\RequirePackage{kvoptions}
\RequirePackage{catchfile}
\RequirePackage{xstring}
% \end{macrocode}
%
% \subsection{Options}
% The options are defined.
% \begin{macrocode}
\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*
% \end{macrocode}
%
%
% \subsection{Getting Git Information}
% Git information is read directly from the files within the specified git-directory.
%
% \subsubsection{Branch Name}
% Branch is read from HEAD.
% \begin{macrocode}
\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).}
}
% \end{macrocode}
%
% \subsubsection{Commit Hash}
% Commit-Hash is read from refs/heads/<branch-name>.
% \begin{macrocode}
\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).}
}
% \end{macrocode}
%
% \subsection{Defining Local Variables}
% Make directory, branch and hash available outside of package
% \begin{macrocode}
\ifgitstatus@novariables
\else
\def\gitdir{\gitstatus@gitdir}
\def\gitbranch{\gitstatus@branch}
\def\gitcommit{\gitstatus@commit}
\fi
% \end{macrocode}
%
% \subsection{Creating Watermark}
% Include git information as watermark.
% \begin{macrocode}
\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
% \end{macrocode}
%
% \PrintIndex
%
% \Finale
\endinput
|