@@ -630,7 +630,9 @@ def parse_git_remote(string: str) -> t.List[str]:
630630 return repo_info [- 2 :]
631631
632632
633- def publish_to_ghpages (directory : Path , update_source : bool ) -> None :
633+ def publish_to_ghpages (
634+ directory : Path , update_source : bool , no_push : bool = False
635+ ) -> None :
634636 """
635637 Publish the current project to GitHub pages.
636638 """
@@ -666,13 +668,13 @@ def publish_to_ghpages(directory: Path, update_source: bool) -> None:
666668 repo .active_branch .rename ("main" )
667669 log .info ("Successfully initialized new Git repository!" )
668670 log .info ("" )
669- log .info (f"Preparing to deploy from active `{ repo .active_branch .name } ` git branch." )
670- log .info ("" )
671+ log .info (
672+ f"Preparing to deploy from active `{ repo .active_branch .name } ` git branch.\n "
673+ )
671674 if repo .bare or repo .is_dirty () or len (repo .untracked_files ) > 0 :
672675 log .info ("Changes to project source since last commit detected." )
673676 if update_source :
674- log .info ("Add/committing these changes to local Git repository." )
675- log .info ("" )
677+ log .info ("Committing these changes to local Git repository.\n " )
676678 repo .git .add (all = True )
677679 repo .git .commit (message = "Update to PreTeXt project source." )
678680 # Should we push this commit?
@@ -684,12 +686,10 @@ def publish_to_ghpages(directory: Path, update_source: bool) -> None:
684686 "Just deploying your built project will not save changes to your source on GitHub.`"
685687 )
686688 # Note, we no longer return here; continue with deployment even though repo isn't clean.
687-
688689 try :
689690 origin = repo .remotes .origin
690691 except AttributeError :
691- log .warning ("Remote GitHub repository is not yet configured." )
692- log .info ("" )
692+ log .warning ("Remote GitHub repository is not yet configured.\n " )
693693 log .info (
694694 "And if you haven't already, create a remote GitHub repository for this project at:"
695695 )
@@ -724,6 +724,7 @@ def publish_to_ghpages(directory: Path, update_source: bool) -> None:
724724 directory ,
725725 mesg = "Latest build deployed." ,
726726 nojekyll = True ,
727+ no_history = True ,
727728 )
728729 log .info (f"Attempting to connect to remote repository at `{ origin .url } `..." )
729730 # log.info("(Your SSH password may be required.)")
@@ -736,24 +737,37 @@ def publish_to_ghpages(directory: Path, update_source: bool) -> None:
736737 pages_url = f"https://{ repo_name } "
737738 else :
738739 pages_url = f"https://{ repo_user } .github.io/{ repo_name } /"
739- except Exception :
740+ except Exception as e :
740741 log .error (f"Unable to parse GitHub URL from { origin .url } " )
741742 log .error ("Deploy unsuccessful" )
743+ log .debug (e , exc_info = True )
742744 return
745+ # Stop here if we are not pushing to GitHub.
746+ if no_push :
747+ log .info (
748+ "Skipping push to GitHub. You can push manually with `git push origin gh-pages`."
749+ )
750+ log .info ("" )
751+ log .info ("Output committed to the `gh-pages` branch." )
752+ return
753+ # Otherwise we try to push to GitHub.
743754 try :
744755 origin .push (refspec = f"{ repo .active_branch .name } :{ repo .active_branch .name } " )
745756 origin .push (refspec = "gh-pages:gh-pages" )
746- except git .exc .GitCommandError : # type: ignore
757+ except git .exc .GitCommandError as e : # type: ignore
747758 log .warning (
748- f"There was an issue connecting to GitHub repository located at { repo_url } "
759+ f"There was an issue connecting to GitHub repository located at { repo_url } \n "
749760 )
750- log .info ( "" )
761+ log .debug ( e , exc_info = True )
751762 log .info (
752763 "Make sure you have set up authentication for GitHub. For more information, visit:"
753764 )
754765 log .info (" https://docs.github.com/en/authentication" )
755766 log .info (
756- "Make sure you can push changes, either from the command line or in VS Code. Then try to deploy again."
767+ "Make sure you can push changes, either from the command line or in VS Code. Then try to deploy again.\n "
768+ )
769+ log .info (
770+ "You can also try to run `pretext deploy --no-push` to skip this step, then switch to the `gh-pages` branch (using `git checkout gh-pages`) and push manually."
757771 )
758772 log .info ("" )
759773 log .info (f"(If `{ origin .url } ` doesn't match your GitHub repository," )
0 commit comments