view .shell.d/50.hg_functions.sh @ 210:0590f34b92a0

shell.d: split hg and git functions out of vcs functions
author Augie Fackler <durin42@gmail.com>
date Sun, 16 May 2010 20:43:00 -0500
parents .shell.d/50.vcs_functions.sh@9e45ac5350fd
children 0c8939baa35c
line wrap: on
line source

## hg_functions
# various hg utility functions

function mq () {
    ( wcroot ;
       hg -R .hg/patches $@
     )
}

function mq-snapshot () {
    mq ci -m "Applied on $(hg log -r qparent --template '{node|short}\n')"
}

function hgsvnmergebranch() {
    local targetrev
    local striprev
    targetrev=$(hg id | cut -d ' ' -f 1)
    hg merge $1
    hg ci -m "Merging $1"
    striprev=$(hg id | cut -d ' ' -f 1)
    hg co $targetrev
    hg diff -r$targetrev:$striprev | hg import - -m "Merged branch $1."
    hg strip $striprev
}
alias hg-svn-merge-branch=hgsvnmergebranch

function hgsvnrebaseall() {
    for b in `hg log -u 'Augie Fackler <durin42@gmail.com>' --template '{branches}\n' | sort | uniq`
    do
        echo "rebase $b"
        hg co $b
        if [[ "$?" != "0" ]] ; then
            echo "abort: could not checkout $b"
            return
        fi
        hg parent --svn > /dev/null
        if [[ "$?" == "0" ]] ; then
            hg rebase --svn || return
        else
            echo "Skip $b since it has a merge."
        fi
    done
}
alias hg-svn-rebase-all=hgsvnrebaseall

function hgamend() {
    hg qimport -r . && hg qref && hg qfin qtip
}
alias hg-amend=hgamend

function hg_verify_all() {
  for x in $(find . -name '.hg') ; do
    y=$(dirname $x)
    echo $y
    hg verify -R $y
  done
}

function hgsvnmkbranch() {
    local upstream
    upstream=$(hg paths default | sed 's%/*$%%')
    local branchname
    if [ "x$1" = "x" ] ; then
        echo 'Must provide new branch name.'
        return 1
    fi
    local d=`hg svn info | grep URL | sed 's/.*://'`
    local br=`echo $d | awk '{
            if ( index($1, "trunk") ) {
                    print  "trunk"
                } else {
                    x = index($1, "branches") ;
                    if ( x != 0 ) {
                            sub(".*/branches/", "");
                            sub("/.*", "");
                            print $0
                        }
                }
                }'`

    branchname=$br
    echo svn cp $upstream/$branchname $upstream/branches/$1
}
alias hg-svn-mkbranch=hgsvnmkbranch