Monday, April 21, 2008

Harvesting Fixtures from a Live Rails project

So I've put together a simple plugin for grabbing fixtures out of a Live Rails project.


Harvixture is a tool that can be used to extract data, in the form of fixtures,
from a Rails project. It is done by pointing the harvixture at a request_path
and dumping fixtures for all "found" ActiveRecord objects.

$ sudo gem install jeremyf-harvixture --source=http://gems.github.com/

$ cd path/to/rails/project

$ . harvixture run --request_path=/users/1/calendars./bug_100/users.yml
./bug_100/calendars.yml


Get the plugin here.
http://github.com/jeremyf/harvixture/tree/master

TODO:
- Possibly convert to a gem.

Monday, April 14, 2008

A little bash script hacking

Puttering around the blog-o-tubes, I discovered an awesome little post concerning git and your command line. The problem with the script is its too limiting. I use both svn and git. So enter my little hack.

In ~/.bashrc


function parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(git::\1)/'
}
function parse_svn_branch() {
parse_svn_url | sed -e 's#^'"$(parse_svn_repository_root)"'##g' | awk -F / '{print "(svn::"$1 "/" $2 ")"}'
}
function parse_svn_url() {
svn info 2>/dev/null | grep -e '^URL*' | sed -e 's#^URL: *\(.*\)#\1#g '
}
parse_svn_repository_root() {
svn info 2>/dev/null | grep -e '^Repository Root:*' | sed -e 's#^Repository Root: *\(.*\)#\1\/#g '
}
function parse_scm_branch() {
local value=$(parse_git_branch)
if [ -z "$value" ]; then
local value=$(parse_svn_branch)
fi
echo "$value"
}

export PS1="\[\033[00m\]\u@\h\[\033[01;34m\] \w \[\033[31m\]\$(parse_scm_branch) \[\033[00m\]$\[\033[00m\] "



For git directories

jeremyf@reclusive-geek ~/Documents/Repositories/git/ccs_portal (git::master) $


For svn directories

jeremyf@reclusive-geek ~/Documents/Repositories/svn/ccs_main/app/controllers (svn::ccs_main/trunk) $


If anyone knows how to tighten this script up, let me know.

Tuesday, April 08, 2008

git add --patch file.name

I would highly recommend reading http://tomayko.com/writings/the-thing-about-git, it highlights yet another awesome feature of git. Git lets you do your work how you do it, instead of how the SCM says you should. Here is a great example. I have a hopelessly muddled set of changes in file_the_other.txt. The changes are for two (or more) different purposes, and I need to only push a portion of it. Enter `git add --patch`. I can go through each diff element and select to put it in the queue (the Index) for what will be committed.



$ git add --patch file_the_other.txt
diff --git a/file_the_other.txt b/file_the_other.txt
index 2120d21..e3aa90d 100644
--- a/file_the_other.txt
+++ b/file_the_other.txt
@@ -1,3 +1,6 @@
+World is here
A file like another file, but with different content.

-There is even more content here.
\ No newline at end of file
+There is even more content here.
+
+Hello World
\ No newline at end of file
Stage this hunk [y/n/a/d/s/?]?