@@ -41,7 +41,7 @@ async def validate_git_url(url) -> None:
4141 except subprocess .CalledProcessError as e :
4242 raise ValueError (f"Invalid Git repository URL: { url } . Error: { e .stderr } " ) from e
4343
44- async def commit_and_push_changes (repo_path : Path , branch_name : str = None , commit_message : str = "Auto-commit: Save changes" ) -> None :
44+ async def commit_and_push_changes (repo_path : Path , branch_name : str = None , commit_message : str = "Auto-commit: Save changes" , checkout : bool = True ) -> None :
4545 """Add all changes, commit with default message, and push to remote."""
4646
4747 repo_path_str = str (repo_path )
@@ -51,27 +51,26 @@ async def commit_and_push_changes(repo_path: Path, branch_name: str = None, comm
5151 if not branch_name :
5252 branch_name = f"agent-tide-{ ulid ()} "
5353
54- # Create and checkout new branch
55- process = await asyncio . create_subprocess_exec (
56- "git" , "checkout" , "-b" , branch_name ,
57- cwd = repo_path_str ,
58- stdout = asyncio . subprocess . PIPE ,
59- stderr = asyncio .subprocess .PIPE ,
60- text = True
61- )
62-
63- stdout , stderr = await asyncio .wait_for (process .communicate (), timeout = 10 )
64-
65- if process .returncode != 0 :
66- raise subprocess .CalledProcessError (process .returncode , ["git" , "checkout" , "-b" , branch_name ], stdout , stderr )
67-
54+ if checkout :
55+ # Create and checkout new branch
56+ process = await asyncio . create_subprocess_exec (
57+ "git" , "checkout" , "-b" , branch_name ,
58+ cwd = repo_path_str ,
59+ stdout = asyncio .subprocess .PIPE ,
60+ stderr = asyncio . subprocess . PIPE
61+ )
62+
63+ stdout , stderr = await asyncio .wait_for (process .communicate (), timeout = 10 )
64+
65+ if process .returncode != 0 :
66+ raise subprocess .CalledProcessError (process .returncode , ["git" , "checkout" , "-b" , branch_name ], stdout , stderr )
67+
6868 # Add all changes
6969 process = await asyncio .create_subprocess_exec (
7070 "git" , "add" , "." ,
7171 cwd = repo_path_str ,
7272 stdout = asyncio .subprocess .PIPE ,
73- stderr = asyncio .subprocess .PIPE ,
74- text = True
73+ stderr = asyncio .subprocess .PIPE
7574 )
7675
7776 stdout , stderr = await asyncio .wait_for (process .communicate (), timeout = 30 )
@@ -84,8 +83,7 @@ async def commit_and_push_changes(repo_path: Path, branch_name: str = None, comm
8483 "git" , "commit" , "-m" , commit_message ,
8584 cwd = repo_path_str ,
8685 stdout = asyncio .subprocess .PIPE ,
87- stderr = asyncio .subprocess .PIPE ,
88- text = True
86+ stderr = asyncio .subprocess .PIPE
8987 )
9088
9189 stdout , stderr = await asyncio .wait_for (process .communicate (), timeout = 30 )
@@ -101,8 +99,7 @@ async def commit_and_push_changes(repo_path: Path, branch_name: str = None, comm
10199 "git" , "push" , "origin" , branch_name ,
102100 cwd = repo_path_str ,
103101 stdout = asyncio .subprocess .PIPE ,
104- stderr = asyncio .subprocess .PIPE ,
105- text = True
102+ stderr = asyncio .subprocess .PIPE
106103 )
107104
108105 stdout , stderr = await asyncio .wait_for (process .communicate (), timeout = 60 )
0 commit comments