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

Added Status Message for Amending #309

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
41 changes: 41 additions & 0 deletions gitgud/skills/user_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,44 @@ def display_entry(index, human_name, code_name, indent):
code_name=item.name,
indent=indent
)


def amending_message(before_ref, after_ref, show_hashes=True, show_files=True, show_refs=True): # noqa: E501
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method doesn't let you show the branches as shown in #257

file_operator = operations.get_operator()
display_data = [
{"_name": "Before", "_commit": file_operator.repo.commit(before_ref)},
{"_name": "After", "_commit": file_operator.repo.commit(after_ref)}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, it might be worth it to do tuples or nested dictionaries. Using underscores is a bit weird here.

]

# Necessary for showing branches
if show_refs:
tree = file_operator.get_current_tree()
referred_by = {}
for branch_name in tree['branches']:
target = tree['branches'][branch_name]['target']
if target not in referred_by:
referred_by.update({target: [branch_name]})
else:
referred_by[target].append(branch_name)
for target in referred_by:
referred_by[target] = ", ".join(referred_by[target])

for snapshot in display_data:
commit = snapshot["_commit"]
snapshot["Message"] = commit.message
if show_hashes:
snapshot["Hash"] = commit.hexsha[:7]
if show_files:
files = file_operator.get_commit_content(commit)
snapshot["File"] = "Present" if files else "Missing"

for snapshot in display_data:
print(snapshot["_name"], end="")
if show_refs:
print(" ({}):".format(referred_by[snapshot["_commit"].hexsha]))
else:
print(":")
for feature in snapshot:
if not feature.startswith("_"):
print(feature + ":", str(snapshot[feature]).strip())
print()