feat(interpreter): enhance git diff output in gen_commit.py

This commit is contained in:
KaySar12 2025-05-20 16:53:52 +07:00
parent cacf18e723
commit 3ea4377d47

View File

@ -17,7 +17,32 @@ def get_git_credentials():
def get_git_diff(project_path): def get_git_diff(project_path):
"""Run git diff and return the output.""" """Run git diff and return the output."""
result = os.popen(f'cd "{project_path}" && git diff --compact-summary').read() result = os.popen(f'cd "{project_path}" && git diff --compact-summary').read()
return result.strip() staged_changes = os.popen(f'cd "{project_path}" && git diff --cached --compact-summary').read()
# Combine both staged and unstaged changes
all_changes = result.strip() + "\n" + staged_changes.strip()
return all_changes.strip() if all_changes.strip() else "✓ No changes"
def format_tree_output(base_path, submodule_diffs):
"""Format the output in a tree structure."""
base_name = os.path.basename(base_path)
base_diff = get_git_diff(base_path)
output = [f"📦 {base_name}"]
output.append(f"└── 📝 Changes:")
for line in base_diff.split('\n'):
output.append(f" └── {line}")
if submodule_diffs:
output.append("└── 📚 Submodules:")
for submodule_path, diff in submodule_diffs.items():
name = os.path.basename(submodule_path)
output.append(f" └── 📦 {name}")
for line in diff.split('\n'):
output.append(f" └── {line}")
return '\n'.join(output)
def gen_commit(project_path): def gen_commit(project_path):
@ -185,6 +210,20 @@ async def push_code():
os.chdir(project_path) os.chdir(project_path)
print(f"Changed to project path: {project_path}") print(f"Changed to project path: {project_path}")
# Get submodule information
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:")
print(tree_output)
print()
# Rest of the push_code function remains the same
proc = await asyncio.create_subprocess_exec( proc = await asyncio.create_subprocess_exec(
"git", "git",
"remote", "remote",
@ -224,5 +263,6 @@ async def push_code():
print(stderr.decode()) print(stderr.decode())
if __name__ == "__main__": if __name__ == "__main__":
asyncio.run(push_code()) asyncio.run(push_code())