|
|
@@ -12,10 +12,10 @@ def main():
|
|
|
|
|
|
print(args) if DEBUG>1 else None
|
|
|
|
|
|
- if args.source_url.find('://') < 0 and args.source_url.find( ':' ) > 0:
|
|
|
+ if args.source_url and args.source_url.find('://') < 0 and args.source_url.find( ':' ) > 0:
|
|
|
args.source_url = 'ssh://' + args.source_url.replace( ':', '/', 1)
|
|
|
|
|
|
- for ret in recurse_abe_submodules( args.target_dir, args.source_url, args.branch, clone_repo_cached(cache_dir=args.cache_dir)):
|
|
|
+ for ret in recurse_abe_submodules( args.output_dir, args.source_url, args.tag, clone_repo_cached(cache_dir=args.cache_dir)):
|
|
|
pass
|
|
|
|
|
|
|
|
|
@@ -24,10 +24,10 @@ def parser():
|
|
|
p = argparse.ArgumentParser()
|
|
|
p.add_argument('-d', '--debug', action='count', default=1)
|
|
|
p.add_argument('-q', '--quiet', action='store_true')
|
|
|
- p.add_argument('-t', '--target_dir', default='.')
|
|
|
+ p.add_argument('-o', '--output_dir', default='.')
|
|
|
p.add_argument('-c', '--cache_dir', default=None)
|
|
|
- p.add_argument('-b', '--branch', default='master')
|
|
|
- p.add_argument('source_url')
|
|
|
+ p.add_argument('-t', '--tag', default='master')
|
|
|
+ p.add_argument('-s', '--source_url', default=None)
|
|
|
return p
|
|
|
|
|
|
|
|
|
@@ -43,13 +43,14 @@ def recurse_abe_submodules(path, remote, ref=None, func=None):
|
|
|
for su in subm:
|
|
|
newpath = os.path.normpath(os.path.join( path, su.subdir))
|
|
|
newurl = url._replace(path=su.remote).geturl()
|
|
|
- print('Repo:', path, 'Has Submodule:', newpath, 'Type:', su.subtype,'From:', newurl) if DEBUG else None
|
|
|
+ print(f"Repo: \"{path}\" has Submodule: \"{newpath}\" Type: \"{su.subtype}\" From: \"{newurl}\"") if DEBUG else None
|
|
|
for ret in recurse_abe_submodules( newpath, newurl, su.ref, func):
|
|
|
yield ret
|
|
|
|
|
|
def cache_path(cache, remote):
|
|
|
import os.path
|
|
|
- return os.path.join( cache, remote.replace('/','_').replace( '@', '_at_'))
|
|
|
+ for url in remote:
|
|
|
+ return os.path.join( cache, str(url).replace('/','_').replace( '@', '_at_'))
|
|
|
|
|
|
def real_relpath(dest, source='.'):
|
|
|
import os.path
|
|
|
@@ -57,16 +58,18 @@ def real_relpath(dest, source='.'):
|
|
|
real_source = os.path.realpath(source)
|
|
|
return os.path.relpath(real_dest, real_source)
|
|
|
|
|
|
+from git import RemoteProgress
|
|
|
+class ProgressPrinter(RemoteProgress):
|
|
|
+ def update(self,op_code,cur_count,max_count=None,message=''):
|
|
|
+ cur_count_int = round(cur_count)
|
|
|
+ max_count_int = round(max_count or 100)
|
|
|
+ print(' '.join(['' for _ in range(30)]), end='\r')
|
|
|
+ print(f"{cur_count_int}/{max_count_int}", str(round(100*cur_count / (max_count or 100)))+'%', end="\r")
|
|
|
+
|
|
|
def clone_repo_cached( cache_dir=None, bare=False):
|
|
|
def clone_repo(path, remote, ref=None, cache_dir=cache_dir, bare=bare):
|
|
|
print('Repo:', path) if DEBUG>1 else None
|
|
|
- from git import Repo, RemoteProgress
|
|
|
- class ProgressPrinter(RemoteProgress):
|
|
|
- def update(self,op_code,cur_count,max_count=None,message=''):
|
|
|
- cur_count_int = round(cur_count)
|
|
|
- max_count_int = round(max_count or 100)
|
|
|
- print(' '.join(['' for _ in range(30)]), end='\r')
|
|
|
- print(f"{cur_count_int}/{max_count_int}", str(round(100*cur_count / (max_count or 100)))+'%', end="\r")
|
|
|
+ from git import Repo
|
|
|
repo = Repo.init(path, bare=bare)
|
|
|
if 'origin' in repo.remotes:
|
|
|
origin = repo.remotes['origin']
|
|
|
@@ -74,7 +77,7 @@ def clone_repo_cached( cache_dir=None, bare=False):
|
|
|
origin = repo.create_remote('origin', remote)
|
|
|
|
|
|
if cache_dir != None:
|
|
|
- cache_repo_path = cache_path(cache_dir, remote)
|
|
|
+ cache_repo_path = cache_path(cache_dir, origin.urls)
|
|
|
print('Cacheing from:', cache_repo_path) if DEBUG else None
|
|
|
clone_repo_cached(cache_dir=None, bare=True)( cache_repo_path, remote, ref)
|
|
|
if 'cache' in repo.remotes:
|
|
|
@@ -115,7 +118,7 @@ def clone_repo_cached( cache_dir=None, bare=False):
|
|
|
print('Active Branch:', active_branch) if DEBUG else None
|
|
|
print('Tracking Ref:', tracking_ref, '\n') if DEBUG else None
|
|
|
active_branch.checkout()
|
|
|
- repo.git.merge( tracking_ref )
|
|
|
+ repo.head.reset( tracking_ref, index=True, working_tree=False)
|
|
|
return repo
|
|
|
return clone_repo
|
|
|
|