Set author/committer name/email from dotfiles.
authorIain Patterson <me@iain.cx>
Tue, 6 Jan 2015 10:25:15 +0000 (10:25 +0000)
committerIain Patterson <me@iain.cx>
Wed, 7 Jan 2015 09:22:07 +0000 (09:22 +0000)
Read author name from .git_author_name and author email from
.git_author_email.  Read committer name and email from
.git_commiter_name and .git_committer_email.

Fall back to author name/email if committer name/email is undefined.

Look in HOME first then PROFILE_HOME, unlike many other profile scripts
which override settings in HOME with PROFILE_HOME.

.profile.d/git-commit-tree.bashrc [new file with mode: 0644]

diff --git a/.profile.d/git-commit-tree.bashrc b/.profile.d/git-commit-tree.bashrc
new file mode 100644 (file)
index 0000000..37ec8eb
--- /dev/null
@@ -0,0 +1,39 @@
+# Set GIT_AUTHOR_NAME etc from dotfiles in the profile.
+function git_commit_tree() {
+  local WHO=$1; shift
+  local who=${WHO,,}
+  local WHAT=
+
+  for WHAT in EMAIL NAME; do
+    local what=${WHAT,,}
+    local where=
+
+    # Look in $HOME then $PROFILE_HOME.
+    for where in '~' '$PROFILE_HOME'; do
+      eval local value=\$\(\<${where}/".git_${who}_${what}"\) 2>/dev/null
+
+      if [ -z "$value" ]; then
+        # COMMITTER defaults to AUTHOR.
+        if [ "$WHO" = "COMMITTER" ]; then
+          eval value="\$GIT_AUTHOR_${WHAT}"
+        fi
+
+        # Fall back to generic file.
+        if [ -z "$value" ]; then
+            eval value=\$\(\<\$${where}/".git_${what}"\) 2>/dev/null
+        fi
+      fi
+
+      if [ -n "$value" ]; then
+        eval export "GIT_${WHO}_${WHAT}=\$value"
+        # Skip next location.
+        break
+      fi
+    done
+  done
+}
+
+git_commit_tree AUTHOR
+git_commit_tree COMMITTER
+
+unset git_commit_tree