feat: Enhance commit command handling in AICodeAgentCog to set committer identity
This commit is contained in:
parent
d19297dcc0
commit
17c806eedd
@ -219,8 +219,25 @@ class AICodeAgentCog(commands.Cog):
|
||||
# For now, let's assume simple commands or trust shell=True for git.
|
||||
# However, the example used shell=True. Let's try that first for consistency with the hint.
|
||||
|
||||
final_command_str = command_str
|
||||
if "commit" in command_str and "--author" in command_str: # Heuristic to identify our commit commands
|
||||
# COMMIT_AUTHOR = "Name <email>"
|
||||
author_name_match = re.match(r"^(.*?)\s*<(.+?)>$", COMMIT_AUTHOR)
|
||||
if author_name_match:
|
||||
committer_name = author_name_match.group(1).strip()
|
||||
committer_email = author_name_match.group(2).strip()
|
||||
# Prepend -c flags for committer identity
|
||||
# Ensure the original command_str is correctly modified.
|
||||
# If command_str starts with "git commit", we insert after "git".
|
||||
if command_str.strip().startswith("git commit"):
|
||||
parts = command_str.strip().split(" ", 1) # "git", "commit ..."
|
||||
final_command_str = f"{parts[0]} -c user.name=\"{committer_name}\" -c user.email=\"{committer_email}\" {parts[1]}"
|
||||
print(f"AICodeAgentCog: Modified commit command for committer ID: {final_command_str}")
|
||||
else:
|
||||
print(f"AICodeAgentCog: Warning - Could not parse COMMIT_AUTHOR ('{COMMIT_AUTHOR}') to set committer identity.")
|
||||
|
||||
proc = subprocess.Popen(
|
||||
command_str, # Command as a string
|
||||
final_command_str, # Potentially modified command string
|
||||
shell=True, # Execute through the shell
|
||||
cwd=cwd,
|
||||
env=env,
|
||||
@ -236,10 +253,10 @@ class AICodeAgentCog(commands.Cog):
|
||||
stdout, stderr = proc.communicate()
|
||||
return (stdout, stderr, -1, True) # -1 for timeout-specific return code
|
||||
except FileNotFoundError as fnf_err: # Specifically catch if 'git' command itself is not found
|
||||
print(f"AICodeAgentCog: FileNotFoundError for command '{command_str}': {fnf_err}. Is Git installed and in PATH?")
|
||||
print(f"AICodeAgentCog: FileNotFoundError for command '{final_command_str}': {fnf_err}. Is Git installed and in PATH?")
|
||||
return ("", f"FileNotFoundError: {fnf_err}. Ensure Git is installed and in PATH.", -2, False)
|
||||
except Exception as e:
|
||||
print(f"AICodeAgentCog: Exception in run_sync_subprocess for '{command_str}': {type(e).__name__} - {e}")
|
||||
print(f"AICodeAgentCog: Exception in run_sync_subprocess for '{final_command_str}': {type(e).__name__} - {e}")
|
||||
return ("", str(e), -3, False) # -3 for other exceptions
|
||||
|
||||
stdout_str, stderr_str, returncode, timed_out = await asyncio.to_thread(run_sync_subprocess)
|
||||
@ -257,7 +274,8 @@ class AICodeAgentCog(commands.Cog):
|
||||
# If stdout is empty but no error, return it as is.
|
||||
# If full_output is just "Stdout:\n\n", it means empty stdout.
|
||||
# We want the actual stdout for rev-parse, not the "Stdout:" prefix.
|
||||
if command_str == "git rev-parse --abbrev-ref HEAD" and stdout_str:
|
||||
# Check original command_str for this specific case, not final_command_str which might be modified
|
||||
if command_str == "git rev-parse --abbrev-ref HEAD" and stdout_str: # Use original command_str for this check
|
||||
return True, stdout_str.strip() # Return just the branch name
|
||||
return True, full_output.strip() if full_output.strip() else "Command executed successfully with no output."
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user