Skip to content

Commit

Permalink
Merge pull request #12 from Xerdi/dirty
Browse files Browse the repository at this point in the history
Git status
  • Loading branch information
MacLotsen authored Sep 14, 2024
2 parents 6b97aab + b16250f commit 4bc979f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
4 changes: 3 additions & 1 deletion doc/gitinfo-lua.tex
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@
When the version is dirty it will be post fixed with \texttt{-<commit count>-<short ref>}.
For example, when this paragraph was written, the version was displaying 0.0.1-14-gcc2bc30.\\

\DescribeMacro{\ifgitdirty} To test whether there are any pending changes in the local Git repository, use the \cmd{\ifgitdirty}\marg{true code}\marg{false code} macro.
For this macro to work properly, be sure to add a \texttt{.gitignore}\footnote{A proper example of a \texttt{.gitignore} file for \LaTeX: \url{https://raw.githubusercontent.com/github/gitignore/main/TeX.gitignore}} file and include all \TeX\ based generated files.\\

The \DescribeMacro{\gitdate}\cmd{\gitdate} macro gets the most recent date from the git log.
Meaning, the last `short date' variant is picked from the last commit.
This short date is formatted ISO based and is already suitable for use in packages like \texttt{isodate} for more advanced date formatting.\\
Expand Down Expand Up @@ -201,7 +204,6 @@
For this section the git project of this document is used due to the fact that there are references to revisions.
The test project's revisions change for every user, since they get recreated every time \texttt{test-scenario.sh} is executed (see section~\ref{sec:project}).\\

\clearpage
\noindent
\DescribeMacro{\gitcommit}\oarg{format}\marg{csname}\marg{revision}\\
For displaying commit data \cmd{\gitcommit} can be used.
Expand Down
15 changes: 14 additions & 1 deletion scripts/gitinfo-lua.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,23 @@ function api:write_version()
end
end

function api:is_dirty()
local files_changed, _ = self.cmd:exec('status --porcelain=1', true)
return files_changed and #files_changed > 0
end

function api:write_is_dirty()
if self:is_dirty() then
tex.write('1')
else
tex.write('0')
end
end

-- todo: prevent output to stderr
-- todo: add write variant
-- experimental
function api:is_dirty()
function api:is_tag()
local ok, _ = self.cmd:exec('describe --tags --exact-match')
return ok == nil
end
Expand Down
9 changes: 9 additions & 0 deletions tex/gitinfo-lua.sty
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@
\newcommand*\gitdate{\directlua{git:cs_last_commit('git@single@arg', 'cs')}}
\newcommand*\gitdirectory[1]{\directlua{git:dir('#1')}}
\newcommand*\gitunsetdirectory{\directlua{git:dir(nil)}}
\newcommand*\ifgitdirty[2]{%
\def\@dirtytrue{1}%
\edef\@dirty{\directlua{git:write_is_dirty()}}%
\ifx\@dirty\@dirtytrue
#1%
\else
#2%
\fi
}

\newcommand\git@format@author[2]{%
#1
Expand Down

0 comments on commit 4bc979f

Please sign in to comment.