lib/update.hg
author Tero Marttila <terom@paivola.fi>
Tue, 17 Dec 2013 00:04:00 +0200
branchdns-new
changeset 605 26a307558602
child 612 51270237a6ff
permissions -rw-r--r--
update update
#!/bin/bash
#
# HG wrappers

## Run `hg ...` within $REPO.
function hg {
    cmd $HG "${HG_ARGS[@]}" "$@"
}

## Does the repo have local modifications?
function hg_modified {
    hg id | grep -q '+'
}

## Output possible -u flag for commit.
function hg_user {
    if [ ${SUDO_USER:-} ]; then
        echo '-u' "$SUDO_USER"

    elif [ $HOME ] && [ -e $HOME/.hgrc ]; then
        debug "using .hgrc user"
        echo ''

    else
        echo '-u' "$USER"
    fi
}

## Show changes in repo
#   hg_diff     [path ...]
function hg_diff {
    hg diff "$@"
}

## Commit changes in repo, with given message:
#
#   hg_commit   $msg
#
# Automatically determines possible -u to use when running with sudo.
function hg_commit {
    local msg=$1; shift
    local user_opt=$(hg_user)
    local msg_opt=

    [ $msg ] && msg_opt=('-m' "$msg")
    
    debug "$user_opt: $msg"
    hg commit ${user_opt[@]} ${msg_opt[@]}
}