feat: enhance git diff visualization with tree structure

This commit is contained in:
KaySar12 2025-05-20 16:59:27 +07:00
parent 5990ada146
commit 0e0c7098e1

View File

@ -205,14 +205,38 @@ async def commit_and_push_submodules():
print(f"Submodule '{name}' stderr:\n{stderr.decode()}")
def format_tree_output(project_path, project_diff, submodule_diffs):
tree = f"📦 {os.path.basename(project_path)}\n"
tree += "└── 📝 Changes:\n"
if project_diff:
tree += indent_lines(project_diff, level=2)
else:
tree += indent_lines("✓ No changes", level=2)
if submodule_diffs:
tree += "\n└── 📚 Submodules:"
for sub_path, diff in submodule_diffs.items():
sub_name = os.path.basename(sub_path)
tree += f"\n └── 📦 {sub_name}\n"
if diff:
tree += indent_lines(diff, level=3, prefix="└── 📝 Changes:\n")
else:
tree += " └── ✓ No changes"
return tree
def indent_lines(text, level=1, prefix=""):
indent = " " * level
if prefix:
return f"{indent}{prefix}{indent}{text.replace(chr(10), f'{chr(10)}{indent}')}"
return f"{indent}{text.replace(chr(10), f'{chr(10)}{indent}')}"
async def push_code():
git_user, git_pass, project_path = get_git_credentials()
os.chdir(project_path)
print(f"Changed to project path: {project_path}")
# Rest of the push_code function remains the same
proc = await asyncio.create_subprocess_exec(
"git",
"remote",
@ -227,8 +251,13 @@ async def push_code():
git_repo = stdout.decode().strip().replace(".git", "").replace("https://", "")
remote_url = f"https://{git_user}:{git_pass}@{git_repo}"
# Get main project diff before committing
project_diff = get_git_diff(project_path)
# Commit & push submodules
await commit_and_push_submodules()
# Generate and commit main project
commit_msg = gen_commit(project_path)
print(f"Generated commit message:\n{commit_msg}\n")
@ -244,21 +273,21 @@ async def push_code():
cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await proc.communicate()
if proc.returncode != 0:
print(f"Command failed: {cmd}")
print(stderr.decode())
elif stderr:
# Not an error; just info output
print(stderr.decode())
submodule_diffs = {}
if stdout:
print(stdout.decode())
if stderr:
print(stderr.decode())
# Prepare submodule diff tree
submodule_diffs = {}
if await has_submodules():
submodule_info = await get_submodule_info()
for path in submodule_info:
submodule_diffs[path] = get_git_diff(path)
# Format and print the tree output
tree_output = format_tree_output(project_path, submodule_diffs)
print("\nProject Status:")
# Show tree output
tree_output = format_tree_output(project_path, project_diff, submodule_diffs)
print("\n📦 Project Tree View:")
print(tree_output)
print()