Skip to content

Commit

Permalink
Merge pull request #21 from dploi/feature/git-helpers
Browse files Browse the repository at this point in the history
Feature/git helpers
  • Loading branch information
Tom Berger committed Jan 14, 2015
2 parents 6306d6b + 0842fa7 commit 253504a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
26 changes: 23 additions & 3 deletions dploi_fabric/git.py
@@ -1,5 +1,5 @@
from fabric.operations import run, prompt
from fabric.api import task, env, get, put
from fabric.api import task, env, get, put, local
from fabric.contrib.files import exists
import ConfigParser
import StringIO
Expand All @@ -10,6 +10,7 @@
from .messages import CAUTION
from .utils import config


@task
def update():
test = run("cd %(path)s; git --no-pager diff --stat" % env)
Expand All @@ -26,10 +27,10 @@ def update():
download_diff = prompt("What do you want to do?", default="D")
if download_diff.lower() == "d":
diff = run(("cd %(path)s; git diff --color .") % env)
for i in range(1,50):
for i in range(1, 50):
print
print diff
for i in range(1,5):
for i in range(1, 5):
print
exit()
elif download_diff.lower() == "e":
Expand All @@ -44,14 +45,17 @@ def update():
run("cd %(path)s; git submodule update" % env)
append_settings()


@task
def diff(what=''):
run(("cd %(path)s; git --no-pager diff " + what) % env)


@task
def status():
run("cd %(path)s; git status" % env)


@task
def reset():
"""
Expand All @@ -60,6 +64,7 @@ def reset():
run("cd %(path)s; find . -iname '*.pyc' -delete" % env)
run("cd %(path)s; git reset --hard HEAD" % env)


@task
def incoming(remote='origin', branch=None):
"""
Expand All @@ -68,3 +73,18 @@ def incoming(remote='origin', branch=None):
if not branch:
branch = env.branch
run(("cd %(path)s; git fetch " + remote + " && git log --oneline .." + remote + '/' + branch) % env)


def local_branch_is_dirty(ignore_untracked_files=True):
untracked_files = '--untracked-files=no' if ignore_untracked_files else ''
git_status = local(
'git status %s --porcelain' % untracked_files, capture=True)
return git_status != ''


def local_branch_matches_remote():
local_branch = local(
'git rev-parse --symbolic-full-name --abbrev-ref HEAD',
capture=True).strip()
target_branch = env.branch.strip()
return local_branch == target_branch
21 changes: 19 additions & 2 deletions dploi_fabric/utils.py
Expand Up @@ -9,8 +9,9 @@
from fabric.state import _AttributeDict


from dploi_fabric.toolbox.datastructures import EnvConfigParser
from dploi_fabric.messages import DOMAIN_DICT_DEPRECATION_WARNING
from .toolbox.datastructures import EnvConfigParser
from .messages import DOMAIN_DICT_DEPRECATION_WARNING


STATIC_COLLECTED = "../static/"
DATA_DIRECTORY = "../upload/"
Expand Down Expand Up @@ -570,3 +571,19 @@ def safe_put(*args, **kwargs):
if dst_path:
run('mkdir -p {}'.format(os.path.dirname(dst_path)))
return put(*args, **kwargs)


@task
def gulp_deploy(css_dir='private', *args, **kwargs):
# Import here to avoid circular references
from .git import local_branch_is_dirty, local_branch_matches_remote

if local_branch_is_dirty() or not local_branch_matches_remote():
print ("Please make sure that local branch is not dirty and "
"matches the remote (deployment) branch.")
else:
print "Preparing files (CSS/JS)"
local('compass compile {}'.format(css_dir))
# Replace compass with 'gulp' when front-end is ready
upload_media('./static/css/', '../static/css/')
upload_media('./static/js/', '../static/js/')

0 comments on commit 253504a

Please sign in to comment.