From f2142495e9138f247d6db65cbc4c5b6211902a95 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Sun, 25 May 2014 11:00:15 +0530 Subject: [PATCH] Exit github_deploy if output folder is committed on source branch. --- nikola/plugins/command/github_deploy.py | 34 ++++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/nikola/plugins/command/github_deploy.py b/nikola/plugins/command/github_deploy.py index 782e119a10..e9ef48b976 100644 --- a/nikola/plugins/command/github_deploy.py +++ b/nikola/plugins/command/github_deploy.py @@ -50,13 +50,15 @@ class CommandGitHubDeploy(Command): It performs the following actions: 1. Ensure that your site is a git repository, and git is on the PATH. - 2. Check for changes, and prompt the user to continue, if required. - 3. Build the site - 4. Clean any files that are "unknown" to Nikola. - 5. Create a deploy branch, if one doesn't exist. - 6. Commit the output to this branch. (NOTE: Any untracked source + 2. Ensure that the output directory is not committed on the + source branch. + 3. Check for changes, and prompt the user to continue, if required. + 4. Build the site + 5. Clean any files that are "unknown" to Nikola. + 6. Create a deploy branch, if one doesn't exist. + 7. Commit the output to this branch. (NOTE: Any untracked source files, may get committed at this stage, on the wrong branch!) - 7. Push and deploy! + 8. Push and deploy! NOTE: This command needs your site to be a git repository, with a master branch (or a different branch, configured using @@ -91,6 +93,8 @@ def _execute(self, command, args): self._ensure_git_repo() + self._exit_if_output_committed() + if not self._prompt_continue(): return @@ -229,6 +233,24 @@ def _ensure_git_repo(self): ) sys.exit(1) + def _exit_if_output_committed(self): + """ Exit if the output folder is committed on the source branch. """ + + source = self._source_branch + subprocess.check_call(['git', 'checkout', source]) + + output_folder = self.site.config['OUTPUT_FOLDER'] + output_log = subprocess.check_output( + ['git', 'ls-files', '--', output_folder] + ) + + if len(output_log.strip()) > 0: + self.logger.error( + 'Output folder is committed on the source branch. ' + 'Cannot proceed until it is removed.' + ) + sys.exit(1) + def _prompt_continue(self): """ Show uncommitted changes, and ask if user wants to continue. """