diff --git a/securedrop/i18n_tool.py b/securedrop/i18n_tool.py index bebdcdc78a..cf1900b9a3 100755 --- a/securedrop/i18n_tool.py +++ b/securedrop/i18n_tool.py @@ -255,6 +255,15 @@ def set_translate_desktop_parser(self, subps): self.set_translate_parser(subps, parser, translations_dir, sources) parser.set_defaults(func=self.translate_desktop) + @staticmethod + def require_git_email_name(git_dir): + cmd = ('git -C {d} config --get user.name > /dev/null && ' + 'git -C {d} config --get user.email > /dev/null'.format( + d=git_dir)) + if subprocess.call(cmd, shell=True): # nosec + raise Exception(cmd + ' returned false, please set name and email') + return True + def update_docs(self, args): l10n_content = '.. GENERATED BY i18n_tool.py DO NOT EDIT:\n\n' for (code, info) in sorted(I18NTool.SUPPORTED_LANGUAGES.items()): @@ -262,6 +271,7 @@ def update_docs(self, args): includes = join(args.documentation_dir, 'includes') l10n_txt = join(includes, 'l10n.txt') open(l10n_txt, 'w').write(l10n_content) + self.require_git_email_name(includes) if self.file_is_modified(l10n_txt): sh(""" set -ex @@ -334,6 +344,7 @@ def add(p): self.upstream_commit(args, code) def upstream_commit(self, args, code): + self.require_git_email_name(args.root) authors = set() for path in sh("git -C {r} diff --name-only --cached".format( r=args.root)).split(): diff --git a/securedrop/tests/test_i18n_tool.py b/securedrop/tests/test_i18n_tool.py index 9d2f48963d..2264c4d5bc 100644 --- a/securedrop/tests/test_i18n_tool.py +++ b/securedrop/tests/test_i18n_tool.py @@ -215,6 +215,21 @@ def test_translate_messages_compile_arg(self, tmpdir): assert 'code hello i18n' in mo assert 'template hello i18n' not in mo + def test_require_git_email_name(self, tmpdir): + i18n_tool.sh(""" + cd {dir} + git init + """.format(dir=str(tmpdir))) + with pytest.raises(Exception) as excinfo: + i18n_tool.I18NTool.require_git_email_name(str(tmpdir)) + assert 'please set name' in excinfo.value.message + i18n_tool.sh(""" + cd {dir} + git config user.email "you@example.com" + git config user.name "Your Name" + """.format(dir=str(tmpdir))) + assert i18n_tool.I18NTool.require_git_email_name(str(tmpdir)) + def test_update_docs(self, tmpdir, caplog): os.makedirs(join(str(tmpdir), 'includes')) i18n_tool.sh("""