Skip to content
This repository has been archived by the owner on Jul 11, 2019. It is now read-only.

Commit

Permalink
repo_update will now ask user permission to stash changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lnielsen committed Nov 14, 2012
1 parent ff1b5e0 commit 839bd2f
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/inveniofab/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
make on it.
"""

from fabric.api import task, puts, env, settings, local, abort
from fabric.api import task, puts, env, settings, local, abort, hide
from fabric.contrib.console import confirm
from fabric.colors import cyan, red
import os
Expand Down Expand Up @@ -121,7 +121,7 @@ def repo_update(**kwargs):
ref = kwargs[repo]
if not ref:
ref = None
repo_refs.append(repo, ref)
repo_refs.append((repo, ref))
del kwargs[repo]
else:
try:
Expand Down Expand Up @@ -229,7 +229,19 @@ def git_newworkdir(repo):
local("%(CFG_INVENIO_PREFIX)s/bin/git-new-workdir %(srcdir)s %(srcworkdir)s" % ctx)


def git_isdirty(dir):
"""
Check working directory for uncommitted changes
"""
with settings(hide('everything'), warn_only=True):
output = local("cd %s && git diff-index --exit-code HEAD --" % dir, capture=True)
return output.return_code != 0


def git_checkout(repo, ref):
"""
Checkout a specific git reference.
"""
topsrcdir = repo_check(repo, workdir=True)

ctx = {
Expand All @@ -238,8 +250,14 @@ def git_checkout(repo, ref):
}
ctx.update(env)

# Stash away any uncomitted changes
local("cd %(topsrcdir)s; if ! git diff-index --quiet HEAD --; then git stash; fi; git checkout -f %(ref)s" % ctx)
# Stash uncommited changes
if git_isdirty(topsrcdir):
if not confirm("Working directory %(topsrcdir)s contains uncommited changes. Do you want to stash the changes (required to continue)?" % ctx ):
abort("Cannot continue unless uncommitted changes are stashed")
else:
local("cd %(topsrcdir)s; git stash" % ctx)

local("cd %(topsrcdir)s; git checkout -f %(ref)s" % ctx)


def git_clone(repo):
Expand Down

0 comments on commit 839bd2f

Please sign in to comment.