Skip to content

Commit

Permalink
git pulls devel repos on subsequent runs
Browse files Browse the repository at this point in the history
  • Loading branch information
nkakouros committed Mar 19, 2019
1 parent 6cdd0e5 commit ece086e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
26 changes: 15 additions & 11 deletions gilt/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ def clone(name, repository, destination, debug=False):
util.run_command(cmd, debug=debug)


def checkout(name, destination, version, debug=False):
def sync(name, destination, version, debug=False):
os.chdir(destination)
msg = ' - checking out {} at {}'.format(name, version)
msg = " - syncing {} with {} of origin".format(name, version)
util.print_info(msg)
cmd = sh.git.bake('checkout', version)
util.run_command(cmd, debug=debug)
_get_version(version, clean=False, debug=debug)


def remote_add(destination, name, url, debug=False):
Expand Down Expand Up @@ -86,7 +85,7 @@ def extract(repository, destination, version, debug=False):
shutil.rmtree(destination)

os.chdir(repository)
_get_version(version, debug)
_get_version(version, debug=debug)
cmd = sh.git.bake(
'checkout-index', force=True, all=True, prefix=destination)
util.run_command(cmd, debug=debug)
Expand All @@ -109,7 +108,7 @@ def overlay(repository, files, version, debug=False):
"""
with util.saved_cwd():
os.chdir(repository)
_get_version(version, debug)
_get_version(version, debug=debug)

for fc in files:
if '*' in fc.src:
Expand All @@ -127,7 +126,7 @@ def overlay(repository, files, version, debug=False):
util.print_info(msg)


def _get_version(version, debug=False):
def _get_version(version, clean=True, debug=False):
"""
Handle switching to the specified version and return None.
Expand All @@ -147,11 +146,16 @@ def _get_version(version, debug=False):
util.run_command(cmd, debug=debug)
cmd = sh.git.bake('checkout', version)
util.run_command(cmd, debug=debug)
cmd = sh.git.bake('clean', '-d', '-x', '-f')
util.run_command(cmd, debug=debug)
if _has_branch(version, debug):
cmd = sh.git.bake('pull', rebase=True, ff_only=True)
if clean:
cmd = sh.git.bake('clean', '-d', '-x', '-f')
util.run_command(cmd, debug=debug)
if _has_branch(version, debug):
try:
cmd = sh.git.bake('pull', rebase=True, ff_only=True)
util.run_command(cmd, debug=debug)
except sh.ErrorReturnCode:
msg = ' - pulling {} failed, local changes exist?'
sh.print_warn(msg)


def _has_commit(version, debug=False):
Expand Down
12 changes: 4 additions & 8 deletions gilt/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,15 @@ def overlay(ctx): # pragma: no cover
with fasteners.InterProcessLock(c.lock_file):
util.print_info('{}:'.format(c.name))
if c.devel:
if (not os.path.exists(c.dst + '/.git')
and not os.listdir(c.dst)):
git.clone(c.name, c.git, c.dst, debug=debug)
elif not os.path.exists(c.dst + '/.git'):
if os.listdir(c.dst) and not os.path.exists(c.dst + '/.git'):
msg = ' {} not a git repository, skipping'
msg = msg.format(c.dst)
util.print_warn(msg)
continue
else:
msg = ' - already cloned {} at {}'.format(c.name, c.dst)
util.print_info(msg)
elif not os.listdir(c.dst):
git.clone(c.name, c.git, c.dst, debug=debug)

git.checkout(c.name, c.dst, c.version, debug=debug)
git.sync(c.name, c.dst, c.version, debug=debug)

for remote in c.remotes:
git.remote_add(c.dst, remote.name, remote.url, debug=debug)
Expand Down

0 comments on commit ece086e

Please sign in to comment.