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.
master
Simon McVittie 2015-11-30 19:34:04 +00:00
parent 719612a976
commit ed1e1ebe70
3 changed files with 40 additions and 0 deletions

View File

@ -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;
}

3
debian/changelog vendored
View File

@ -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

View File

@ -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"