Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: richer git-status #74

Merged
merged 1 commit into from
Aug 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions reana/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ def get_srcdir(component=''):
def get_current_branch(srcdir):
"""Return current Git branch name checked out in the given directory.

:param component: standard component name
:type component: str
:param srcdir: source code directory
:type srcdir: str

:return: checkout out branch in the component source code directory
:rtype: str
Expand All @@ -279,6 +279,19 @@ def get_current_branch(srcdir):
'grep "^*" | colrm 1 2')


def get_current_commit(srcdir):
"""Return information about git commit checked out in the given directory.

:param srcdir: source code directory
:type srcdir: str

:return: commit information composed of brief SHA1 and subject
:rtype: str
"""
os.chdir(srcdir)
return subprocess.getoutput('git log --pretty=format:"%h %s" -n 1')


def select_components(components):
"""Return expanded and unified component name list based on input values.

Expand Down Expand Up @@ -553,11 +566,12 @@ def git_status(component): # noqa: D301
components = select_components(component)
for component in components:
branch = get_current_branch(get_srcdir(component))
commit = get_current_commit(get_srcdir(component))
click.secho('- {0}'.format(component), nl=False, bold=True)
if branch == 'master':
click.secho(' @ {0}'.format(branch))
click.secho(' @ {0} {1}'.format(branch, commit))
else:
click.secho(' @ {0}'.format(branch), fg='red')
click.secho(' @ {0} {1}'.format(branch, commit), fg='red')


@click.option('--component', '-c', multiple=True, default=['CLUSTER'],
Expand Down