From 3ea4377d47de06a719f5de55519aee34249d1940 Mon Sep 17 00:00:00 2001 From: KaySar12 Date: Tue, 20 May 2025 16:53:52 +0700 Subject: [PATCH] feat(interpreter): enhance git diff output in gen_commit.py --- scripts/interpreter/gen_commit.py | 42 ++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/scripts/interpreter/gen_commit.py b/scripts/interpreter/gen_commit.py index a2012aa..485b6ab 100755 --- a/scripts/interpreter/gen_commit.py +++ b/scripts/interpreter/gen_commit.py @@ -17,7 +17,32 @@ def get_git_credentials(): def get_git_diff(project_path): """Run git diff and return the output.""" 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): @@ -185,6 +210,20 @@ async def push_code(): os.chdir(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( "git", "remote", @@ -224,5 +263,6 @@ async def push_code(): print(stderr.decode()) + if __name__ == "__main__": asyncio.run(push_code())