Skip to content

Commit

Permalink
Merge pull request #89 from GEOS-ESM/develop
Browse files Browse the repository at this point in the history
Merge develop into main
  • Loading branch information
mathomp4 committed Jul 14, 2020
2 parents 95a054e + 7a12815 commit a93b61e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
12 changes: 12 additions & 0 deletions mepo.d/cmdline/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,21 @@ def __clone(self):
description = "Clone repositories.")
clone.add_argument(
'repo_url',
metavar = 'URL',
nargs = '?',
default = None,
help = 'URL to clone')
clone.add_argument(
'directory',
nargs = '?',
default = None,
help = "Directory to clone into (Only allowed with URL!)")
clone.add_argument(
'--branch','-b',
metavar = 'name',
nargs = '?',
default = None,
help = 'Branch/tag of URL to initially clone (Only allowed with URL!)')
clone.add_argument(
'--config',
metavar = 'config-file',
Expand Down
24 changes: 18 additions & 6 deletions mepo.d/command/clone/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,25 @@

def run(args):

# This protects against someone using branch without a URL
if args.branch and not args.repo_url:
raise RuntimeError("The branch argument can only be used with a URL")

if args.repo_url:
p = urlparse(args.repo_url)
last_url_node = p.path.rsplit('/')[-1]
url_suffix = pathlib.Path(last_url_node).suffix
if url_suffix == '.git':
git_url_directory = pathlib.Path(last_url_node).stem
if args.directory:
local_clone(args.repo_url,args.branch,args.directory)
os.chdir(args.directory)
else:
git_url_directory = last_url_node
if url_suffix == '.git':
git_url_directory = pathlib.Path(last_url_node).stem
else:
git_url_directory = last_url_node

local_clone(args.repo_url)
os.chdir(git_url_directory)
local_clone(args.repo_url,args.branch)
os.chdir(git_url_directory)

# This tries to read the state and if not, calls init,
# loops back, and reads the state
Expand All @@ -45,7 +53,11 @@ def print_clone_info(comp, name_width):
ver_name_type = '({}) {}'.format(comp.version.type, comp.version.name)
print('{:<{width}} | {:<s}'.format(comp.name, ver_name_type, width = name_width))

def local_clone(url):
def local_clone(url,branch=None,directory=None):
cmd = 'git clone '
if branch:
cmd += '--branch {} '.format(branch)
cmd += '--quiet {}'.format(url)
if directory:
cmd += ' {}'.format(directory)
shellcmd.run(cmd.split())
2 changes: 2 additions & 0 deletions mepo.d/utest/test_mepo_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def setUpClass(cls):
mepo_init.run(args)
args.config = None
args.repo_url = None
args.branch = None
args.directory = None
mepo_clone.run(args)

def setUp(self):
Expand Down

0 comments on commit a93b61e

Please sign in to comment.