author | Tero Marttila <terom@paivola.fi> |
Sun, 22 Dec 2013 18:22:37 +0200 | |
changeset 99 | 934aab83b769 |
parent 96 | bed4765fc56f |
permissions | -rw-r--r-- |
82 | 1 |
#!/bin/bash |
2 |
# |
|
3 |
# HG wrappers |
|
4 |
||
5 |
## Run `hg ...` within $REPO. |
|
6 |
function hg { |
|
89
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
82
diff
changeset
|
7 |
local repo=$1; shift |
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
82
diff
changeset
|
8 |
cmd $HG -R "$repo" "${HG_ARGS[@]}" "$@" |
82 | 9 |
} |
10 |
||
11 |
## Does the repo have local modifications? |
|
12 |
function hg_modified { |
|
95
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
13 |
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:
89
diff
changeset
|
14 |
} |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
15 |
|
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
16 |
## 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:
89
diff
changeset
|
17 |
function hg_time { |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
18 |
local repo=$1 |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
19 |
local hg_unix= |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
20 |
local hg_tz= |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
21 |
|
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
22 |
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:
89
diff
changeset
|
23 |
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:
89
diff
changeset
|
24 |
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:
89
diff
changeset
|
25 |
|
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
26 |
[ -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:
89
diff
changeset
|
27 |
|
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
28 |
echo "$hg_unix" |
82 | 29 |
} |
30 |
||
31 |
## Show changes in repo |
|
32 |
# hg_diff [path ...] |
|
33 |
function hg_diff { |
|
89
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
82
diff
changeset
|
34 |
local repo=$1; shift |
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
82
diff
changeset
|
35 |
hg $repo diff "$@" |
82 | 36 |
} |
37 |
||
38 |
## Commit changes in repo, with given message: |
|
39 |
# |
|
96
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
40 |
# hg_commit .../etc $msg |
82 | 41 |
# |
42 |
# Automatically determines possible -u to use when running with sudo. |
|
43 |
function hg_commit { |
|
96
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
44 |
local repo="$1" |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
45 |
local msg="$2" |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
46 |
local user_opt= |
82 | 47 |
local msg_opt= |
48 |
||
96
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
49 |
if [ ${SUDO_USER:-} ]; then |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
50 |
user_opt=('-u' "$SUDO_USER") |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
51 |
|
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
52 |
elif [ $HOME ] && [ -e $HOME/.hgrc ]; then |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
53 |
debug "using .hgrc user" |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
54 |
user_opt=( ) |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
55 |
|
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
56 |
else |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
57 |
user_opt=('-u' "$USER") |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
58 |
fi |
82 | 59 |
|
96
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
60 |
if [ "$msg" ]; then |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
61 |
msg_opt=('-m' "$msg") |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
62 |
fi |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
63 |
|
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
64 |
# XXX: there's something about bash arrays that I don't like... empty arrays behave badly |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
65 |
# mercurial does not like it if you pass it '' as an argument |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
66 |
if [ -n "${user_opt:-}" -a -n "${msg_opt:-}" ]; then |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
67 |
hg $repo commit "${user_opt[@]}" "${msg_opt[@]}" |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
68 |
elif [ -n "${user_opt:-}" ]; then |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
69 |
hg $repo commit "${user_opt[@]}" |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
70 |
elif [ -n "${msg_opt:-}" ]; then |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
71 |
hg $repo commit "${msg_opt[@]}" |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
72 |
else |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
73 |
hg $repo commit |
bed4765fc56f
fix hg commit message argument passing
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
74 |
fi |
82 | 75 |
} |