Skip to content

Commit

Permalink
Merge pull request #516 from mbacho/master
Browse files Browse the repository at this point in the history
Adding custom commit message option to gh_deploy
  • Loading branch information
d0ugal committed May 15, 2015
2 parents 667fc66 + 0d2c63b commit 93a181a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
7 changes: 7 additions & 0 deletions docs/user-guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ google_analytics: ['UA-36723568-3', 'mkdocs.org']
**default**: `null`


### remote_branch

Set the remote branch to commit to when using `gh-deploy` to update Github Pages. This option can be overriden by a commandline option in `gh-deploy`.

**default**: `gh-pages`


## Documentation layout

### pages
Expand Down
13 changes: 10 additions & 3 deletions mkdocs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def configure_logging(log_name='mkdocs', level=logging.INFO):
theme_choices = utils.get_theme_names()
site_dir_help = "The directory to output the result of the documentation build."
reload_help = "Enable and disable the live reloading in the development server."
commit_message_help = ("A commit message to use when commiting to the "
"Github Pages remote branch")
remote_branch_help = ("The remote branch to commit to for Github Pages. This "
"overrides the value specified in config")


@click.group()
Expand Down Expand Up @@ -120,13 +124,16 @@ def json_command(clean, config_file, strict, site_dir):
@cli.command(name="gh-deploy")
@click.option('--clean', is_flag=True, help=clean_help)
@click.option('--config-file', type=click.File('rb'), help=config_file_help)
def gh_deploy_command(config_file, clean):
@click.option('--message', '-m', help=commit_message_help)
@click.option('--remote-branch', '-b', help=remote_branch_help)
def gh_deploy_command(config_file, clean, message, remote_branch):
"""Deply your documentation to GitHub Pages"""
config = load_config(
config_file=config_file
config_file=config_file,
remote_branch=remote_branch
)
build.build(config, clean_site_dir=clean)
gh_deploy.gh_deploy(config)
gh_deploy.gh_deploy(config, message=message)


@cli.command(name="new")
Expand Down
3 changes: 3 additions & 0 deletions mkdocs/config/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,7 @@
# MkDocs itself. A good example here would be including the current
# project version.
('extra', config_options.Type(dict, default={})),

# the remote branch to commit to when using gh-deploy
('remote_branch', config_options.Type(str, default='gh-pages')),
)
17 changes: 11 additions & 6 deletions mkdocs/gh_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@
log = logging.getLogger(__name__)


def gh_deploy(config):
def gh_deploy(config, message=None):

if not os.path.exists('.git'):
log.info('Cannot deploy - this directory does not appear to be a git '
'repository')
return

log.info("Copying '%s' to `gh-pages` branch and pushing to GitHub.",
config['site_dir'])
command = ['ghp-import', '-p', config['site_dir']]

command.extend(['-b', config['remote_branch']])

if message is not None:
command.extend(['-m', message])

log.info("Copying '%s' to '%s' branch and pushing to GitHub.",
config['site_dir'], config['remote_branch'])

try:
command = ['ghp-import', '-p', config['site_dir']]
if 'remote_branch' in config:
command.extend(['-b', config['remote_branch']])
subprocess.check_call(command)
except Exception:
return
Expand Down

0 comments on commit 93a181a

Please sign in to comment.