From 716e3fc6b947567d9fc129f2ad662178485a41fa Mon Sep 17 00:00:00 2001 From: KaySar12 Date: Thu, 15 May 2025 18:13:16 +0700 Subject: [PATCH] feat: add submodule check before committing and pushing --- scripts/interpreter/gen_commit.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/interpreter/gen_commit.py b/scripts/interpreter/gen_commit.py index e7b91e6..a62c776 100755 --- a/scripts/interpreter/gen_commit.py +++ b/scripts/interpreter/gen_commit.py @@ -57,7 +57,20 @@ Analyze the following git diff and generate a commit message: return str(response).strip() +async def has_submodules(): + """Check if the repository has any submodules.""" + proc = await asyncio.create_subprocess_exec( + "git", "config", "--file", ".gitmodules", "--get-regexp", r"^submodule\.", + stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, + ) + stdout, stderr = await proc.communicate() + return bool(stdout.decode().strip()) + + async def get_submodule_info(): + if not await has_submodules(): + return {} + proc = await asyncio.create_subprocess_exec( "git", "config", "--file", ".gitmodules", "--get-regexp", r"^submodule\..*\.path$", stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, @@ -80,6 +93,10 @@ async def get_submodule_info(): async def commit_and_push_submodules(): + if not await has_submodules(): + print("No submodules found in this repository.") + return + print("Checking for submodule changes...") submodule_info = await get_submodule_info()