From 6ae35cb21eb6734700334c0c846003db844d9ae0 Mon Sep 17 00:00:00 2001 From: dsc Date: Thu, 17 May 2012 11:37:30 -0700 Subject: [PATCH] Fixes for branch support in deploy script. --- fabfile/__init__.py | 2 +- fabfile/deploy.py | 7 ++++++- fabfile/stages.py | 6 +----- fabfile/util.py | 19 ++++++++++++++++++- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/fabfile/__init__.py b/fabfile/__init__.py index 60acf02..ad21357 100644 --- a/fabfile/__init__.py +++ b/fabfile/__init__.py @@ -54,7 +54,7 @@ defaults(env, dict( browserify_js = 'vendor/browserify.js', work_browserify_js = '%(work_dir)s/%(browserify_js)s', - vendor_search_dirs = ['static', 'var', '%(work_dir)s'] + vendor_search_dirs = ['static', 'var', '%(work_dir)s'], vendor_bundle = '%(work_dir)s/vendor/vendor-bundle.min.js', app_bundle = '%(work_dir)s/js/kraken/app-bundle.js', )) diff --git a/fabfile/deploy.py b/fabfile/deploy.py index 6f7e6cb..961e84d 100644 --- a/fabfile/deploy.py +++ b/fabfile/deploy.py @@ -56,7 +56,9 @@ def checkout(): # TODO: Locally saved data files will cause yelling? with cd(env.target_dir): run('git fetch --all') - run('git checkout --track origin/%(git_branch)s' % env) + opts = {'track' : '--track' if env.git_branch not in branches() else ''} + opts.update(env) + run('git checkout %(track)s origin/%(git_branch)s' % opts) @task @expand_env @@ -79,6 +81,9 @@ def sync_files(): local("rsync -Crz -v %(work_dir)s %(user)s@%(host)s:%(target_dir)s/" % env) # TODO: make sure the following works. # rsync_project(local_dir=env.work_dir, remote_dir="%(user)s@%(host)s:%(target_dir)s/" % env) + + # Remove derived files to ensure they get regenerated + run('rm -rf %(target_dir)s/var' % env) @task @expand_env diff --git a/fabfile/stages.py b/fabfile/stages.py index 21ba7d2..78da700 100644 --- a/fabfile/stages.py +++ b/fabfile/stages.py @@ -60,10 +60,6 @@ def ensure_stage(fn): return wrapper -def working_branch(): - "Determines the working branch." - return [ branch.split()[1] for branch in local('git branch', capture=True).split('\n') if '*' in branch ][0] - def check_branch(fn): "Decorator that ensures deploy branch matches current branch." @@ -146,5 +142,5 @@ def lessly(): env.git_branch = 'develop' env.owner = 'wmf' env.group = 'www' - del env['gateway'] + if 'gateway' in env: del env['gateway'] diff --git a/fabfile/util.py b/fabfile/util.py index c5e7ef5..30bd1a3 100644 --- a/fabfile/util.py +++ b/fabfile/util.py @@ -10,7 +10,7 @@ from fabric.api import * from fabric.colors import white, blue, cyan, green, yellow, red, magenta __all__ = ( - 'quietly', 'msg', 'coke', 'update_version', + 'quietly', 'msg', 'branches', 'working_branch', 'coke', 'update_version', 'defaults', 'expand', 'expand_env', 'format', 'expand_env', ) @@ -46,6 +46,23 @@ def msg(txt, quiet=False): return outer + +### Git Integration + +def branches(remotes=False, all=False): + "List of git branchs." + opts = { + 'remotes' : '--remotes' if remotes else '', + 'all' : '--all' if all else '' + } + return [ branch.strip().split()[-1] for branch in local('git branch %(remotes)s %(all)s' % opts, capture=True).split('\n') ] + +def working_branch(): + "Determines the working branch." + return [ branch.split()[1] for branch in local('git branch', capture=True).split('\n') if '*' in branch ][0] + + + ### Coke Integration def coke(args, capture=False): -- 1.7.0.4