3636from .local import (generate_GitHub_token , encrypt_variable , encrypt_file ,
3737 upload_GitHub_deploy_key , generate_ssh_key , check_repo_exists , GitHub_login )
3838from .travis import (setup_GitHub_push , commit_docs , push_docs ,
39- get_current_repo , sync_from_log , find_sphinx_build_dir , run , get_travis_branch )
39+ get_current_repo , sync_from_log , find_sphinx_build_dir , run ,
40+ get_travis_branch , copy_to_tmp , checkout_deploy_branch )
4041from . import __version__
4142
4243def make_parser_with_config_adder (parser , config ):
@@ -152,6 +153,9 @@ def get_parser(config=None):
152153 conjunction with the --command flag, for instance, if the command syncs
153154 the files for you. Any files you wish to commit should be added to the
154155 index.""" )
156+ deploy_parser .add_argument ('--no-temp-dir' , dest = 'temp_dir' ,
157+ action = 'store_false' , default = True , help = """Don't copy the
158+ --built-docs directory to a temporary directory.""" )
155159 deploy_parser_add_argument ('--no-push' , dest = 'push' , action = 'store_false' ,
156160 default = True , help = "Run all the steps except the last push step. "
157161 "Useful for debugging" )
@@ -161,6 +165,7 @@ def get_parser(config=None):
161165 the first argument to 'doctr deploy'. This flag is kept for backwards
162166 compatibility.""" )
163167
168+
164169 if config :
165170 print ('Warning, The following options in `.travis.yml` were not recognized:\n %s' % json .dumps (config , indent = 2 ))
166171
@@ -249,14 +254,25 @@ def deploy(args, parser):
249254 branch_whitelist = {'master' } if args .require_master else set (get_travis_branch ())
250255 branch_whitelist .update (set (config .get ('branches' ,set ({}))))
251256
252- can_push = setup_GitHub_push (deploy_repo , deploy_branch = deploy_branch ,
257+ canpush = setup_GitHub_push (deploy_repo , deploy_branch = deploy_branch ,
253258 auth_type = 'token' if args .token else 'deploy_key' ,
254259 full_key_path = args .key_path ,
255260 branch_whitelist = branch_whitelist )
256261
262+ if args .command :
263+ run (args .command , shell = True )
264+
257265 if args .sync :
258266 built_docs = args .built_docs or find_sphinx_build_dir ()
267+ if args .temp_dir :
268+ built_docs = copy_to_tmp (built_docs )
269+
270+ # Reset in case there are modified files that are tracked in the
271+ # dpeloy branch.
272+ run (['git' , 'reset' , '--hard' ])
273+ checkout_deploy_branch (deploy_branch , canpush = canpush )
259274
275+ if args .sync :
260276 log_file = os .path .join (deploy_dir , '.doctr-files' )
261277
262278 print ("Moving built docs into place" )
@@ -266,14 +282,9 @@ def deploy(args, parser):
266282 else :
267283 added , removed = [], []
268284
269- if args .command :
270- run (['git' , 'checkout' , get_travis_branch ()])
271- run (args .command , shell = True )
272- run (['git' , 'checkout' , deploy_branch ])
273-
274285 changes = commit_docs (added = added , removed = removed )
275286 if changes :
276- if can_push and args .push :
287+ if canpush and args .push :
277288 push_docs (deploy_branch )
278289 else :
279290 print ("Don't have permission to push. Not trying." )
0 commit comments