Skip to content

Commit

Permalink
Merge pull request #233 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 committed Aug 10, 2022
2 parents 1310b69 + df1f7d7 commit 50e0c2d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

## [1.45.0] - 2022-08-10

### Changed

- Allow `checkout-if-exists` to work on tags or branches

## [1.44.0] - 2022-04-28

### Fixed
Expand Down
8 changes: 4 additions & 4 deletions mepo.d/cmdline/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ def __checkout(self):
def __checkout_if_exists(self):
checkout_if_exists = self.subparsers.add_parser(
'checkout-if-exists',
description = 'Switch to branch `branch-name` in any component where it is present. ',
description = 'Switch to branch or tag `ref-name` in any component where it is present. ',
aliases=mepoconfig.get_command_alias('checkout-if-exists'))
checkout_if_exists.add_argument(
'branch_name',
metavar = 'branch-name',
help = "Name of branch")
'ref_name',
metavar = 'ref-name',
help = "Name of branch or tag")
checkout_if_exists.add_argument(
'-q', '--quiet',
action = 'store_true',
Expand Down
18 changes: 10 additions & 8 deletions mepo.d/command/checkout-if-exists/checkout-if-exists.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ def run(args):
allcomps = MepoState.read_state()
for comp in allcomps:
git = GitRepository(comp.remote, comp.local)
branch = args.branch_name
status = git.verify_branch(branch)
ref_name = args.ref_name
status, ref_type = git.verify_branch_or_tag(ref_name)

if status == 0:
if args.dry_run:
print("Branch %s exists in %s" %
(colors.YELLOW + branch + colors.RESET,
print("%s %s exists in %s" %
(ref_type,
colors.YELLOW + ref_name + colors.RESET,
colors.RESET + comp.name + colors.RESET))
else:
if not args.quiet:
print("Checking out branch %s in %s" %
(colors.YELLOW + branch + colors.RESET,
colors.RESET + comp.name + colors.RESET))
git.checkout(branch,args.detach)
print("Checking out %s %s in %s" %
(ref_type.lower(),
colors.YELLOW + ref_name + colors.RESET,
colors.RESET + comp.name + colors.RESET))
git.checkout(ref_name,args.detach)
16 changes: 12 additions & 4 deletions mepo.d/repository/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,18 @@ def push_tag(self, tag_name, force):
cmd += ' origin {}'.format(tag_name)
shellcmd.run(shlex.split(cmd))

def verify_branch(self, branch_name):
cmd = self.__git + ' show-branch remotes/origin/{}'.format(branch_name)
status = shellcmd.run(shlex.split(cmd),status=True)
return status
def verify_branch_or_tag(self, ref_name):
branch_cmd = self.__git + f' show-branch remotes/origin/{ref_name}'
tag_cmd = self.__git + f' rev-parse {ref_name}'
branch_status = shellcmd.run(shlex.split(branch_cmd),status=True)
ref_type = "UNKNOWN"
if branch_status != 0:
status = shellcmd.run(shlex.split(tag_cmd),status=True)
ref_type = "Tag"
else:
status = branch_status
ref_type = "Branch"
return status, ref_type

def check_status(self, ignore_permissions=False):
cmd = 'git -C {}'.format(self.__full_local_path)
Expand Down

0 comments on commit 50e0c2d

Please sign in to comment.