--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/pvl/commit/git.sh Thu Feb 26 22:36:05 2015 +0200
@@ -0,0 +1,60 @@
+# Git wrappers
+
+GIT=/usr/bin/git
+GIT_ARGS=()
+
+
+function git_probe {
+ local repo=$1
+
+ [ -d "$repo/.git" ]
+}
+
+## Run `git ...` within $REPO.
+function git {
+ local repo=$1
+ cmd $GIT -C "$repo" "${GIT_ARGS[@]:-}" "${@:2}"
+}
+
+## Does the repo have local modifications?
+function git_modified {
+ local repo=$1
+
+ git $repo diff --quiet
+}
+
+## Get the date for the current commit as an unix timestamp
+function hg_time {
+ local repo=$1
+
+ git $repo log -1 --format=format:%ct
+}
+
+## Show changes in repo
+# git_diff [path ...]
+function git_diff {
+ local repo=$1
+ git $repo diff --cached "$@"
+ git $repo diff "$@"
+}
+
+## Commit changes in repo, with given message:
+#
+# git_commit $repo $msg
+#
+# Automatically determines possible -u to use when running with sudo.
+function git_commit {
+ local repo="$1"
+ local msg="$2"
+ local opts=()
+
+ if [ ${SUDO_USER:-} ]; then
+ opts+=("--author=$SUDO_USER")
+ fi
+
+ if [ "$msg" ]; then
+ opts+=('-m' "$msg")
+ fi
+
+ git $repo commit -a "${opts[@]:-}"
+}