From 71b2971f83e4fe36c6fb1f77f4488f577bf2b8a1 Mon Sep 17 00:00:00 2001 From: dajiaohuang Date: Sat, 20 Jun 2026 12:27:32 +0800 Subject: [PATCH 1/2] fix: move logger.debug into function body for github_create_branch The debug log line was placed outside the function body (zero indentation), making it a syntax error. Move it inside the try block after successful checkout. Fixes #1348 --- src/praisonai-agents/praisonaiagents/tools/github_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/praisonai-agents/praisonaiagents/tools/github_tools.py b/src/praisonai-agents/praisonaiagents/tools/github_tools.py index 70fed0793..aa06f3499 100644 --- a/src/praisonai-agents/praisonaiagents/tools/github_tools.py +++ b/src/praisonai-agents/praisonaiagents/tools/github_tools.py @@ -7,8 +7,7 @@ @tool def github_create_branch(branch_name: str) -> str: """Create and checkout a new git branch. - -logger.debug(f"Branch '{branch_name}' checked out successfully.") + Args: branch_name: The name of the branch to create and checkout. """ @@ -16,6 +15,7 @@ def github_create_branch(branch_name: str) -> str: # Check if we are in a git repository subprocess.run(["git", "rev-parse", "--is-inside-work-tree"], check=True, capture_output=True) subprocess.run(["git", "checkout", "-B", branch_name], check=True, capture_output=True, text=True) + logger.debug(f"Branch '{branch_name}' checked out successfully.") return f"Successfully created and checked out branch '{branch_name}'" except subprocess.CalledProcessError as e: logger.error(f"Failed to create branch: {e.stderr}") From 2ffba861f9efc6c8946159372ded2b975d80beaf Mon Sep 17 00:00:00 2001 From: dajiaohuang Date: Sun, 21 Jun 2026 04:31:47 +0800 Subject: [PATCH 2/2] fix: add git branch name validation before checkout Per CodeRabbit review: validate branch_name with git check-ref-format --branch before passing it to git checkout -B to prevent misinterpretation as git options or invalid refs. --- .../praisonaiagents/tools/github_tools.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/praisonai-agents/praisonaiagents/tools/github_tools.py b/src/praisonai-agents/praisonaiagents/tools/github_tools.py index aa06f3499..72cc99928 100644 --- a/src/praisonai-agents/praisonaiagents/tools/github_tools.py +++ b/src/praisonai-agents/praisonaiagents/tools/github_tools.py @@ -14,6 +14,14 @@ def github_create_branch(branch_name: str) -> str: try: # Check if we are in a git repository subprocess.run(["git", "rev-parse", "--is-inside-work-tree"], check=True, capture_output=True) + # Validate branch name to prevent misinterpretation as git options or invalid refs + try: + subprocess.run( + ["git", "check-ref-format", "--branch", branch_name], + check=True, capture_output=True, text=True + ) + except subprocess.CalledProcessError as e: + return f"Error: invalid branch name '{branch_name}': {e.stderr.strip() if e.stderr else 'branch name is not a valid git ref'}" subprocess.run(["git", "checkout", "-B", branch_name], check=True, capture_output=True, text=True) logger.debug(f"Branch '{branch_name}' checked out successfully.") return f"Successfully created and checked out branch '{branch_name}'"