Skip to content
This repository has been archived by the owner on Mar 5, 2018. It is now read-only.

Commit

Permalink
Reworked module fetching to clone specific branch with depth 1 (#115)
Browse files Browse the repository at this point in the history
Reworked module fetching to clone specific branch with depth 1
  • Loading branch information
rwngwn authored and goldmann committed Jul 26, 2017
1 parent f70642d commit 36982ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
25 changes: 16 additions & 9 deletions cct/lib/git.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import shutil
import subprocess

from cct.errors import CCTError
Expand All @@ -8,19 +9,25 @@


def clone_repo(url, path, version=None, force=False):
# this is not a nice way, but we are passing version as a None explictly on multiple places
if not version:
version = "master"
try:
if not os.path.exists(path):
logger.info("Cloning %s into %s" % (url, path))
subprocess.check_call(["git", "clone", url, path])
if version:
logger.info('Checking out %s revision' % version)
subprocess.check_call(['git', 'checkout', version], cwd=path)
elif os.path.exists(path) and force:
logger.info('Forcing %s revision for %s' % (version, path))
subprocess.check_call(['git', 'checkout', version], cwd=path)
if os.path.exists(path):
if force:
logger.info("Removing old module from path: '%'." % path)
shutil.rmtree(path)
else:
return

logger.info("Cloning %s into %s" % (url, path))
cmd = ["git", "clone", "--depth", "1", url, path, "-b", version]
logger.debug("Running '%s'" % ' '.join(cmd))
out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)

except Exception as ex:
logger.error("Cannot clone repo %s into %s: %s", url, path, ex)
raise
raise CCTError('Cannot clone repo %s, %s' % (url, ex))


Expand Down
1 change: 0 additions & 1 deletion cct/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def install_module(self, url, version, override=False):
repo_dir = "%s/%s" % (self.directory, os.path.basename(url))
if repo_dir.endswith('git'):
repo_dir = repo_dir[:-4]
logger.info("Cloning module into %s" % repo_dir)
clone_repo(url, repo_dir, self.version, self.override)
self.discover_modules(repo_dir)

Expand Down

0 comments on commit 36982ed

Please sign in to comment.