Skip to content

Commit

Permalink
Merge pull request #105 from GEOS-ESM/develop
Browse files Browse the repository at this point in the history
Merge Develop into Main
  • Loading branch information
tclune authored Oct 7, 2020
2 parents 7e018b0 + b0f61f7 commit cd96ff4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 21 deletions.
25 changes: 17 additions & 8 deletions mepo.d/command/save/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from repository.git import GitRepository
from config.config_file import ConfigFile

import os

def run(args):
allcomps = MepoState.read_state()
for comp in allcomps:
Expand All @@ -14,27 +16,34 @@ def run(args):
relpath_start = MepoState.get_root_dir()
for comp in allcomps:
complist.update(comp.to_dict(relpath_start))
ConfigFile(args.config_file).write_yaml(complist)
print("Components written to '{}'".format(args.config_file))
config_file_root_dir=os.path.join(relpath_start,args.config_file)
ConfigFile(config_file_root_dir).write_yaml(complist)
print(f"Components written to '{config_file_root_dir}'")

def _update_comp(comp):
git = GitRepository(comp.remote, comp.local)
orig_ver = comp.version
curr_ver = MepoVersion(*git.get_version())
if _version_has_changed(curr_ver, orig_ver):
_verify_local_and_remote_commit_ids_match(git, curr_ver.name, comp.name)
_verify_local_and_remote_commit_ids_match(git, curr_ver.name, comp.name, curr_ver.type)
comp.version = curr_ver

def _version_has_changed(curr_ver, orig_ver):
result = False
if curr_ver != orig_ver:
assert curr_ver.type == 'b', '{}'.format(curr_ver)
assert curr_ver.detached is False, '{}'.format(curr_ver)
result = True
if curr_ver.type == 'b':
assert curr_ver.detached is False, '{}'.format(curr_ver)
result = True
elif curr_ver.type == 't':
result = True
elif curr_ver.type == 'h':
result = True
else:
raise Exception("This should not happen")
return result

def _verify_local_and_remote_commit_ids_match(git, curr_ver_name, comp_name):
remote_id = git.get_remote_latest_commit_id(curr_ver_name)
def _verify_local_and_remote_commit_ids_match(git, curr_ver_name, comp_name, curr_ver_type):
remote_id = git.get_remote_latest_commit_id(curr_ver_name, curr_ver_type)
local_id = git.get_local_latest_commit_id()
failmsg = "{} (remote commit) != {} (local commit) for {}:{}. Did you try 'mepo push'?"
if remote_id != local_id:
Expand Down
38 changes: 27 additions & 11 deletions mepo.d/repository/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ def check_status(self):

short_status = item.split()[1]

#print("file: ", file_name, "short_status:", short_status, "index_field:", index_field)

if index_field == "?":
verbose_status = colors.RED + "untracked file" + colors.RESET

Expand Down Expand Up @@ -253,14 +251,32 @@ def push(self,tags):
cmd = self.__git + ' push -u {}'.format(self.__remote)
return shellcmd.run(cmd.split(), output=True).strip()

def get_remote_latest_commit_id(self, branch):
cmd = self.__git + ' ls-remote {} refs/heads/{}'.format(self.__remote, branch)
output = shellcmd.run(cmd.split(), output=True).strip()
if not output:
msg = 'Branch {} does not exist on {}'.format(branch, self.__remote)
msg += " Have you run 'mepo push'?"
raise RuntimeError(msg)
return output.split()[0]
def get_remote_latest_commit_id(self, branch, commit_type):
if commit_type == 'h':
cmd = self.__git + ' cat-file -e {}'.format(branch)
status = shellcmd.run(cmd.split(), status=True)
if status != 0:
msg = 'Hash {} does not exist on {}'.format(branch, self.__remote)
msg += " Have you run 'mepo push'?"
raise RuntimeError(msg)
return branch
else:
# If we are a branch...
if commit_type == 'b':
msgtype = "Branch"
reftype = 'heads'
elif commit_type == 't':
msgtype = 'Tag'
reftype = 'tags'
else:
raise RuntimeError("Should not get here")
cmd = self.__git + ' ls-remote {} refs/{}/{}'.format(self.__remote, reftype, branch)
output = shellcmd.run(cmd.split(), output=True).strip()
if not output:
msg = '{} {} does not exist on {}'.format(msgtype, branch, self.__remote)
msg += " Have you run 'mepo push'?"
raise RuntimeError(msg)
return output.split()[0]

def get_local_latest_commit_id(self):
cmd = self.__git + ' rev-parse HEAD'
Expand All @@ -287,7 +303,7 @@ def get_version(self):
name = tmp
tYpe = 'b'
elif output.startswith('HEAD'): # Assume hash
cmd = self.__git + ' rev-parse --short HEAD'
cmd = self.__git + ' rev-parse HEAD'
hash_out = shellcmd.run(cmd.split(), output=True)
detached = True
name = hash_out.rstrip()
Expand Down
6 changes: 4 additions & 2 deletions mepo.d/state/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __set_original_version(self, comp_details):
ver_type = 'b'
elif comp_details.get('hash', None):
# Hashes don't have to exist
ver_name = comp_details['hash'][:7]
ver_name = comp_details['hash']
ver_type = 'h'
else:
ver_name = comp_details['tag'] # 'tag' key has to exist
Expand All @@ -49,7 +49,9 @@ def to_dict(self, start):
details['remote'] = self.remote
if self.version.type == 't':
details['tag'] = self.version.name
else: # if not tag, version has to be a branch
elif self.version.type == 'h':
details['hash'] = self.version.name
else: # if not tag or hash, version has to be a branch
if self.version.detached: # SPECIAL HANDLING of 'detached head' branches
details['branch'] = self.version.name.replace('origin/', '')
else:
Expand Down

0 comments on commit cd96ff4

Please sign in to comment.