Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ script:
python -m doctr deploy --no-require-master --command "echo test; ls; touch docs/_build/html/test" docs;
# Test syncing a tracked file with a change
python -m doctr deploy --sync . --built-docs test;
python -m doctr deploy --deploy-repo drdoctr/drdoctr.github.io docs;
fi
- if [[ "${TESTS}" == "true" ]]; then
pyflakes doctr;
Expand Down
2 changes: 1 addition & 1 deletion doctr/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def deploy(args, parser):
if args.deploy_branch_name:
deploy_branch = args.deploy_branch_name
else:
deploy_branch = 'master' if deploy_dir.endswith(('.github.io', '.github.com')) else 'gh-pages'
deploy_branch = 'master' if deploy_repo.endswith(('.github.io', '.github.com')) else 'gh-pages'

current_commit = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('utf-8').strip()
try:
Expand Down
40 changes: 25 additions & 15 deletions doctr/travis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

from cryptography.fernet import Fernet

DOCTR_WORKING_BRANCH = '__doctr_working_branch'

def decrypt_file(file, key):
"""
Decrypts the file ``file``.
Expand Down Expand Up @@ -242,15 +244,19 @@ def checkout_deploy_branch(deploy_branch, canpush=True):
Checkout the deploy branch, creating it if it doesn't exist.
"""
#create empty branch with .nojekyll if it doesn't already exist
new_deploy_branch = create_deploy_branch(deploy_branch, push=canpush)
print("Checking out {}".format(deploy_branch))
local_deploy_branch_exists = deploy_branch in subprocess.check_output(['git', 'branch']).decode('utf-8').split()
if new_deploy_branch or local_deploy_branch_exists:
run(['git', 'checkout', deploy_branch])
else:
run(['git', 'checkout', '-b', deploy_branch, '--track', 'doctr_remote/{}'.format(deploy_branch)])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this still automatically create gh-pages on the remote if it doesn't exist?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if I understand correctly that part happens in create_deploy_branch which is still called, just above the first line I touched. To be clear I have not tested that; I just don't think the behavior had changed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I was wrong about that -- it did not successfully create a master branch if one did not exist -- but that is fixed in 8007280, which I think will pass once it runs in context where it's allowed to push.

create_deploy_branch(deploy_branch, push=canpush)
print("Checking out doctr working branch tracking doctr_remote/{}".format(deploy_branch))
clear_working_branch()
run(['git', 'checkout', '-b', DOCTR_WORKING_BRANCH, '--track', 'doctr_remote/{}'.format(deploy_branch)])
print("Done")

return canpush

def clear_working_branch():
local_branch_names = subprocess.check_output(['git', 'branch']).decode('utf-8').split()
if DOCTR_WORKING_BRANCH in local_branch_names:
run(['git', 'branch', '-D', DOCTR_WORKING_BRANCH])

def deploy_branch_exists(deploy_branch):
"""
Check if there is a remote branch with name specified in ``deploy_branch``.
Expand All @@ -277,20 +283,24 @@ def create_deploy_branch(deploy_branch, push=True):
Return True if ``deploy_branch`` was created, False if not.
"""
if not deploy_branch_exists(deploy_branch):
print("Creating {} branch".format(deploy_branch))
run(['git', 'checkout', '--orphan', deploy_branch])
print("Creating {} branch on doctr_remote".format(deploy_branch))
clear_working_branch()
run(['git', 'checkout', '--orphan', DOCTR_WORKING_BRANCH])
# delete everything in the new ref. this is non-destructive to existing
# refs/branches, etc...
run(['git', 'rm', '-rf', '.'])
print("Adding .nojekyll file to {} branch".format(deploy_branch))
print("Adding .nojekyll file to working branch")
run(['touch', '.nojekyll'])
run(['git', 'add', '.nojekyll'])
run(['git', 'commit', '-m', 'Create new {} branch with .nojekyll'.format(deploy_branch)])
if push:
print("Pushing {} branch to remote".format(deploy_branch))
run(['git', 'push', '-u', 'doctr_remote', deploy_branch])
# return to master branch
run(['git', 'checkout', '-'])
print("Pushing working branch to remote {} branch".format(deploy_branch))
run(['git', 'push', '-u', 'doctr_remote', '{}:{}'.format(DOCTR_WORKING_BRANCH, deploy_branch)])
# return to master branch and clear the working branch
run(['git', 'checkout', 'master'])
run(['git', 'branch', '-D', DOCTR_WORKING_BRANCH])
# fetch the remote so that doctr_remote/{deploy_branch} is resolved
run(['git', 'fetch', 'doctr_remote'])

return True
return False
Expand Down Expand Up @@ -448,7 +458,7 @@ def push_docs(deploy_branch='gh-pages', retries=3):
print("Pulling")
code = run(['git', 'pull', '-s', 'recursive', '-X', 'ours', 'doctr_remote', deploy_branch])
print("Pushing commit")
code = run(['git', 'push', '-q', 'doctr_remote', deploy_branch], exit=False)
code = run(['git', 'push', '-q', 'doctr_remote', '{}:{}'.format(DOCTR_WORKING_BRANCH, deploy_branch)])
if code:
retries -= 1
print("Push failed, retrying")
Expand Down