Skip to content

Commit

Permalink
Add stash indicator to status (#327)
Browse files Browse the repository at this point in the history
* Add stash indicator to status

* Add blobless clone
  • Loading branch information
mathomp4 authored Oct 11, 2024
1 parent f54c6db commit 593f8db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Hidden option `--location` for mepo that returns the path to the mepo directory
- Added ability to print number of stashes in `mepo status`

### Changed

Expand Down
18 changes: 15 additions & 3 deletions src/mepo/command/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def run(args):


def check_component_status(comp, ignore_permissions):
"""Check the status of a single component"""
git = GitRepository(comp.remote, comp.local)

# Older mepo clones will not have ignore_submodules in comp, so
Expand All @@ -54,21 +55,27 @@ def check_component_status(comp, ignore_permissions):
# This command is to try and work with git tag oddities
curr_ver = sanitize_version_string(orig_ver, curr_ver, git)

# We also want to see if there are any stashes in the component
num_stashes = len(git.list_stash().splitlines())

return (
curr_ver,
internal_state_branch_name,
num_stashes,
git.check_status(ignore_permissions, _ignore_submodules),
)


def print_status(allcomps, result, max_width, nocolor=False, hashes=False):
"""Print the status of all components"""
for index, comp in enumerate(allcomps):
time.sleep(0.025)
print_component_status(comp, result[index], max_width, nocolor, hashes)


def print_component_status(comp, result, width, nocolor=False, hashes=False):
current_version, internal_state_branch_name, output = result
"""Print the status of a single component"""
current_version, internal_state_branch_name, num_stashes, output = result
if hashes:
comp_path = _get_relative_path(comp.local)
comp_hash = shellcmd.run(
Expand All @@ -86,8 +93,13 @@ def print_component_status(comp, result, width, nocolor=False, hashes=False):
width += len(colors.RED) + len(colors.RESET)
else:
component_name = comp.name
FMT0 = "{:<%s.%ss} | {:<s}" % (width, width)
print(FMT0.format(component_name, current_version))

# If there are stashes, we print the number of stashes in yellow
if num_stashes:
stash_str = colors.YELLOW + f"[stashes: {num_stashes}]" + colors.RESET
print(f"{component_name:<{width}} | {current_version} {stash_str}")
else:
print(f"{component_name:<{width}} | {current_version}")
if output:
for line in output.split("\n"):
print(" |", line.rstrip())
2 changes: 1 addition & 1 deletion tests/test_mepo_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __get_saved_output(cls, output_file):
@classmethod
def __checkout_fixture(cls):
remote = f"https://github.com/GEOS-ESM/{cls.fixture}.git"
git_clone = "git clone "
git_clone = "git clone --filter=blob:none "
if cls.tag:
git_clone += f"-b {cls.tag}"
cmd = f"{git_clone} {remote} {cls.fixture_dir}"
Expand Down

0 comments on commit 593f8db

Please sign in to comment.