zsh-workers
 help / color / mirror / code / Atom feed
* git branches and compilation
@ 2013-06-15 19:46 Bart Schaefer
  2013-06-17 10:57 ` Mikael Magnusson
  2013-07-24 14:25 ` Richard Hartmann
  0 siblings, 2 replies; 5+ messages in thread
From: Bart Schaefer @ 2013-06-15 19:46 UTC (permalink / raw)
  To: zsh-workers

On Saturday, May 18, 2013, Phil Pennock wrote:

> On 2013-05-18 at 16:24 -0700, Bart Schaefer wrote:
> > (One of the few things I'm finding annoying about git is that
> > a cloned repository doesn't preserve file timestamps.)
>
> There's a post-checkout hook [...]

Having been annoyed a couple of times by things not recompiling when a
different branch is checked out (especially the texinfo inputs in Doc/,
leading to reams of bad node errors when doing "make info") I dug into
this a bit further and found "metastore".

http://david.hardeman.nu/software.php

It's available as a Debian package and seems so far to do what I want,
although I haven't really been able to test it thoroughly because no one
else has pushed anything in the past couple of days.

The following patch adds a couple of more lines to the .*ignore files
and three functions in Util/, two of which are git hooks and the third
of which creates symlinks in .git/hooks for the first two.  I'm curious
if anyone has any opinions/examples on whether this approach is best,
or if something requiring "git clone --template ..." is preferred.

It might also be ideal to have the metadata stored when stashing or at
least (in the old branch) before checkout (of the new), but there don't
seem to be hooks for either of those.

I won't push this patch without some discussion from the list first.

diff --git a/.cvsignore b/.cvsignore
index 95cdc58..a5f7191 100644
--- a/.cvsignore
+++ b/.cvsignore
@@ -14,3 +14,4 @@ stamp-h.in
 autom4te.cache
 *.swp
 .git
+.metadata
diff --git a/.gitignore b/.gitignore
index d0172e3..b89a5cc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,6 +9,7 @@ TAGS
 *~
 .*.sw?
 \#*
+.metadata
 
 /META-FAQ
 /config.cache
diff --git a/Util/add-git-hooks b/Util/add-git-hooks
new file mode 100755
index 0000000..77b2ac2
--- /dev/null
+++ b/Util/add-git-hooks
@@ -0,0 +1,38 @@
+#! /bin/sh
+
+HOOKS="pre-commit post-checkout"
+
+case `pwd` in
+*/Util) cd ..;;
+esac
+
+if ! [ -d .git/hooks ]
+then
+	echo "No directory for git hooks" >&2
+	exit 1
+fi
+
+if metastore -h 2>/dev/null 1>&2
+then
+	echo "Installing in `pwd`/.git/hooks ..." >&2
+	cd .git/hooks
+	for hook in $HOOKS
+	do
+		if [ -e $hook ]
+		then
+			if cmp -s ../../Util/git-$hook $hook
+			then
+				echo "$hook is already installed" >&2
+			else
+				echo "Another $hook already exists" >&2
+			fi
+		else
+			ln -s ../../Util/git-$hook $hook
+			chmod +x $hook
+		fi
+	done
+else
+	echo "Did not find metastore, skipping hooks" >&2
+fi
+
+exit 0
diff --git a/Util/git-post-checkout b/Util/git-post-checkout
new file mode 100755
index 0000000..a15d1d9
--- /dev/null
+++ b/Util/git-post-checkout
@@ -0,0 +1,24 @@
+#!/bin/bash
+#
+# Hook script to restore metadata information using metastore
+# following each checkout.
+
+# Do not restore metadata on a checkout from index
+if [ "$3" -eq 0 ]
+then
+	exit 0
+fi
+
+STOREFILE=".metadata/$(git symbolic-ref HEAD)/.metadata"
+
+if [ ! -e "$STOREFILE" ]; then
+	echo "No .metadata yet" >&2
+	exit 0
+fi
+
+if ! metastore -q -a -f "$STOREFILE"; then
+	echo "Failed to execute metastore -a" >&2
+	exit 1
+fi
+
+exit 0
diff --git a/Util/git-pre-commit b/Util/git-pre-commit
new file mode 100755
index 0000000..6030d12
--- /dev/null
+++ b/Util/git-pre-commit
@@ -0,0 +1,25 @@
+#!/bin/bash
+#
+# Hook script to store metadata information using metastore
+# before each commit.
+
+STOREPATH=".metadata/$(git symbolic-ref HEAD)"
+STOREFILE="$STOREPATH/.metadata"
+
+if [ ! -d "$STOREPATH" ] && ! mkdir -p "$STOREPATH"
+then
+	echo "Cannot create $STOREPATH, committing anyway" >&2
+	exit 0
+fi
+
+if ! metastore -s -f "$STOREFILE"; then
+	echo "Failed to execute metastore -s" >&2
+	exit 1
+fi
+
+if [ ! -e "$STOREFILE" ]; then
+	echo ".metadata missing after metastore -s" >&2
+	exec test \! -x .git/hooks/post-checkout
+fi
+
+exit 0

-- 
Barton E. Schaefer


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-07-25 18:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-15 19:46 git branches and compilation Bart Schaefer
2013-06-17 10:57 ` Mikael Magnusson
2013-06-17 17:04   ` Bart Schaefer
2013-07-24 14:25 ` Richard Hartmann
2013-07-25 18:53   ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).