<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>bloggo ergo sum &#187; git</title>
	<atom:link href="http://bloggoergosum.com/tag/git/feed/" rel="self" type="application/rss+xml" />
	<link>http://bloggoergosum.com</link>
	<description></description>
	<lastBuildDate>Mon, 10 Oct 2011 04:42:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>pre-commit script for submodule hygiene</title>
		<link>http://bloggoergosum.com/2008/08/19/pre-commit-script-for-submodule-hygiene/</link>
		<comments>http://bloggoergosum.com/2008/08/19/pre-commit-script-for-submodule-hygiene/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 16:02:08 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://bloggoergosum.com/?p=323</guid>
		<description><![CDATA[Our team at work is using git submodules to track re-usable code across projects, and it&#8217;s been pretty good so far, but we have hit minor snags along the way (such as the absence of a &#8216;git submodule rm&#8217; command!). Another one is that using submodules adds a step to the sequence of things you [...]]]></description>
			<content:encoded><![CDATA[<p>Our team at work is using git submodules to track re-usable code across projects, and it&#8217;s been pretty good so far, but we have hit minor snags along the way (such as the absence of a &#8216;git submodule rm&#8217; command!).  Another one is that using submodules adds a step to the sequence of things you have to do to publish changes: pushing submodule commits.  It&#8217;s an easy thing to forget, but it&#8217;s a headache for anyone on the other end of a pull when git-checkout-index fails.  This pre-commit hook script will cause the commit to fail if the commit contains new submodule moments and those moments are not present in the corresponding submodule origin.</p>
<pre lang="Bash">
#!/bin/sh

function array_has
{
    for item in $1
    do
	if [ "$item" = "$2" ]; then
	    return 1;
	fi
    done

    return 0;
}

diffs=`git diff --cached --name-only`

IFS=`echo -en "\n\b"`
for smstat in `git submodule 2>/dev/null`
do
    if [[ "$smstat" =~ '^\+(.*)' ]]; then
	smstat=${BASH_REMATCH[1]}
    fi

    head=$(echo $smstat | awk '{print $1}')
    path=$(echo $smstat | awk '{print $2}')
    moment=$(git ls-files -s $path | awk '{print $2}')

    array_has $diffs $path
    if [ $? ]; then
	pushd >/dev/null $path
	for rhead in $(git ls-remote -h origin
	               | awk '{print $1}')
	do
	    if [ "$(git rev-list $moment ^$rhead)"
		    != "" ]
	    then
		unpub=1;
	    fi
	done
    fi

    if [[ $unpub -gt 0 ]]; then
	echo -n "ERROR: you are trying to commit "
	echo -n "unpublished changes to the $path "
	echo    "submodule."
	exit 1;
    fi

done

exit 0;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://bloggoergosum.com/2008/08/19/pre-commit-script-for-submodule-hygiene/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

