Subversioned $HOME

“Damn, what did I change last night in my dot.zshrc?”

I sat more than once at work thinking something like that, then copied my dot.zshrc
over with scp and merged the settings into my local copy, which tends to get annoying
when you have to do it a few times a week.

Thinking about that “problem” I came to the conclusion that I want to achive two goals:
>> have the configs wherever I am
>> have them in some version-control system

The solution to all that was my Subversion-Repository running on my webserver.
Reachable all over the world, with the just the need for some Subversion client.

To reach my goal I added the following piece of code into my ~/.zshrc, which should work in your ~/.bashrc as well.

## `svn` binary required
svn_bin=`which svn`
if [ -x ${svn_bin} ]; then

	## subversion settings
	svn_parm="--username SvnUser"
	svn_repos="http://www.domain.org/svn"
	svn_home_repos="${svn_repos}/Configs/User/SvnUser"

	## checkout, only needed for initial checkout, use update afterwards
	alias home_checkout="${svn_bin} ${svn_parm} checkout ${svn_home_repos} ${HOME}"

	## bring changes from repository into the working copy
	alias home_update="${svn_bin} ${svn_parm} update"

	## bring local changes into repository
	alias home_commit="${svn_bin} ${svn_parm} commit -m "" -N ${HOME}"

	## show status of files and/or trees under version control against the repository
	alias home_status="${svn_bin} ${svn_parm} status -u -q | sort '"

	## show local status of files and/or trees under version control
	alias home_lstatus="${svn_bin} ${svn_parm} status -q | sort "

	## show status of _all_ files and/or trees against the repository
	alias home_astatus="${svn_bin} ${svn_parm} status -u | sort | less"

	## put file/s or tree under version control
	alias home_add="${svn_bin} add $*"

	## remove file/s or tree from version control
	alias home_delete="${svn_bin} delete $*"

	## update ignore-properties from ignore-file and show them afterwards
	alias home_ignore="${svn_bin} propset svn:ignore -F ~/.subversion/ignore . \
				&& svn propget svn:ignore"

	## list which file/s or trees are currently ignored
	alias home_lignore="${svn_bin} propget svn:ignore"

fi

Ok, now let’s get through the stuff quickly.
First it checks if there’s the svn-binary available for execution, if unavailable we can omit all settings.
After that, there are the subversion settings which you have to edit to suit your needs.
I use the svn_repos for some other aliases too so I splitted it up into a base part (svn_repos) and the path
you want to store your $HOME-files in the repository (svn_home_repos).

Lets continue transforming your $HOME into a working repository directory.
We first create your $svn_home_repos as an empty directory and then check it out into
your $HOME. When that’s done, you can simply “add” all files or trees you
want to put under version-control.

## make sure you restarted your shell to reread your settings
$> svn mkdir $svn_home_repos \
	-m "Make a directory in the repository to correspond to \$HOME"

## enter your home directory
$> cd $HOME

## checkout the (empty) repository directory
$> home_checkout

## add files and/or trees
$> home_add .zshrc .vimrc .pinerc

## commit your changes into the directory
$> home_commit

If you want to check the status of your svn-controlled files do:

 $> home_status 

To get the status overview of all files in your $HOME do:

 $> home_astatus 

Running the “home_astatus” command will show you a bunch of files marked with “?”.
Thats subversions way to tell you that this file isn’t under version-control and that
it doesn’t know its status.
Maybe there are files or directories you (currently) don’t want to be under version-control.
Simply add them to “~/.subversion/ignore” and do

$> home_ignore
[...]
$> home_commit
[...]

## or run to change the ignores "by hand"
$> svn propedit svn:ignore .

You can always check which files/directories are ignored with:

 $> home_lignore 

Please be aware that running “home_ignore” will always change settings for “.” which
have to be commited afterwards.
Updating your $HOME to the latest revision is pretty easy too

$> home_update 

If you have problems or remarks for that quicky please drop me an email.

TODO:
	> how to merge other $HOMEs

URLs:
	> The Subversion book

Thanks to:
	> nXOR for debugging

By:
	> Michael 'buk' Scherer // 25.10.2004 19:36:01