This is a small instruction guide for installing git-dude on OSX. Git dude is a convenient git repo monitoring service.
Ensure you have Homebrew installed.
Install growlnotify via brew install growlnotify
.
If you are a Lion user and are getting No formula available
, then you can just
download growlnotify as a package
If you are a Snow Leopard user, See this gist on getting growlnotify to play nicely.
Install git-dude via brew install https://raw.github.com/gist/1289314/git-dude.rb --HEAD
Make a ~/.git-dude
directory where we will store repo mirrors for git-dude to monitor.
$ mkdir ~/.git-dude
$ cd ~/.git-dude
Clone a directory using the --mirror
tag.
$ git clone --mirror git://github.com/username/yourrepo.git
Append the following convenience function to your ~/.bashrc
# Git dude repo monitoring service
# arg1: "stop" or "start"
function gd(){
val="$1"
if [ $val == "start" ]; then
git dude ~/.git-dude &>/dev/null &
printf "git-dude started\n"
elif [ $val == "stop" ]; then
ps aux | grep 'git[ -]dude' | awk '{print $2}' | xargs sudo kill -9
printf "git-dude stopped\n"
else
printf "$val not valid. Use start/stop\n"
fi
}
Now reload your ~/.bashrc
and start git-dude! You should push to your repo
to test it out.
$ source ~/.bashrc
$ gd start
To stop git-dude, just run gd stop
For configuration options ,including images and checking intervals, check out the git-dude readme
Currently, you must execute gd start
every time you log in if you want to monitor
repos. I find this a bit cumbersome. To avoid such a cumbersome task, we will take
advantage of OS X's Login Hooks.
Running git-dude as part of the login hook implies running git-dude as root. Consequently,
we have to take some precautions. A huge issue is that the FETCH_HEAD
file needed by
git-dude is not created until the first time you run git fetch
on a repo. In the event
that the root user is the one who first runs git fetch
through git-dude, FETCH_HEAD will
belong to root and will thus not be usable by the script!
To avoid this, we create a convenience function that will create a mirrored clone of a
repo and immediately run git fetch
on it. Append the following to your ~/.bashrc
# Create a new repo clone and immediately fetch to avoid
# permission issue with root when running in the background
# arg1: repo URL
function watch_repo(){
# The folder where git-dude watches repos
gitDudeWatchFolder=~/.git-dude
cd $gitDudeWatchFolder
repoURL=$1
git clone --mirror $repoURL
# Get the directory of the repo just pulled
repoDir=$(basename $repoURL)
# We need to `git fetch` immediately so that FETCH_HEAD is owned by the
# user and NOT by root when running is a login hook
cd $repoDir
git fetch
cd $gitDudeWatchFolder
echo "Now watching $repoDir"
}
Remember to load the ~/.bashrc
file into your session.
$ source ~/.bashrc
Now if you want to clone a repo for the purpose of watching it through git-dude, all you have to do is
$ watch_repo git://github.com/joequery/Rails-Template.git
If you're going to use the Login Hook to run git-dude upon login, you MUST create your repos with the provided bash function.
Now we actually create the login hook...
Change to your /Library
directory and make a Hooks
directory.
$ cd /Library
$ mkdir Hooks
$ cd Hooks
Now create a file called login
in your favorite text editor.
$ vim login
Paste the following into the login
file and save.
#!/bin/bash
/path/to/git dude /Users/YourUser/.git-dude &>/dev/null &
You can find your /path/to/git
via
$ which git
NOTE: It's important that you reference absolute paths in your login
script.
Now we need to make this login
file executable.
$ chmod +x login
We now add the script to the login hook.
$ sudo defaults write com.apple.loginwindow LoginHook /Library/Hooks/login
Note that this modifies the /var/root/Library/Preferences/com.apple.loginwindow file
if you ever want to undo it.
Feel free to log out and log back in. To check and see if the git-dude
process is
running, you can search for the process via
$ ps aux | grep "git-dude"
Enjoy your repo monitoring!