Skip to content

Commit 5d38986

Browse files
committed
Revisiting \GI@check@repo@prefix.
- Exporting \GI@repo@prefix to the global scope. - Being nicer if not in a git repository.
1 parent 2bf63dc commit 5d38986

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

Todo

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
Error handling
22
--------------
33

4-
Be nicer if not in a git repo?
5-
64
Check for unexpected EOF?
75

86
Git logic
97
---------
108

11-
What to do it HEAD is not a branch?
9+
What to do if HEAD is not a branch?
1210

1311
General
1412
-------

git-info.sty

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
\newcommand\githeadminute{0}
1616
\newcommand\githeadsecond{0}
1717
\newcommand\githeadtzsign{+}
18-
\newcommand\githeadtzhour{0}
19-
\newcommand\githeadtzminute{0}
18+
\newcommand\githeadtzhour{00}
19+
\newcommand\githeadtzminute{00}
2020

21-
% semi-private setting
21+
% semi-private settings
2222
\newcommand\GI@max@depth{8}
2323
\newcommand\GI@gih@name{git-info.gih}
2424

25+
% private values
26+
\newif\ifGI@is@a@repo@
27+
2528
% private constants
2629
\newcommand\GI@repo@prefix{}
2730
\newcommand\GI@head@file{\GI@repo@prefix/.git/HEAD}
@@ -51,6 +54,7 @@
5154
% finding the .git directory
5255

5356
\newcommand\GI@check@repo@prefix{%
57+
\GI@is@a@repo@true
5458
\IfFileExists{./\GI@head@file}{%
5559
\edef\GI@repo@prefix{./}%
5660
}{%
@@ -74,11 +78,38 @@
7478

7579
\newcommand\GI@not@a@git@repo{%
7680
\endgroup
77-
\PackageError{git-info}{%
78-
Current directory is not a git repository}{%
79-
Check the manual for details.}%
81+
\PackageWarning{git-info}{%
82+
Current directory is not a git repository.\MessageBreak
83+
No information about current HEAD is available.\MessageBreak
84+
\protect\githead* commands are set to dummy values\@gobble}
85+
\GI@is@a@repo@false
8086
\endinput}
8187

88+
% getting all informations about HEAD
89+
90+
\newcommand\GI@get@head@all{%
91+
\begingroup
92+
\GI@get@head@path
93+
\GI@get@branch
94+
\GI@get@head@hash
95+
\GI@get@head@infos
96+
\GI@get@gen@datetime{head}%
97+
\edef\@tempa{\endgroup
98+
\GI@set@export\githeadauthor{\githeadauthor}%
99+
\GI@set@export\githeadmail{\githeadmail}%
100+
\GI@set@export\githeadcommit{\githeadcommit}%
101+
\GI@set@export\githeadbranch{\githeadbranch}%
102+
\GI@set@export\githeadyear{\githeadyear}%
103+
\GI@set@export\githeadmonth{\githeadmonth}%
104+
\GI@set@export\githeadday{\githeadday}%
105+
\GI@set@export\githeadhour{\githeadhour}%
106+
\GI@set@export\githeadminute{\githeadminute}%
107+
\GI@set@export\githeadsecond{\githeadsecond}%
108+
\GI@set@export\githeadtzsign{\githeadtzsign}%
109+
\GI@set@export\githeadtzhour{\githeadtzhour}%
110+
\GI@set@export\githeadtzminute{\githeadtzminute}}%
111+
\@tempa}
112+
82113
% finding the path to head
83114

84115
\newcommand\GI@get@head@path{%
@@ -247,28 +278,8 @@
247278

248279
% main
249280

250-
\newcommand\gitgetinfos{%
251-
\begingroup
252-
\GI@check@repo@prefix
253-
\GI@get@head@path
254-
\GI@get@branch
255-
\GI@get@head@hash
256-
\GI@get@head@infos
257-
\GI@get@gen@datetime{head}%
258-
\edef\@tempa{\endgroup
259-
\GI@set@export\githeadauthor{\githeadauthor}%
260-
\GI@set@export\githeadmail{\githeadmail}%
261-
\GI@set@export\githeadcommit{\githeadcommit}%
262-
\GI@set@export\githeadbranch{\githeadbranch}%
263-
\GI@set@export\githeadyear{\githeadyear}%
264-
\GI@set@export\githeadmonth{\githeadmonth}%
265-
\GI@set@export\githeadday{\githeadday}%
266-
\GI@set@export\githeadhour{\githeadhour}%
267-
\GI@set@export\githeadminute{\githeadminute}%
268-
\GI@set@export\githeadsecond{\githeadsecond}%
269-
\GI@set@export\githeadtzsign{\githeadtzsign}%
270-
\GI@set@export\githeadtzhour{\githeadtzhour}%
271-
\GI@set@export\githeadtzminute{\githeadtzminute}}%
272-
\@tempa}
281+
\GI@check@repo@prefix
282+
\ifGI@is@a@repo@
283+
\GI@get@head@all
284+
\fi
273285

274-
\gitgetinfos

0 commit comments

Comments
 (0)