Show Your GIT Branch Name In Your Prompt

Typing git branch over and over to see what branch you are on sucks. Sure, you could argue that you should always KNOW what branch you're currently working on. And if you did, you would obviously not be a git user.

Bouncing around branches can be pretty common, and I know I've messed some things up pretty bad not knowing what branch I was on.

So set up your shell to always put the name of the current branch into your prompt.

function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
 
function proml {
  local        BLUE="\[\033[0;34m\]"
  local         RED="\[\033[0;31m\]"
  local   LIGHT_RED="\[\033[1;31m\]"
  local       GREEN="\[\033[0;32m\]"
  local LIGHT_GREEN="\[\033[1;32m\]"
  local       WHITE="\[\033[1;37m\]"
  local  LIGHT_GRAY="\[\033[0;37m\]"
  case $TERM in
    xterm*)
    TITLEBAR='\[\033]0;\u@\h:\w\007\]'
    ;;
    *)
    TITLEBAR=""
    ;;
  esac
 
PS1="${TITLEBAR}\
$BLUE[$RED\$(date +%H:%M)$BLUE]\
$BLUE[$RED\u@\h:\w$GREEN\$(parse_git_branch)$BLUE]\
$GREEN\$ "
PS2='> '
PS4='+ '
}
proml

Pastie Link

Put this at the top of your .bash_profile and you'll be pimping your branch all over.

Thanks to @defunkt for this.

Popularity: 25% [?]

    Categories: GIT, Snippets     4 Comments »

Cleanly Migrate Your Subversion Repository To a GIT Repository

So you're ready to ride the GIT train eh? But what about all those projects in your subversion repository? Sure you could just use git-svn but what you really want is to cleanly move that repository and all its history to a nice new GIT repository.

Luckily it's not that hard. For this example I'm going to use my_blog as the application name you're porting to a GIT repository. We're basically going to just initialize a new GIT repository, point it at your SVN repository, and suck in your code and history while remapping the users to GIT users. We'll then just clone THAT repository to have a clean GIT repository free of SVN clutter.

The first thing we need to do is create a users file that maps all your SVN users to your GIT users. Just make a file on your Desktop named 'users.txt'. Map the users using this format:

jmaddox = Jon Maddox <jon@gmail.com>
bigpappa = Brian Biggs <bigpappa@gmail.com>

Simple. Now here are the commands you'll run. I'll explain them below.

mkdir my_blog_tmp
cd my_blog_tmp
git-svn init http://code.yoursite.net/my_blog/trunk/ --no-metadata
git config svn.authorsfile ~/Desktop/users.txt
git-svn fetch

The first two are self explanatory, we're making a new directory for the temporary repository. The second command initializes the directory as a git-svn hybrid thing and points the origin at your SVN repository. The flag, --no-metadata, tells GIT to leave all the SVN details behind (not the commit log). The fourth command tells GIT to remap all the SVN users to GIT users when it sucks down the source and history. The last command actually does the fetching.

Ok, so now after a few LONG minutes, your source is all there. Do a git log to see that your users have been mapped. Sweet!

Now you just have one last step. You need to clone this repository. Why do we do this? When doing a normal git clone it will take everything we want from the temporary repository, while leaving behind all the SVN cruft that was there to support the git-svn stuff.

git clone my_blog_tmp my_blog

Boom! You're done. Now you have a super clean GIT repository all ready to use.

Popularity: 54% [?]

    Categories: GIT, Snippets     17 Comments »

Spec Out Your Cookies with Rspec

Here's something that got me this weekend and I couldn't find much info on it anywhere. So like my Internet taught me, I'm sharing.

links_controller.rb
cookies[:phone] = params[:phone]
links_controller_spec.rb
it "should save the phone number in a cookie" do
  @my_cookies = mock('cookies')
  @my_cookies.stub!(:[]=)
  controller.stub!(:cookies).and_return(@my_cookies)
 
  @my_cookies.should_receive(:[]=).with(:phone, '804-755-7555')
 
  do_post
end

Here I'm making the expectation that a cookie will be set with the key of 'phone' and a value of a passed in parameter. My do_post method takes care of the post and passes in the parameter :phone => '804-755-7555'.

Popularity: 14% [?]

    Categories: Rails, Snippets, Testing     No Comments »

Use Your Basecamp Feed Under Leopard’s Mail.app

Ok, here's another tip for Leopard. I may need to add a new category to this weblog, or maybe just stop spamming my dev blog with these posts. But I will argue that these are all tools that us web devs use.

I have a lot of feeds, and I like to use them in different ways. My basecamp is one of those feeds that isn't so much information based, as much as it is notification based. Because of this, I want to use it in Mail.app.

Simple enough, ok... add feed, and... oh wait a second...

Sweet. Thanks Apple. You were smart enough to know the feed was protected by http auth, but not cool enough to prompt me for the username/password combo.

This solution might be obvious to some, but not to others, so I thought I'd post it anyways. To get your feed working, just overload the URL with your username and password.

http://myusername:mypassword@company.projectpath.com

Mail.app will pull in your feed as normal. But what if you're a hipster using openid!? Click to the My Info section of Basecamp and you'll find a whole section devoted to this. Basically, you'll use your openid as a username and Basecamp provides you with some kind of hashed password.

http://jonmaddox.myopenid.com:34kjlk3kk3kl3jkl43@company.projectpath.com

Yeah, simple, but someone's gonna get stuck.

Popularity: 10% [?]

    Categories: Snippets     2 Comments »

Flush your DNS Cache in Leopard

As a web dev, you may spend some time messing with DNS and overriding it. Though, it can get annoying when you can't get things back to the way that mere mortals see things on the internet.

lookupd -flushcache was a big tool in my arsenal in Tiger. But Leopard put a rightful end to lookupd, but left us without our known way of flushing the cache.

For the last couple of weeks its been pretty annoying, but I'm here to bring you, the NEW way to flush dns cache for OS X users!!! Holy crap this is exciting.

So it's as simple as this:


dscacheutil -flushcache

There you have it.

Popularity: 19% [?]

    Categories: Snippets     8 Comments »