Category Archives: ubuntu / debian / linux

Notification when maven build finishes

Maven builds often take some time. This often causes me to start doing something else (read mail, browse web), which makes me unaware of when the build completes and I can continue working.

There should be a way to fix this. On Ubuntu, you get notifications when mail arrives, when network is up/down etc. Why not use this same system to get notifications when the maven build completes.

Maven notification window

Maven notification window

You can do this by adding the following in your ~/.bash_aliases file:

alias maven="command mvn"
notified_maven() {
  maven $* ; notify-send --icon=message-im "mvn" "build finished"    
}
alias mvn=notified_maven

Update
Thanks to Adrien, you can also use a more advanced version, showing the build result and maven parameters.

alias maven="command mvn"
notified_maven() {
  maven $* | \
  perl -pe'$m|=/BUILD .*SUCCESS/; END {exit!$m}' && \
  notify-send --icon=face-cool "`basename $(pwd)`: mvn $*" "Build SUCCESS" || \
  notify-send --icon=face-crying "`basename $(pwd)`: mvn $*" "Build FAILED"
}
alias mvn=notified_maven

Merging a git and mercurial project into one git repository

For this project the back-end was written in Java and stored in a mercurial (hg) repository, and the front-end was written in Ruby and stored in a git repository. To allow having branches across the project, we wanted to merge the two repositories into one. The target SCM was git.

In the result repository, there needed two be two subdirectories, back-end and front-end which contain the original projects.

Let’s start by converting the mercurial repository to a git:

git init back-end
cd back-end
hg-fast-export -r /path/to_hg/repo
git checkout 

Now move the contents into a subdirectory, rewriting history to preserve it:

git filter-branch --index-filter \
    'git ls-files -s | sed "s-\t\"*-&back-end/-" |
        GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
            git update-index --index-info &&
    mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD

This repository is now ready for merging.

cd ..

Now get the front-end repo and put its content in a subdirectory preserving history:

git clone <front-end-git-url> front-end
cd front-end
it filter-branch --index-filter \
    'git ls-files -s | sed "s-\t\"*-&front-end/-" |
        GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
            git update-index --index-info &&
    mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
cd ..

Now create a new repository for the combined project:

git init merged
cd merged
git pull ../back-end
git pull ../front-end

Done. Add the remote origin and push to finish.

Change bash prompt to include git or mercurial branch and dirty indicator

Thanks to my colleague @huugsy and Henrik Nuy. With some additions to include the same information for Mercurial.

Include the snippet below in your /etc/bash.bashrc file:

# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# Mercurial additions see http://blog.progs.be/?p=351
#
# joachim likes it like this:
# joachim:~/dev/dir[master]$ # clean working directory 
# joachim:~/dev/dir[master⚡]$ # dirty working directory
 
function parse_git_dirty {
  [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "⚡"
}
function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
 
function parse_hg_dirty {
  [[ $( hg status 2> /dev/null ) != "" ]] && echo "⚡"
}
function parse_hg_branch {
  hg branch 2> /dev/null | sed -e "s/\(.*\)/[\1$(parse_hg_dirty)]/"
}
 
 
export PS1='\u:\[\033[1;33m\]\w\[\033[0m\]$(parse_git_branch)$(parse_hg_branch)$ '

Do make sure you .gitignore or .hgignore file is complete or you will always see the dirty thunderbolt.