From 00d14d385422c5354b59c954bcda6159ac3e32b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Fri, 23 Jun 2017 17:01:35 +0200 Subject: [PATCH] Add the --show-git-push-stderr flag Related https://github.com/pyvec/elsa/issues/26 --- CHANGELOG.rst | 8 ++++++++ elsa/_cli.py | 8 ++++++-- elsa/_deployment.py | 15 +++++++++------ tests/test_commands.py | 15 +++++++++++++++ 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e46329f..57712ff 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,14 @@ Changes ======= +0.1.4 (unreleased) +------------------ + +* Add the ``--show-git-push-stderr`` option to make deploy more verbose, + this can help debug problems, but is potentially dangerous, hence the output + of ``git push`` is hidden by default. + + 0.1.3 ----- diff --git a/elsa/_cli.py b/elsa/_cli.py index 31aa817..b668898 100644 --- a/elsa/_cli.py +++ b/elsa/_cli.py @@ -111,8 +111,12 @@ def freeze(path, base_url, serve, port, cname): @click.option('--freeze/--no-freeze', default=True, help='Whether to freeze the site before deploying, ' 'default is to freeze') + @click.option('--show-git-push-stderr', is_flag=True, + help='Show the stderr output of `git push` failure, ' + 'might be dangerous if logs are public') @cname_option() - def deploy(path, base_url, remote, push, freeze, cname): + def deploy(path, base_url, remote, push, freeze, + show_git_push_stderr, cname): """Deploy the site to GitHub pages""" if push is None: warnings.simplefilter('always') @@ -128,6 +132,6 @@ def deploy(path, base_url, remote, push, freeze, cname): inject_cname(app) freeze_app(app, freezer, path, base_url) - deploy_(path, remote=remote, push=push) + deploy_(path, remote=remote, push=push, show_err=show_git_push_stderr) return command() diff --git a/elsa/_deployment.py b/elsa/_deployment.py index eea9a94..edde649 100644 --- a/elsa/_deployment.py +++ b/elsa/_deployment.py @@ -35,7 +35,7 @@ def get_git_toplevel(): return process.stdout.strip().decode('utf-8') -def deploy(html_dir, *, remote, push): +def deploy(html_dir, *, remote, push, show_err): """Deploy to GitHub pages, expects to be already frozen""" if os.environ.get('TRAVIS'): # Travis CI print('Setting up git...') @@ -66,11 +66,14 @@ def deploy(html_dir, *, remote, push): print('Pushing to GitHub...') try: run(['git', 'push', remote, 'gh-pages:gh-pages', '--force'], - quiet=True) + quiet=not show_err) except subprocess.CalledProcessError as e: - msg = ('Error: git push failed (exit status {}).\n' - 'Note: Due to security constraints, Elsa does not show the ' - 'error message from git, as it may include sensitive ' - 'information and this could be logged.') + msg = 'Error: git push failed (exit status {}).' + if not show_err: + msg += ('\nNote: Due to security constraints, Elsa does not ' + 'show the error message from git, as it may include ' + 'sensitive information and this could be logged. Use ' + 'the --show-git-push-stderr switch to change this ' + 'behavior.') print(msg.format(e.returncode), file=sys.stderr) sys.exit(e.returncode) diff --git a/tests/test_commands.py b/tests/test_commands.py index 1fa709d..73180ee 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -398,6 +398,21 @@ def test_remote_not_displayed_when_pushing_fails(elsa, gitrepo, capsys): assert url not in err +def test_push_error_displayed_when_explicitly_asked_for(elsa, gitrepo, capsys): + url = 'https://example.com' + run_cmd(['git', 'remote', 'set-url', 'origin', url]) + + capsys.readouterr() # flush + + elsa.run('deploy', '--push', '--show-git-push-stderr', should_fail=True) + out, err = capsys.readouterr() + + print('OUT', out) + print('ERR', err) + assert url in err + assert 'not found' in err + + def test_traceback_not_displayed_when_pushing_fails(elsa, gitrepo, capsys): run_cmd(['git', 'remote', 'set-url', 'origin', 'foo']) elsa.run('deploy', '--push', should_fail=True)