Skip to content

Commit

Permalink
Exit github_deploy if output folder is committed on source branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
punchagan committed May 25, 2014
1 parent 5170ea0 commit f214249
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions nikola/plugins/command/github_deploy.py
Expand Up @@ -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
Expand Down Expand Up @@ -91,6 +93,8 @@ def _execute(self, command, args):

self._ensure_git_repo()

self._exit_if_output_committed()

if not self._prompt_continue():
return

Expand Down Expand Up @@ -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. """

Expand Down

0 comments on commit f214249

Please sign in to comment.