--- a/lib/update.hg Thu Dec 19 23:22:12 2013 +0200
+++ b/lib/update.hg Thu Dec 19 23:52:17 2013 +0200
@@ -28,20 +28,6 @@
echo "$hg_unix"
}
-## 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 {
@@ -51,17 +37,39 @@
## Commit changes in repo, with given message:
#
-# hg_commit $msg
+# hg_commit .../etc $msg
#
# Automatically determines possible -u to use when running with sudo.
function hg_commit {
- local repo=$1
- local msg=$2
- local user_opt=$(hg_user)
+ local repo="$1"
+ local msg="$2"
+ local user_opt=
local msg_opt=
- [ $msg ] && msg_opt=('-m' "$msg")
+ if [ ${SUDO_USER:-} ]; then
+ user_opt=('-u' "$SUDO_USER")
+
+ elif [ $HOME ] && [ -e $HOME/.hgrc ]; then
+ debug "using .hgrc user"
+ user_opt=( )
+
+ else
+ user_opt=('-u' "$USER")
+ fi
- debug "$user_opt: $msg"
- hg $repo commit ${user_opt[@]} ${msg_opt[@]}
+ if [ "$msg" ]; then
+ msg_opt=('-m' "$msg")
+ fi
+
+ # XXX: there's something about bash arrays that I don't like... empty arrays behave badly
+ # mercurial does not like it if you pass it '' as an argument
+ if [ -n "${user_opt:-}" -a -n "${msg_opt:-}" ]; then
+ hg $repo commit "${user_opt[@]}" "${msg_opt[@]}"
+ elif [ -n "${user_opt:-}" ]; then
+ hg $repo commit "${user_opt[@]}"
+ elif [ -n "${msg_opt:-}" ]; then
+ hg $repo commit "${msg_opt[@]}"
+ else
+ hg $repo commit
+ fi
}