Source

django-environments / scripts / djenv.mercurial

Full commit
#
# Mercurial utilities for django-environments
# 

export hgpidfile=$PROJECT_ROOT/tmp/hgserve.pid
export hgport=7100

# Start hg server in daemon mode and open first argument in browser
function hgserve() {
    kill -0 `cat $hgpidfile 2>&1` > /dev/null 2>&1
    if [ ! $? -eq 0 ]; then
        cwd=`pwd`
        cdjango
        hg serve --port $hgport --daemon \
            --pid-file $PROJECT_ROOT/tmp/hgserve.pid
        sleep 0.5
        cd $cwd
    fi

    [ ! -z "$1" ] && open http://localhost:$hgport/$1
}

function hgbrowse() {
    hgserve

    path=file/tip`echo \`pwd\` | sed "s#$PROJECT_ROOT##"`
    [ ! -z "$1" ] && path=$path/$1

    open http://localhost:$hgport/$path
}

# Shutdown hg server
function hgkill() {
    kill -9 `cat $hgpidfile 2>&1` > /dev/null 2>&1
    if [ ! $? -eq 0 ]; then
        echo Server not running or other error 2>&1
    fi
}

# Runs an hg command on all hg repositories in the externals directory,
# e.g. 'hgexternals pull -u'
function hgexternals {
    for external in $PROJECT_ROOT/externals/*; do
        if [ -d $external/.hg ]; then
            echo `basename $external`:
            IFS=''
            hg -R $external $*
            echo
        fi
    done
}

# Pull and update the project and all Mercurial externals
function hgfetchall() {
    hg -R $PROJECT_ROOT pull -u
    echo
    hgexternals pull -u
}

# List all .orig files
function hgfindorig() {
    find $PROJECT_ROOT -name \*.orig -l
}

# List all .orig files
function hgremoveorig {
    find $PROJECT_ROOT -name \*.orig -print -delete
}