Fixes for branch support in deploy script.
authordsc <dsc@wikimedia.org>
Thu, 17 May 2012 18:37:30 +0000 (11:37 -0700)
committerdsc <dsc@wikimedia.org>
Thu, 17 May 2012 18:37:30 +0000 (11:37 -0700)
fabfile/__init__.py
fabfile/deploy.py
fabfile/stages.py
fabfile/util.py

index 60acf02..ad21357 100644 (file)
@@ -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',
 ))
index 6f7e6cb..961e84d 100644 (file)
@@ -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
index 21ba7d2..78da700 100644 (file)
@@ -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']
 
index c5e7ef5..30bd1a3 100644 (file)
@@ -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):