From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniele Pizzolli Subject: Re: Insert git hash into exported document Date: Fri, 23 Dec 2016 21:13:38 +0100 Message-ID: <87k2aqh099.fsf@toel.it> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cKWD5-0004ln-9z for emacs-orgmode@gnu.org; Fri, 23 Dec 2016 15:13:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cKWD2-0002uk-42 for emacs-orgmode@gnu.org; Fri, 23 Dec 2016 15:12:59 -0500 Received: from relay4-d.mail.gandi.net ([2001:4b98:c:538::196]:56560) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cKWD1-0002uQ-U0 for emacs-orgmode@gnu.org; Fri, 23 Dec 2016 15:12:56 -0500 In-reply-to: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" 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