From ed1e1ebe70c8aec06a759d8cd0168f242d28ac17 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@debian.org>
Date: Mon, 30 Nov 2015 19:34:04 +0000
Subject: [PATCH] git: if no committer identity is known, set it to "IkiWiki
 <ikiwiki.info>" in .git/config

This resolves commit errors in versions of git that require a non-trivial
committer identity.
---
 IkiWiki/Plugin/git.pm | 31 +++++++++++++++++++++++++++++++
 debian/changelog      |  3 +++
 ikiwiki-makerepo      |  6 ++++++
 3 files changed, 40 insertions(+)

diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm
index 4d48388a0..38254d94a 100644
--- a/IkiWiki/Plugin/git.pm
+++ b/IkiWiki/Plugin/git.pm
@@ -220,6 +220,23 @@ sub run_or_die ($@) { safe_git(\&error, undef, @_) }
 sub run_or_cry ($@) { safe_git(sub { warn @_ }, undef, @_) }
 sub run_or_non ($@) { safe_git(undef, undef, @_) }
 
+my $ensured_committer;
+sub ensure_committer {
+	return if $ensured_committer;
+
+	my $name = join('', run_or_non("git", "config", "user.name"));
+	my $email = join('', run_or_non("git", "config", "user.email"));
+
+	if (! length $name) {
+		run_or_die("git", "config", "user.name", "IkiWiki");
+	}
+
+	if (! length $email) {
+		run_or_die("git", "config", "user.email", "ikiwiki.info");
+	}
+
+	$ensured_committer = 1;
+}
 
 sub merge_past ($$$) {
 	# Unlike with Subversion, Git cannot make a 'svn merge -rN:M file'.
@@ -258,6 +275,8 @@ sub merge_past ($$$) {
 	my @undo;      # undo stack for cleanup in case of an error
 	my $conflict;  # file content with conflict markers
 
+	ensure_committer();
+
 	eval {
 		# Hide local changes from Git by renaming the modified file.
 		# Relative paths must be converted to absolute for renaming.
@@ -526,6 +545,8 @@ sub rcs_get_current_rev () {
 sub rcs_update () {
 	# Update working directory.
 
+	ensure_committer();
+
 	if (length $config{gitorigin_branch}) {
 		run_or_cry('git', 'pull', '--prune', $config{gitorigin_branch});
 	}
@@ -569,6 +590,8 @@ sub rcs_commit_helper (@) {
 	
 	my %env=%ENV;
 
+	ensure_committer();
+
 	if (defined $params{session}) {
 		# Set the commit author and email based on web session info.
 		my $u;
@@ -631,6 +654,8 @@ sub rcs_add ($) {
 
 	my ($file) = @_;
 
+	ensure_committer();
+
 	run_or_cry('git', 'add', $file);
 }
 
@@ -639,12 +664,16 @@ sub rcs_remove ($) {
 
 	my ($file) = @_;
 
+	ensure_committer();
+
 	run_or_cry('git', 'rm', '-f', $file);
 }
 
 sub rcs_rename ($$) {
 	my ($src, $dest) = @_;
 
+	ensure_committer();
+
 	run_or_cry('git', 'mv', '-f', $src, $dest);
 }
 
@@ -944,6 +973,8 @@ sub rcs_revert ($) {
 	my $rev = shift;
 	my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint
 
+	ensure_committer();
+
 	if (run_or_non('git', 'revert', '--no-commit', $sha1)) {
 		return undef;
 	}
diff --git a/debian/changelog b/debian/changelog
index 03e3727f4..30878bb0a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -21,6 +21,9 @@ ikiwiki (3.20150615) UNRELEASED; urgency=medium
     non-git VCSs
   * debian/copyright: update for the rename of openid-selector to
     login-selector
+  * git: if no committer identity is known, set it to
+    "IkiWiki <ikiwiki.info>" in .git/config. This resolves commit errors
+    in versions of git that require a non-trivial committer identity.
 
  -- Simon McVittie <smcv@debian.org>  Mon, 15 Jun 2015 18:13:23 +0100
 
diff --git a/ikiwiki-makerepo b/ikiwiki-makerepo
index c3a13c214..f1c44067e 100755
--- a/ikiwiki-makerepo
+++ b/ikiwiki-makerepo
@@ -85,6 +85,12 @@ git)
 
 	cd "$srcdir"
 	git init
+	if [ -z "$(git config user.name)" ]; then
+		git config user.name IkiWiki
+	fi
+	if [ -z "$(git config user.email)" ]; then
+		git config user.email ikiwiki.info
+	fi
 	echo /.ikiwiki > .gitignore
 	git add .
 	git commit -m "initial commit"
-- 
2.39.5