1+ use std:: path:: PathBuf ;
2+
13use clap:: Parser ;
24use codex_common:: CliConfigOverrides ;
35use codex_core:: config:: Config ;
@@ -17,7 +19,10 @@ pub struct ApplyCommand {
1719 #[ clap( flatten) ]
1820 pub config_overrides : CliConfigOverrides ,
1921}
20- pub async fn run_apply_command ( apply_cli : ApplyCommand ) -> anyhow:: Result < ( ) > {
22+ pub async fn run_apply_command (
23+ apply_cli : ApplyCommand ,
24+ cwd : Option < PathBuf > ,
25+ ) -> anyhow:: Result < ( ) > {
2126 let config = Config :: load_with_cli_overrides (
2227 apply_cli
2328 . config_overrides
@@ -29,10 +34,13 @@ pub async fn run_apply_command(apply_cli: ApplyCommand) -> anyhow::Result<()> {
2934 init_chatgpt_token_from_auth ( & config. codex_home ) . await ?;
3035
3136 let task_response = get_task ( & config, apply_cli. task_id ) . await ?;
32- apply_diff_from_task ( task_response) . await
37+ apply_diff_from_task ( task_response, cwd ) . await
3338}
3439
35- pub async fn apply_diff_from_task ( task_response : GetTaskResponse ) -> anyhow:: Result < ( ) > {
40+ pub async fn apply_diff_from_task (
41+ task_response : GetTaskResponse ,
42+ cwd : Option < PathBuf > ,
43+ ) -> anyhow:: Result < ( ) > {
3644 let diff_turn = match task_response. current_diff_task_turn {
3745 Some ( turn) => turn,
3846 None => anyhow:: bail!( "No diff turn found" ) ,
@@ -42,13 +50,17 @@ pub async fn apply_diff_from_task(task_response: GetTaskResponse) -> anyhow::Res
4250 _ => None ,
4351 } ) ;
4452 match output_diff {
45- Some ( output_diff) => apply_diff ( & output_diff. diff ) . await ,
53+ Some ( output_diff) => apply_diff ( & output_diff. diff , cwd ) . await ,
4654 None => anyhow:: bail!( "No PR output item found" ) ,
4755 }
4856}
4957
50- async fn apply_diff ( diff : & str ) -> anyhow:: Result < ( ) > {
51- let toplevel_output = tokio:: process:: Command :: new ( "git" )
58+ async fn apply_diff ( diff : & str , cwd : Option < PathBuf > ) -> anyhow:: Result < ( ) > {
59+ let mut cmd = tokio:: process:: Command :: new ( "git" ) ;
60+ if let Some ( cwd) = cwd {
61+ cmd. current_dir ( cwd) ;
62+ }
63+ let toplevel_output = cmd
5264 . args ( vec ! [ "rev-parse" , "--show-toplevel" ] )
5365 . output ( )
5466 . await ?;
0 commit comments