Skip to content

Commit 7cd5a65

Browse files
committed
Modified git clone function to perform shallow clones if requested
1 parent 35f1444 commit 7cd5a65

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

mbed/mbed.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -607,21 +607,24 @@ def cleanup():
607607
for branch in branches: # delete all local branches so the new repo clone is not poluted
608608
pquery([git_cmd, 'branch', '-D', branch])
609609

610-
def clone(url, name=None, depth=None, protocol=None):
611-
if depth:
610+
def clone(url, path, rev=None, depth=None, protocol=None, name=None):
611+
result = pquery([git_cmd, "ls-remote", url, (rev if rev else "HEAD")])
612+
613+
if result:
612614
repo_name = url.split('/')[-1]
613615
if '.git' in repo_name:
614616
repo_name = repo_name[:-4]
615617

616618
os.mkdir(repo_name)
617-
619+
618620
with cd(repo_name):
619621
Git.init()
620-
Git.fetch(url=url, branch='latest', depth=depth)
622+
Git.fetch(url=url, rev=rev, depth=depth)
621623
Git.checkout('FETCH_HEAD')
622624
popen([git_cmd, 'remote', 'add', 'origin', url])
625+
623626
else:
624-
popen([git_cmd, 'clone', formaturl(url, protocol), name] + (['-v'] if very_verbose else ([] if verbose else ['-q'])))
627+
popen([git_cmd, 'clone', formaturl(url, protocol), path] + (['-v'] if very_verbose else ([] if verbose else ['-q'])))
625628

626629
def add(dest):
627630
info("Adding reference "+dest)
@@ -655,9 +658,9 @@ def publish(all_refs=None):
655658
if not branch:
656659
error(err+"Working set is not on a branch.", 1)
657660

658-
def fetch(url=None, branch=None, depth=None):
661+
def fetch(url=None, rev=None, depth=None):
659662
info("Fetching revisions from remote repository to \"%s\"" % os.path.basename(os.getcwd()))
660-
popen([git_cmd, 'fetch', '--tags'] + ([url] if url else []) + ([branch] if branch else ['--all']) + (['--depth', depth] if depth else []) + (['-v'] if very_verbose else ([] if verbose else ['-q'])))
663+
popen([git_cmd, 'fetch', '--tags'] + ([url] if url else []) + ([rev] if rev else ['--all']) + (['--depth', depth] if depth else []) + (['-v'] if very_verbose else ([] if verbose else ['-q'])))
661664

662665
def discard(clean_files=False):
663666
info("Discarding local changes in \"%s\"" % os.path.basename(os.getcwd()))
@@ -1111,7 +1114,7 @@ def clone(self, url, path, rev=None, depth=None, protocol=None, **kwargs):
11111114
# Main clone routine if the clone with cache ref failed (might occur if cache ref is dirty)
11121115
if main:
11131116
try:
1114-
scm.clone(url, path, depth=depth, protocol=protocol, **kwargs)
1117+
scm.clone(url, path, rev=rev, depth=depth, protocol=protocol, **kwargs)
11151118
except ProcessException:
11161119
if os.path.isdir(path):
11171120
rmtree_readonly(path)
@@ -1816,18 +1819,17 @@ def import_(url, path=None, ignore=False, depth=None, protocol=None, top=True):
18161819
else:
18171820
error(err, 1)
18181821

1819-
action("Syncing repo.");
1820-
#repo.sync()
1822+
repo.sync()
18211823

18221824
if top: # This helps sub-commands to display relative paths to the imported program
18231825
cwd_root = repo.path
18241826

1825-
#with cd(repo.path):
1826-
#deploy(ignore=ignore, depth=depth, protocol=protocol, top=False)
1827+
with cd(repo.path):
1828+
deploy(ignore=ignore, depth=depth, protocol=protocol, top=False)
18271829

18281830
if top:
18291831
action("Post action.");
1830-
#Program(repo.path).post_action()
1832+
Program(repo.path).post_action()
18311833

18321834

18331835
# Add library command

0 commit comments

Comments
 (0)