lib/pvl/commit/hg.sh
author Tero Marttila <tero.marttila@aalto.fi>
Thu, 26 Feb 2015 21:38:09 +0200
changeset 627 a81206440be2
parent 619 lib/update.hg@bed4765fc56f
child 629 7214fe5c6fac
permissions -rw-r--r--
(none)
605
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
     1
# HG wrappers
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
     2
627
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
     3
HG=/usr/bin/hg
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
     4
HG_ARGS=(--config trusted.users=root)
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
     5
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
     6
function hg_probe {
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
     7
    local repo=$1
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
     8
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
     9
    [ -d "$repo/.hg" ]
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
    10
}
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
    11
605
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    12
## Run `hg ...` within $REPO.
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    13
function hg {
627
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
    14
    local repo=$1
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
    15
    cmd $HG -R "$repo" "${HG_ARGS[@]:-}" "${@:2}"
605
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    16
}
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    17
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    18
## Does the repo have local modifications?
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    19
function hg_modified {
618
a756f317d083 update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents: 612
diff changeset
    20
    hg $1 id -i | grep -q '+'
a756f317d083 update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents: 612
diff changeset
    21
}
a756f317d083 update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents: 612
diff changeset
    22
a756f317d083 update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents: 612
diff changeset
    23
## Get the date for the current commit as an unix timestamp
a756f317d083 update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents: 612
diff changeset
    24
function hg_time {
a756f317d083 update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents: 612
diff changeset
    25
    local repo=$1
a756f317d083 update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents: 612
diff changeset
    26
    local hg_unix=
a756f317d083 update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents: 612
diff changeset
    27
    local hg_tz=
a756f317d083 update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents: 612
diff changeset
    28
a756f317d083 update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents: 612
diff changeset
    29
    local hg_date=$(hg $repo log -r . --template '{date|hgdate}')
a756f317d083 update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents: 612
diff changeset
    30
    local hg_unix=${hg_date% *}
a756f317d083 update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents: 612
diff changeset
    31
    local hg_tz=${hg_date#* }
a756f317d083 update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents: 612
diff changeset
    32
a756f317d083 update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents: 612
diff changeset
    33
    [ -n "$hg_unix" ] || fail "failed to read hg time"
a756f317d083 update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents: 612
diff changeset
    34
a756f317d083 update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents: 612
diff changeset
    35
    echo "$hg_unix"
605
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    36
}
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    37
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    38
## Show changes in repo
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    39
#   hg_diff     [path ...]
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    40
function hg_diff {
627
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
    41
    local repo=$1
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
    42
    hg $repo diff "${@:2}"
605
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    43
}
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    44
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    45
## Commit changes in repo, with given message:
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    46
#
619
bed4765fc56f fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents: 618
diff changeset
    47
#   hg_commit   .../etc $msg
605
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    48
#
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    49
# Automatically determines possible -u to use when running with sudo.
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    50
function hg_commit {
619
bed4765fc56f fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents: 618
diff changeset
    51
    local repo="$1"
bed4765fc56f fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents: 618
diff changeset
    52
    local msg="$2"
627
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
    53
    local opts=()
605
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    54
619
bed4765fc56f fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents: 618
diff changeset
    55
    if [ ${SUDO_USER:-} ]; then
627
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
    56
        opts+=('-u' "$SUDO_USER")
619
bed4765fc56f fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents: 618
diff changeset
    57
bed4765fc56f fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents: 618
diff changeset
    58
    elif [ $HOME ] && [ -e $HOME/.hgrc ]; then
bed4765fc56f fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents: 618
diff changeset
    59
        debug "using .hgrc user"
bed4765fc56f fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents: 618
diff changeset
    60
bed4765fc56f fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents: 618
diff changeset
    61
    else
627
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
    62
        opts+=('-u' "$USER")
619
bed4765fc56f fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents: 618
diff changeset
    63
    fi
605
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    64
    
619
bed4765fc56f fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents: 618
diff changeset
    65
    if [ "$msg" ]; then
627
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
    66
        opts+=('-m' "$msg")
619
bed4765fc56f fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents: 618
diff changeset
    67
    fi
bed4765fc56f fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents: 618
diff changeset
    68
   
627
Tero Marttila <tero.marttila@aalto.fi>
parents: 619
diff changeset
    69
    hg $repo commit "${opts[@]:-}"
605
26a307558602 update update
Tero Marttila <terom@paivola.fi>
parents:
diff changeset
    70
}