Skip to content

Commit

Permalink
Merge pull request #16 from goerz/15-ignore-git-add
Browse files Browse the repository at this point in the history
Ignore git add
  • Loading branch information
goerz committed Mar 18, 2021
2 parents 63ec6aa + ef9e879 commit 28a23fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/doctr_versions_menu/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def write_versions_json(version_data, outfile, quiet=False):
json.dump(version_data, out_fh)
if not quiet:
print("version_data =", json.dumps(version_data, indent=2))
subprocess.run(['git', 'add', outfile], check=True)
subprocess.run(['git', 'add', outfile], check=False)


def _write_index_html(version_data):
Expand All @@ -45,7 +45,7 @@ def _write_index_html(version_data):
template = jinja2.Environment().from_string(template_str)
with open("index.html", "w") as out_fh:
out_fh.write(template.render(dict(version_data=version_data)))
subprocess.run(['git', 'add', 'index.html'], check=True)
subprocess.run(['git', 'add', 'index.html'], check=False)


def _write_versions_py():
Expand All @@ -69,7 +69,7 @@ def _write_versions_py():
out_fh.write("}\n")
else:
out_fh.write(line)
subprocess.run(['git', 'add', 'versions.py'], check=True)
subprocess.run(['git', 'add', 'versions.py'], check=False)


def _ensure_no_jekyll():
Expand All @@ -85,7 +85,7 @@ def _ensure_no_jekyll():
else:
logger.debug("creating %s", nojekyll)
nojekyll.touch()
subprocess.run(['git', 'add', str(nojekyll)], check=True)
subprocess.run(['git', 'add', str(nojekyll)], check=False)


class _MultipleTuple(click.Tuple):
Expand Down
21 changes: 21 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,27 @@ def test_default_run(caplog):
# fmt: on


def test_no_git_run(caplog):
"""Test doctr-versions-menu "default" run w/o git."""
root = Path(__file__).with_suffix('') / 'gh_pages_default'
runner = CliRunner()
caplog.set_level(logging.DEBUG)
with runner.isolated_filesystem():
cwd = Path.cwd()
# WE DO NOT RUN 'git init' HERE, SO WORKING DIR IS NOT A GIT REPO
copy_tree(str(root), str(cwd))
result = runner.invoke(doctr_versions_menu_command)
assert result.exit_code == 0
expected_files = [
'index.html',
'.nojekyll',
'versions.json',
'versions.py',
]
for file in expected_files:
assert (cwd / file).is_file()


def test_no_default_branch_run(caplog):
"""Test doctr-versions-menu "no_default_branch" run.
Expand Down

0 comments on commit 28a23fc

Please sign in to comment.