* Insert git hash into exported document
@ 2016-12-23 17:34 David Talmage
2016-12-23 20:13 ` Daniele Pizzolli
0 siblings, 1 reply; 7+ messages in thread
From: David Talmage @ 2016-12-23 17:34 UTC (permalink / raw)
To: Org Mode Mailing List
[-- Attachment #1: Type: text/plain, Size: 211 bytes --]
I'd like to insert the git hash of HEAD in the org-mode documents that I
export. Is there an easy way? I'm exporting to LaTeX.
I looked for it on worg. The mailing list on gmane.org is still off-line,
alas.
[-- Attachment #2: Type: text/html, Size: 314 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Insert git hash into exported document
2016-12-23 17:34 Insert git hash into exported document David Talmage
@ 2016-12-23 20:13 ` Daniele Pizzolli
2016-12-28 19:12 ` David Talmage
0 siblings, 1 reply; 7+ messages in thread
From: Daniele Pizzolli @ 2016-12-23 20:13 UTC (permalink / raw)
To: David Talmage; +Cc: Org Mode Mailing List
David Talmage writes:
> I'd like to insert the git hash of HEAD in the org-mode documents that I
> export. Is there an easy way? I'm exporting to LaTeX.
[]
Hello,
maybe you can start with a simple:
#+NAME: hash-from-lisp
#+BEGIN_SRC emacs-lisp
(shell-command-to-string "git rev-parse HEAD" )
#+END_SRC
#+RESULTS: hash-from-lisp
: 099b6ceee7264832b8e13f1156974b8017e6e4bb
You can hide the result using proper headers or the noexport tag and
then print the result in a verbose way:
The latest commit hash is src_emacs-lisp[:var i=hash-from-lisp]{(format "%s" i)}
or if you enable the shell in babel you can start with:
#+NAME: hash-from-shell
#+BEGIN_SRC shell
git rev-parse HEAD
#+END_SRC
For latex only, I use the following snippets. This works with gitinfo2
(in debian you need the packages texlive-latex-extra and
texlive-latex-extra-doc). Sorry for the long lines...
Please note that this will also highlight the dirty status of the repo,
since adding the latest hash for a modified version make little sense.
Best,
Daniele
#+LATEX_HEADER: \usepackage[,missing={Unknown},dirty={-- Uncommited Changes!!!},notags={Unknown},mark]{gitinfo2}
#+LATEX: \renewcommand{\gitMarkPref}{Historical Info}
# NOTE: \gitTags does not work well: it adds a traling ")"
# NOTE: \gitReln takes the latest release, even there are more commits
#+LATEX: \renewcommand{\gitMark}{Version:\space{}\gitTags{}\space{}--\space{}Id::\space{}\gitAbbrevHash\space{}--\space{}Date:\space{}\gitAuthorIsoDate\space{}\gitDirty}
#+BEGIN_SRC emacs-lisp
(defun update-gitinfo (backend)
"Update .git/gitHeadInfo.gin"
(message "Command: %s" (shell-command-to-string "cd `git rev-parse --show-toplevel` && /bin/bash /usr/share/doc/texlive-doc/latex/gitinfo2/post-xxx-sample.txt"))
(message "Updated gitinfo"))
(add-hook 'org-export-before-processing-hook #'update-gitinfo)
#+END_SRC
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Insert git hash into exported document
2016-12-23 20:13 ` Daniele Pizzolli
@ 2016-12-28 19:12 ` David Talmage
0 siblings, 0 replies; 7+ messages in thread
From: David Talmage @ 2016-12-28 19:12 UTC (permalink / raw)
To: Daniele Pizzolli; +Cc: Org Mode Mailing List
[-- Attachment #1: Type: text/plain, Size: 970 bytes --]
On Fri, Dec 23, 2016 at 3:13 PM, Daniele Pizzolli <dan@toel.it> wrote:
>
> David Talmage writes:
>
> > I'd like to insert the git hash of HEAD in the org-mode documents that I
> > export. Is there an easy way? I'm exporting to LaTeX.
>
> ...
#+NAME: hash-from-lisp
> #+BEGIN_SRC emacs-lisp
> (shell-command-to-string "git rev-parse HEAD" )
> #+END_SRC
>
> #+RESULTS: hash-from-lisp
> : 099b6ceee7264832b8e13f1156974b8017e6e4bb
>
> You can hide the result using proper headers or the noexport tag and
> then print the result in a verbose way:
>
> The latest commit hash is src_emacs-lisp[:var i=hash-from-lisp]{(format
> "%s" i)}
>
>
Thanks! That does what I want. Alas, it has a side effect. When I put
all that in my document, I get the hash I desire but I also get this Emacs
LISP code in my document:
\begin{verbatim}
(shell-command-to-string "git rev-parse HEAD" )
\end{verbatim}
I added :exports results to the BEGIN_SRC block to remove the code.
...
[-- Attachment #2: Type: text/html, Size: 1710 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <16430f8b1ffe49dc987db8e599900630@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>]
* Re: Insert git hash into exported document
[not found] <16430f8b1ffe49dc987db8e599900630@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
@ 2016-12-23 19:47 ` Eric S Fraga
2016-12-24 9:07 ` Michael Welle
[not found] ` <47796546026040e08345d06e9988e8dd@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
0 siblings, 2 replies; 7+ messages in thread
From: Eric S Fraga @ 2016-12-23 19:47 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 660 bytes --]
On Friday, 23 Dec 2016 at 17:34, David Talmage wrote:
> I'd like to insert the git hash of HEAD in the org-mode documents that
> I export. Is there an easy way? I'm exporting to LaTeX.
Anything you can do in a shell could be exported to LaTeX. E.g. I do
the following with mercurial in one of my documents:
#+begin_src org
,* Recent change history
,#+name: changehistoryshellblock
,#+begin_src shell :exports results :results output
hg log --template "{date|shortdate} {desc|firstline}\n" --limit 10 fresa.org
,#+end_src
#+end_src
HTH,
eric
--
: Eric S Fraga (0xFFFCF67D), Emacs 26.0.50.1, Org release_9.0.2-104-gf5b7de
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Insert git hash into exported document
2016-12-23 19:47 ` Eric S Fraga
@ 2016-12-24 9:07 ` Michael Welle
[not found] ` <47796546026040e08345d06e9988e8dd@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
1 sibling, 0 replies; 7+ messages in thread
From: Michael Welle @ 2016-12-24 9:07 UTC (permalink / raw)
To: emacs-orgmode
Hello,
Eric S Fraga <e.fraga@ucl.ac.uk> writes:
> On Friday, 23 Dec 2016 at 17:34, David Talmage wrote:
>> I'd like to insert the git hash of HEAD in the org-mode documents that
>> I export. Is there an easy way? I'm exporting to LaTeX.
>
> Anything you can do in a shell could be exported to LaTeX. E.g. I do
> the following with mercurial in one of my documents:
>
> #+begin_src org
> ,* Recent change history
> ,#+name: changehistoryshellblock
> ,#+begin_src shell :exports results :results output
> hg log --template "{date|shortdate} {desc|firstline}\n" --limit 10 fresa.org
> ,#+end_src
> #+end_src
do you have some mechanism that warns you if you try to export
uncommitted changes? I'm not sure how such a process should be designed.
I think most of the time you publish preliminary revisions and then you
will hate such a warning. On the other hand, I often do work twice when
publishing the final revision, because I forget to checkin and then the
history in the export is wrong.
Regards
hmw
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <47796546026040e08345d06e9988e8dd@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>]
* Re: Insert git hash into exported document
[not found] ` <47796546026040e08345d06e9988e8dd@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
@ 2017-01-03 12:13 ` Eric S Fraga
2017-01-05 16:06 ` Michael Welle
0 siblings, 1 reply; 7+ messages in thread
From: Eric S Fraga @ 2017-01-03 12:13 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 522 bytes --]
On Saturday, 24 Dec 2016 at 09:07, Michael Welle wrote:
[...]
> do you have some mechanism that warns you if you try to export
> uncommitted changes? I'm not sure how such a process should be designed.
I do not. I manually always check the status of the working directory
(C-x v d RET). In any case, as you also note, I do export uncommitted
versions and would find the extra check annoying in practice!
Happy new year!
--
: Eric S Fraga (0xFFFCF67D), Emacs 26.0.50.1, Org release_9.0.2-104-gf5b7de
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Insert git hash into exported document
2017-01-03 12:13 ` Eric S Fraga
@ 2017-01-05 16:06 ` Michael Welle
0 siblings, 0 replies; 7+ messages in thread
From: Michael Welle @ 2017-01-05 16:06 UTC (permalink / raw)
To: emacs-orgmode
Hello,
Eric S Fraga <e.fraga@ucl.ac.uk> writes:
> On Saturday, 24 Dec 2016 at 09:07, Michael Welle wrote:
>
> [...]
>
>> do you have some mechanism that warns you if you try to export
>> uncommitted changes? I'm not sure how such a process should be designed.
>
> I do not. I manually always check the status of the working directory
> (C-x v d RET). In any case, as you also note, I do export uncommitted
> versions and would find the extra check annoying in practice!
hm, maybe I will add a draft marker to the export, if the file has
uncommitted echanges.
> Happy new year!
Same to you.
Regards
hmw
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-01-05 16:06 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-23 17:34 Insert git hash into exported document David Talmage
2016-12-23 20:13 ` Daniele Pizzolli
2016-12-28 19:12 ` David Talmage
[not found] <16430f8b1ffe49dc987db8e599900630@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
2016-12-23 19:47 ` Eric S Fraga
2016-12-24 9:07 ` Michael Welle
[not found] ` <47796546026040e08345d06e9988e8dd@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
2017-01-03 12:13 ` Eric S Fraga
2017-01-05 16:06 ` Michael Welle
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.