Skip to content

Commit 00d14d3

Browse files
committed
Add the --show-git-push-stderr flag
Related #26
1 parent 7f8e9c0 commit 00d14d3

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changes
22
=======
33

4+
0.1.4 (unreleased)
5+
------------------
6+
7+
* Add the ``--show-git-push-stderr`` option to make deploy more verbose,
8+
this can help debug problems, but is potentially dangerous, hence the output
9+
of ``git push`` is hidden by default.
10+
11+
412
0.1.3
513
-----
614

elsa/_cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,12 @@ def freeze(path, base_url, serve, port, cname):
111111
@click.option('--freeze/--no-freeze', default=True,
112112
help='Whether to freeze the site before deploying, '
113113
'default is to freeze')
114+
@click.option('--show-git-push-stderr', is_flag=True,
115+
help='Show the stderr output of `git push` failure, '
116+
'might be dangerous if logs are public')
114117
@cname_option()
115-
def deploy(path, base_url, remote, push, freeze, cname):
118+
def deploy(path, base_url, remote, push, freeze,
119+
show_git_push_stderr, cname):
116120
"""Deploy the site to GitHub pages"""
117121
if push is None:
118122
warnings.simplefilter('always')
@@ -128,6 +132,6 @@ def deploy(path, base_url, remote, push, freeze, cname):
128132
inject_cname(app)
129133
freeze_app(app, freezer, path, base_url)
130134

131-
deploy_(path, remote=remote, push=push)
135+
deploy_(path, remote=remote, push=push, show_err=show_git_push_stderr)
132136

133137
return command()

elsa/_deployment.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def get_git_toplevel():
3535
return process.stdout.strip().decode('utf-8')
3636

3737

38-
def deploy(html_dir, *, remote, push):
38+
def deploy(html_dir, *, remote, push, show_err):
3939
"""Deploy to GitHub pages, expects to be already frozen"""
4040
if os.environ.get('TRAVIS'): # Travis CI
4141
print('Setting up git...')
@@ -66,11 +66,14 @@ def deploy(html_dir, *, remote, push):
6666
print('Pushing to GitHub...')
6767
try:
6868
run(['git', 'push', remote, 'gh-pages:gh-pages', '--force'],
69-
quiet=True)
69+
quiet=not show_err)
7070
except subprocess.CalledProcessError as e:
71-
msg = ('Error: git push failed (exit status {}).\n'
72-
'Note: Due to security constraints, Elsa does not show the '
73-
'error message from git, as it may include sensitive '
74-
'information and this could be logged.')
71+
msg = 'Error: git push failed (exit status {}).'
72+
if not show_err:
73+
msg += ('\nNote: Due to security constraints, Elsa does not '
74+
'show the error message from git, as it may include '
75+
'sensitive information and this could be logged. Use '
76+
'the --show-git-push-stderr switch to change this '
77+
'behavior.')
7578
print(msg.format(e.returncode), file=sys.stderr)
7679
sys.exit(e.returncode)

tests/test_commands.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,21 @@ def test_remote_not_displayed_when_pushing_fails(elsa, gitrepo, capsys):
398398
assert url not in err
399399

400400

401+
def test_push_error_displayed_when_explicitly_asked_for(elsa, gitrepo, capsys):
402+
url = 'https://example.com'
403+
run_cmd(['git', 'remote', 'set-url', 'origin', url])
404+
405+
capsys.readouterr() # flush
406+
407+
elsa.run('deploy', '--push', '--show-git-push-stderr', should_fail=True)
408+
out, err = capsys.readouterr()
409+
410+
print('OUT', out)
411+
print('ERR', err)
412+
assert url in err
413+
assert 'not found' in err
414+
415+
401416
def test_traceback_not_displayed_when_pushing_fails(elsa, gitrepo, capsys):
402417
run_cmd(['git', 'remote', 'set-url', 'origin', 'foo'])
403418
elsa.run('deploy', '--push', should_fail=True)

0 commit comments

Comments
 (0)