605
|
1 |
#!/bin/bash
|
|
2 |
#
|
|
3 |
# HG wrappers
|
|
4 |
|
|
5 |
## Run `hg ...` within $REPO.
|
|
6 |
function hg {
|
|
7 |
cmd $HG "${HG_ARGS[@]}" "$@"
|
|
8 |
}
|
|
9 |
|
|
10 |
## Does the repo have local modifications?
|
|
11 |
function hg_modified {
|
|
12 |
hg id | grep -q '+'
|
|
13 |
}
|
|
14 |
|
|
15 |
## Output possible -u flag for commit.
|
|
16 |
function hg_user {
|
|
17 |
if [ ${SUDO_USER:-} ]; then
|
|
18 |
echo '-u' "$SUDO_USER"
|
|
19 |
|
|
20 |
elif [ $HOME ] && [ -e $HOME/.hgrc ]; then
|
|
21 |
debug "using .hgrc user"
|
|
22 |
echo ''
|
|
23 |
|
|
24 |
else
|
|
25 |
echo '-u' "$USER"
|
|
26 |
fi
|
|
27 |
}
|
|
28 |
|
|
29 |
## Show changes in repo
|
|
30 |
# hg_diff [path ...]
|
|
31 |
function hg_diff {
|
|
32 |
hg diff "$@"
|
|
33 |
}
|
|
34 |
|
|
35 |
## Commit changes in repo, with given message:
|
|
36 |
#
|
|
37 |
# hg_commit $msg
|
|
38 |
#
|
|
39 |
# Automatically determines possible -u to use when running with sudo.
|
|
40 |
function hg_commit {
|
|
41 |
local msg=$1; shift
|
|
42 |
local user_opt=$(hg_user)
|
|
43 |
local msg_opt=
|
|
44 |
|
|
45 |
[ $msg ] && msg_opt=('-m' "$msg")
|
|
46 |
|
|
47 |
debug "$user_opt: $msg"
|
|
48 |
hg commit ${user_opt[@]} ${msg_opt[@]}
|
|
49 |
}
|
|
50 |
|
|
51 |
|