lib/update.hg
branchdns-new
changeset 82 26a307558602
child 89 51270237a6ff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/update.hg	Tue Dec 17 00:04:00 2013 +0200
@@ -0,0 +1,51 @@
+#!/bin/bash
+#
+# HG wrappers
+
+## Run `hg ...` within $REPO.
+function hg {
+    cmd $HG "${HG_ARGS[@]}" "$@"
+}
+
+## Does the repo have local modifications?
+function hg_modified {
+    hg id | grep -q '+'
+}
+
+## 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 {
+    hg diff "$@"
+}
+
+## Commit changes in repo, with given message:
+#
+#   hg_commit   $msg
+#
+# Automatically determines possible -u to use when running with sudo.
+function hg_commit {
+    local msg=$1; shift
+    local user_opt=$(hg_user)
+    local msg_opt=
+
+    [ $msg ] && msg_opt=('-m' "$msg")
+    
+    debug "$user_opt: $msg"
+    hg commit ${user_opt[@]} ${msg_opt[@]}
+}
+
+