From: Simon McVittie Date: Mon, 26 Dec 2016 18:19:52 +0000 (+0000) Subject: git: if no committer identity is known, set it to "IkiWiki " in .git... X-Git-Tag: debian/3.20120629.2+deb7u2~31 X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/06710834bc2b81ea7f6f1195fbb69c499596cb04?ds=sidebyside git: if no committer identity is known, set it to "IkiWiki " in .git/config This resolves commit errors in versions of git that require a non-trivial committer identity. (cherry picked from commit ed1e1ebe70c8aec06a759d8cd0168f242d28ac17) --- diff --git a/IkiWiki/Plugin/git.pm b/IkiWiki/Plugin/git.pm index 75b89e476..8bf7ff690 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/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"