emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Daniele Pizzolli <dan@toel.it>
To: David Talmage <david.talmage@shoutpoint.com>
Cc: Org Mode Mailing List <emacs-orgmode@gnu.org>
Subject: Re: Insert git hash into exported document
Date: Fri, 23 Dec 2016 21:13:38 +0100	[thread overview]
Message-ID: <87k2aqh099.fsf@toel.it> (raw)
In-Reply-To: <CAM6q_N43gFEK_ux6VuMMC2jrMU8p0rXzK98a4ip5rKGFtWxRzQ@mail.gmail.com>


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

  reply	other threads:[~2016-12-23 20:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-23 17:34 Insert git hash into exported document David Talmage
2016-12-23 20:13 ` Daniele Pizzolli [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k2aqh099.fsf@toel.it \
    --to=dan@toel.it \
    --cc=david.talmage@shoutpoint.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).