diff --git a/ognibuild/dist.py b/ognibuild/dist.py index abdfacf..fc70ccb 100644 --- a/ognibuild/dist.py +++ b/ognibuild/dist.py @@ -152,6 +152,7 @@ def create_dist( ) -> Optional[str]: from .buildsystem import detect_buildsystems from .buildlog import InstallFixer + from .fixers import GitIdentityFixer if subdir is None: subdir = "package" @@ -166,7 +167,7 @@ def create_dist( # TODO(jelmer): use scan_buildsystems to also look in subdirectories buildsystems = list(detect_buildsystems(export_directory)) resolver = auto_resolver(session) - fixers = [InstallFixer(resolver)] + fixers = [InstallFixer(resolver), GitIdentityFixer(session)] with DistCatcher(export_directory) as dc: session.chdir(reldir) diff --git a/ognibuild/fixers.py b/ognibuild/fixers.py new file mode 100644 index 0000000..2a37773 --- /dev/null +++ b/ognibuild/fixers.py @@ -0,0 +1,41 @@ +#!/usr/bin/python3 +# Copyright (C) 2020 Jelmer Vernooij +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +import subprocess +from typing import Tuple + +from buildlog_consultant import Problem +from buildlog_consultant.common import ( + MissingGitIdentity, + ) + + +class GitIdentityFixer(object): + + def __init__(self, session): + self.session = session + + def can_fix(self, problem: Problem): + return isinstance(problem, MissingGitIdentity) + + def _fix(self, problem: Problem, phase: Tuple[str, ...]): + for name in ['user.email', 'user.name']: + value = subprocess.check_output( + ['git', 'config', '--global', name]).decode().strip() + self.session.check_call( + ['git', 'config', '--global', 'user.email', value]) + return True