Skip to content

Commit

Permalink
Add the --show-git-push-stderr flag
Browse files Browse the repository at this point in the history
Related #26
  • Loading branch information
hroncok committed Jun 23, 2017
1 parent 7f8e9c0 commit 00d14d3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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
-----

Expand Down
8 changes: 6 additions & 2 deletions elsa/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()
15 changes: 9 additions & 6 deletions elsa/_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...')
Expand Down Expand Up @@ -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)
15 changes: 15 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 00d14d3

Please sign in to comment.