<?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>The Troll-Range &#187; git</title>
	<atom:link href="http://blog.trollgod.org.uk/tag/git/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.trollgod.org.uk</link>
	<description>Ghworg&#039;s wibblings and geek projects.</description>
	<lastBuildDate>Mon, 26 Apr 2010 19:31:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Maintaining a WordPress install with git</title>
		<link>http://blog.trollgod.org.uk/2009/04/maintaining-a-wordpress-install-with-git/</link>
		<comments>http://blog.trollgod.org.uk/2009/04/maintaining-a-wordpress-install-with-git/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 06:00:37 +0000</pubDate>
		<dc:creator>Ghworg</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[versioncontrol]]></category>

		<guid isPermaLink="false">http://blog.trollgod.org.uk/?p=200</guid>
		<description><![CDATA[<p>A while ago I started tracking WordPress updates using Subversion. Instead of downloading the official release from the WordPress website I checked out the code from the stable branch of their Subversion repo. This made upgrading as simple as running &#8220;svn up&#8221; and I didn&#8217;t lose any modifications I had made to the code.</p> <span style="color:#777"> . . . &#8594; Read More: <a href="http://blog.trollgod.org.uk/2009/04/maintaining-a-wordpress-install-with-git/">Maintaining a WordPress install with git</a></span>]]></description>
			<content:encoded><![CDATA[<p>A while ago I started tracking <a href="http://wordpress.org/">WordPress</a> updates using <a href="http://subversion.tigris.org/">Subversion</a>.  Instead of downloading the official release from the <a href="http://wordpress.org/download/">WordPress website</a> I checked out the code from the stable branch of their <a href="http://wordpress.org/download/svn/">Subversion repo</a>.  This made upgrading as simple as running &#8220;svn up&#8221; and I didn&#8217;t lose any modifications I had made to the code.</p>
<p>While this worked very well it does have one big drawback, it means I can&#8217;t put the themes and plugins I use into version control since they are inside the official svn checked out dirs.</p>
<p>Recently I&#8217;ve been switching to <a href="http://git.or.cz/index.html">git</a> and thought that switching the WordPress install to git would solve this problem.  My first attempt was using the git-svn tool to convert the upstream subversion repo to a local git one.  This would have enabled something very similar to what I was doing before with the &#8220;svn up&#8221; command, one git-svn command would have updated the code to the latest version.</p>
<p>The problem with that idea is that the WordPress repo contains over 10,000 revisions.  Duplicating that via git-svn would have taken days and all I really need is the current version.  I looked for a while to see if there was a way to limit the number of revisions copied but apparently there isn&#8217;t.</p>
<p>So, I fall back to searching the web and I came across <a href="http://ianloic.com/2008/09/06/tracking-wordpress-using-git/">Tracking WordPress using Git</a>, which is pretty close to what I wanted.  It is a little bit more work to do the updates that way but not that much.</p>
<p>What I need though is an internal dev version of the site on one branch, the live site on another and the upstream code on a third.  Then I need to push the live branch to my web host, and I also need to be able to pull any emergency fixes I make direct on the live site back into my local git repos.  Pushing changes with git is a little tricky since a push doesn&#8217;t update the checked out files, but I found a helpful blog entry <a href="http://joemaller.com/2008/11/25/a-web-focused-git-workflow/">A web focused git work-flow</a>, which gives me exactly what I want.</p>
<p>The one remaining problem I have is I don&#8217;t completely understand how git merges work.  The internal dev branch and the live branch have some differences I don&#8217;t want merged, paths etc.  Whenever I try to merge the branches though it invariably automatically changes one branch to exactly match the other and auto-commits.  I&#8217;m sure git can do this, merge some changes but not others without manual intervention each time but I haven&#8217;t worked out how yet.</p>
<p>Okay, after a bit more time working with this setup it seems the problem is bi-directional merges.  Merging from dev to live works great right up until the point I do a merge from live to dev, at which point git seems to forget that there is some stuff that I don&#8217;t want merged next time I go from dev to live.  Preventing the auto-commit makes this manageable though, to do this you (confusingly) need to specify &#8220;&#8211;no-commit &#8211;no-ff&#8221;.  You&#8217;d think the no-commit would be enough on its own but apparently not.</p>
<p>So in my local copy I have 3 branches:</p>
<ul>
<li>master, the extracted WordPress tarball</li>
<li>internal, my internal development/test site</li>
<li>external, copy of the live site</li>
</ul>
<p>I have the following settings set on my local git repo (private details redacted) to make pushing changes easier, I don&#8217;t have to remember any parameters for the git push command.</p>
<pre>
branch.internal.remote=origin
branch.internal.merge=refs/heads/internal
remote.external.url=ssh://$USER@$HOST/~/$GIT_PATH
remote.external.fetch=+refs/heads/*:refs/remotes/external/*
branch.external.merge=external
branch.external.remote=external
</pre>
<p>Then on my web host I have the bare git repo at $GIT_PATH that gets pushed to, and the actual live site.  Both of those only have the external branch.</p>
<p>To update the live site all I need to do is make the changes on my local copy of the external branch, then run &#8220;git push&#8221;.  This sends the changes up to the bare repo, which then automatically updates the live site.</p>
<p>Then when a new version WordPress gets released, what I will do is</p>
<ol>
<li>Switch to the master branch.</li>
<li>Delete everything except the git dir.</li>
<li>Unpack the new files to replace the deleted ones.</li>
<li>Commit those to git and it will work out what has changed for that release.</li>
<li>Change to the other branches in turn and git merge from the master branch.</li>
</ol>
<p>This should update me to the latest release without losing any of my local themes, plugins or mods.</p>
<p>I could go one step further and create &#8220;upstream&#8221; branches for each plugin I use in a similar manner to the main upstream WordPress branch.  That would allow me to mod the plugins, and still upgrade them easily.  I&#8217;m not going to do that though (yet) as I think it would be more trouble than it is worth.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trollgod.org.uk/2009/04/maintaining-a-wordpress-install-with-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build numbers in interpreted code</title>
		<link>http://blog.trollgod.org.uk/2009/04/build-numbers-in-interpreted-code/</link>
		<comments>http://blog.trollgod.org.uk/2009/04/build-numbers-in-interpreted-code/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 06:00:20 +0000</pubDate>
		<dc:creator>Ghworg</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[versioncontrol]]></category>

		<guid isPermaLink="false">http://blog.trollgod.org.uk/?p=147</guid>
		<description><![CDATA[<p>When I write a program I like to include a build number in the version. Usually I go version.revision.build. The version only ever gets bumped for things that are practically a complete rewrite, and sometimes not even then. The revision gets bumped for new features or major bug fixes and the build gets bumped <span style="color:#777"> . . . &#8594; Read More: <a href="http://blog.trollgod.org.uk/2009/04/build-numbers-in-interpreted-code/">Build numbers in interpreted code</a></span>]]></description>
			<content:encoded><![CDATA[<p>When I write a program I like to include a build number in the version.  Usually I go <strong>version.revision.build</strong>.  The version only ever gets bumped for things that are practically a complete rewrite, and sometimes not even then.  The revision gets bumped for new features or major bug fixes and the build gets bumped for every compile.</p>
<p>This gives the huge of advantage of being able to identify the exact time a particular version of a program was created and thus make bug finding easier.</p>
<p>For compiled code this works really well, I just have the build process increment the number somehow.  For interpreted code, such as python, however there is no build process.  So how do I make sure the build number gets incremented every time?  There is no way I would remember to increment it manually.</p>
<p>When I was using subversion I hacked something together using <em>$LastChangedRevision$</em>, so the build number was based on the most recent svn commit number.  It worked well enough and I was happy.</p>
<p>Now however I&#8217;m switching to git, which doesn&#8217;t have keywords like CVS and Subversion so I&#8217;m a bit stumped.  I tried hacking a script that auto-increments a number then runs a <em>git commit</em>, but not only is it logically flawed, but it relies on me remembering to run it rather than direct git commands which is never going to be reliable.</p>
<p>Maybe I could do something with the current date, but again that would rely on me running something.  Probably repo hooks are the answer somehow but I&#8217;ve no idea how.  The build no. itself needs to be stored in git so as to sync between computers.  Can a git repo hook update a file then commit that update back to itself automatically (without an infinite recursion destroying the repo)?</p>
<p>Update (2009-04-05):  I&#8217;ve worked out how to generate an auto-incrementing number via git hooks.  Use the following script as a pre-commit hook (save as .git/hooks/pre-commit).  It&#8217;s setup for python but it could easily be adapted for whatever language you need.</p>
<div class="dean_ch" style="white-space: nowrap;">
<span class="re3">#!/bin/bash</span><br />
<span class="re3">#</span><br />
<span class="re3"># Called by git-commit with no arguments. &nbsp;The hook should</span><br />
<span class="re3"># <span class="kw3">exit</span> with non-zero status after issuing an appropriate message if</span><br />
<span class="re3"># it wants to stop the commit.</span><br />
<span class="re3">#</span><br />
<span class="re3"># This script will automatically increment the __revision__ number in</span><br />
<span class="re3"># the <span class="kw2">file</span> version.py on every git commit.</span></p>
<p><span class="re2">f=</span><span class="st0">&quot;$GIT_DIR/../version.py&quot;</span></p>
<p><span class="re2">REVISION=</span>$<span class="br0">&#40;</span><span class="kw2">grep</span> <span class="st0">&#8216;^__revision__&#8217;</span> <span class="re1">$f</span> | <span class="kw2">sed</span> <span class="st0">&#8216;s/^__revision__ = //&#8217;</span><span class="br0">&#41;</span><br />
<span class="re3">#echo </span><span class="st0">&quot;Current revision = $REVISION&quot;</span><br />
<span class="kw3">let</span> <span class="re2">REVISION=</span><span class="re1">$REVISION</span><span class="nu0">+1</span><br />
<span class="re3">#echo </span><span class="st0">&quot;New revision = $REVISION&quot;</span><br />
<span class="kw2">sed</span> -r <span class="st0">&quot;s/^(__revision__ = )([0-9]+)$/<span class="es0">\1</span>$REVISION/&quot;</span> &lt; <span class="re1">$f</span> &gt; <span class="re1">$f</span>.new<br />
<span class="kw2">mv</span> <span class="re1">$f</span>.new <span class="re1">$f</span><br />
git add <span class="re1">$f</span><br />
&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.trollgod.org.uk/2009/04/build-numbers-in-interpreted-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving from svn to git</title>
		<link>http://blog.trollgod.org.uk/2009/03/moving-from-svn-to-git/</link>
		<comments>http://blog.trollgod.org.uk/2009/03/moving-from-svn-to-git/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 21:20:26 +0000</pubDate>
		<dc:creator>Ghworg</dc:creator>
				<category><![CDATA[Admin]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[versioncontrol]]></category>

		<guid isPermaLink="false">http://blog.trollgod.org.uk/?p=100</guid>
		<description><![CDATA[<p>I&#8217;ve spent most of the evening trying to figure out how to use git. For a long time I&#8217;ve wanted to have the repositories for some of my personal projects available on the web. For a time I was allowing external access to my apache internal apache server, but I&#8217;m wary about that because <span style="color:#777"> . . . &#8594; Read More: <a href="http://blog.trollgod.org.uk/2009/03/moving-from-svn-to-git/">Moving from svn to git</a></span>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent most of the evening trying to figure out how to use <a href="http://git-scm.com/about">git</a>.  For a long time I&#8217;ve wanted to have the repositories for some of my personal projects available on the web.  For a time I was allowing external access to my apache internal apache server, but I&#8217;m wary about that because I&#8217;m not confident about my ability to secure a box.</p>
<p>I was planning on setting subversion up on my <a href="http://www.dreamhost.com/">web host</a>, but I didn&#8217;t want to depend completely on that and mirroring subversion is non-trivial.  So today I decided to have a go at git, which is much more suited to this sort of thing.</p>
<p>Thankfully there is svn import capability built in to git, so converting my guinea-pig project over was a doddle.  Much more tricky was setting up all the syncing between the repos.  I think I have the magic incantations down now though.</p>
<pre>
git remote add NAME URL
git config branch.master.remote NAME
git config branch.master.merge refs/heads/master
</pre>
<p>I understand the first line, the other two <em>seem</em> to be necessary, but I don&#8217;t know exactly what they do yet.</p>
<p>Also, it is better to run <code>git pull</code> than <code>git push</code> when dealing with a destination that has checked out files as push doesn&#8217;t update them whilst pull does.</p>
<p>One thing that is a little weird is I can&#8217;t push changes from the live site to the public repo, which is on the same server.  But I can pull the changes down to my local machine then push back up to the public.  Tried a couple of different ways but all failed for one reason of another.</p>
<p>Treating the other repo as local throws up permissions issues, </p>
<pre>error: unable to create temporary sha1 filename</pre>
<pre>File exists</pre>
<p>, due to the way webdav is setup on dreamhost.  Treating it as remote (http) doesn&#8217;t work because the binary is compiled without curl support.  Still, the round-trip method works well enough.</p>
<p>I also installed <a href="http://git.or.cz/gitwiki/Gitweb">gitweb</a> and pointed it at the publicly accessable repo, this was very easy contrary to all the web pages I read about it.  Just name the config file gitweb_config.perl and tell it where to look for the git repos and away it went <img src='http://blog.trollgod.org.uk/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
<p><a href="http://git.trollgod.org.uk/">http://git.trollgod.org.uk/</a> is now available for anyone to view.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trollgod.org.uk/2009/03/moving-from-svn-to-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
