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-- |
605 | 1 |
# HG wrappers |
2 |
||
627 | 3 |
HG=/usr/bin/hg |
4 |
HG_ARGS=(--config trusted.users=root) |
|
5 |
||
6 |
function hg_probe { |
|
7 |
local repo=$1 |
|
8 |
||
9 |
[ -d "$repo/.hg" ] |
|
10 |
} |
|
11 |
||
605 | 12 |
## Run `hg ...` within $REPO. |
13 |
function hg { |
|
627 | 14 |
local repo=$1 |
15 |
cmd $HG -R "$repo" "${HG_ARGS[@]:-}" "${@:2}" |
|
605 | 16 |
} |
17 |
||
18 |
## Does the repo have local modifications? |
|
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 | 36 |
} |
37 |
||
38 |
## Show changes in repo |
|
39 |
# hg_diff [path ...] |
|
40 |
function hg_diff { |
|
627 | 41 |
local repo=$1 |
42 |
hg $repo diff "${@:2}" |
|
605 | 43 |
} |
44 |
||
45 |
## Commit changes in repo, with given message: |
|
46 |
# |
|
619
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
618
diff
changeset
|
47 |
# hg_commit .../etc $msg |
605 | 48 |
# |
49 |
# Automatically determines possible -u to use when running with sudo. |
|
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 | 53 |
local opts=() |
605 | 54 |
|
619
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
618
diff
changeset
|
55 |
if [ ${SUDO_USER:-} ]; then |
627 | 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 | 62 |
opts+=('-u' "$USER") |
619
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
618
diff
changeset
|
63 |
fi |
605 | 64 |
|
619
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
618
diff
changeset
|
65 |
if [ "$msg" ]; then |
627 | 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 | 69 |
hg $repo commit "${opts[@]:-}" |
605 | 70 |
} |