Skip to content

Commit

Permalink
Merge pull request #226 from GEOS-ESM/develop
Browse files Browse the repository at this point in the history
Merge develop into main for release
  • Loading branch information
mathomp4 authored Apr 18, 2022
2 parents fbc77d4 + 72528fa commit 63496f7
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mepo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
timeout-minutes: 1
timeout-minutes: 2

- name: Run unit tests
run: python3 mepo.d/utest/test_mepo_commands.py -v
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

## [1.43.0] - 2022-04-18

### Fixed

- Fixed issue where you could issue `mepo clone` in already cloned multirepos (#224)

### Changed

- Changed StateDoesNotExistError and StateAlreadyInitializedError to be subclasses of `SystemExit`
- Changed some git subcommands to use full local path

## [1.42.0] - 2022-03-29

### Added
Expand Down
2 changes: 1 addition & 1 deletion mepo.d/command/clone/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def run(args):
recurse = comp.recurse_submodules
# We need the type to handle hashes in components.yaml
type = comp.version.type
git.clone(version,recurse,type)
git.clone(version,recurse,type,comp.name)
if comp.sparse:
git.sparsify(comp.sparse)
print_clone_info(comp, max_namelen)
Expand Down
19 changes: 12 additions & 7 deletions mepo.d/repository/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from utilities import shellcmd
from utilities import colors
from urllib.parse import urljoin
from state.exceptions import RepoAlreadyClonedError

class GitRepository(object):
"""
Expand All @@ -25,7 +26,7 @@ def __init__(self, remote_url, local_path):
self.__remote = remote_url

root_dir = MepoState.get_root_dir()
full_local_path=os.path.join(root_dir,local_path)
full_local_path=os.path.normpath(os.path.join(root_dir,local_path))
self.__full_local_path=full_local_path
self.__git = 'git -C "{}"'.format(self.__full_local_path)

Expand All @@ -38,16 +39,20 @@ def get_full_local_path(self):
def get_remote_url(self):
return self.__remote

def clone(self, version, recurse, type):
def clone(self, version, recurse, type, comp_name):
cmd1 = 'git clone '
if recurse:
cmd1 += '--recurse-submodules '

cmd1 += '--quiet {} {}'.format(self.__remote, self.__local)
shellcmd.run(shlex.split(cmd1))
cmd2 = 'git -C {} checkout {}'.format(self.__local, version)
cmd1 += '--quiet {} {}'.format(self.__remote, self.__full_local_path)
try:
shellcmd.run(shlex.split(cmd1))
except subprocess.CalledProcessError:
raise RepoAlreadyClonedError(f'Error! Repo [{comp_name}] already cloned')

cmd2 = 'git -C {} checkout {}'.format(self.__full_local_path, version)
shellcmd.run(shlex.split(cmd2))
cmd3 = 'git -C {} checkout --detach'.format(self.__local)
cmd3 = 'git -C {} checkout --detach'.format(self.__full_local_path)
shellcmd.run(shlex.split(cmd3))

# NOTE: The above looks odd because of a quirk of git. You can't do
Expand All @@ -64,7 +69,7 @@ def checkout(self, version, detach=False):
shellcmd.run(shlex.split(cmd2))

def sparsify(self, sparse_config):
dst = os.path.join(self.__local, '.git', 'info', 'sparse-checkout')
dst = os.path.join(self.__full_local_path, '.git', 'info', 'sparse-checkout')
os.makedirs(os.path.dirname(dst), exist_ok=True)
shutil.copy(sparse_config, dst)
cmd1 = self.__git + ' config core.sparseCheckout true'
Expand Down
8 changes: 6 additions & 2 deletions mepo.d/state/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
class StateDoesNotExistError(Exception):
class StateDoesNotExistError(SystemExit):
"""Raised when the mepo state does not exist"""
pass

class StateAlreadyInitializedError(Exception):
class StateAlreadyInitializedError(SystemExit):
"""Raised when the mepo state has already been initialized"""
pass

class RepoAlreadyClonedError(SystemExit):
"""Raised when the repository has already been cloned"""
pass

class ConfigFileNotFoundError(FileNotFoundError):
"""Raised when the config file is not found"""
pass
Expand Down
4 changes: 2 additions & 2 deletions mepo.d/state/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def exists(cls):
@classmethod
def initialize(cls, project_config_file, directory_style):
if cls.exists():
raise StateAlreadyInitializedError('mepo state already exists')
raise StateAlreadyInitializedError('Error! mepo state already exists')
input_components = ConfigFile(project_config_file).read_file()

num_fixture = 0
Expand All @@ -73,7 +73,7 @@ def initialize(cls, project_config_file, directory_style):
@classmethod
def read_state(cls):
if not cls.exists():
raise StateDoesNotExistError('mepo state does not exist')
raise StateDoesNotExistError('Error! mepo state does not exist')
with open(cls.get_file(), 'rb') as fin:
allcomps = pickle.load(fin)
return allcomps
Expand Down

0 comments on commit 63496f7

Please sign in to comment.