@@ -23,7 +23,7 @@ use crate::cli::ConversationState;
2323use crate :: os:: Os ;
2424
2525// The shadow repo path that MUST be appended with a session-specific directory
26- // pub const SHADOW_REPO_DIR: &str = "/Users/kiranbug /.amazonq/captures/";
26+ // pub const SHADOW_REPO_DIR: &str = "/Users/aws /.amazonq/cli- captures/";
2727
2828// CURRENT APPROACH:
2929// We only enable automatically enable checkpoints when the user is already in a git repo.
@@ -64,45 +64,8 @@ impl CaptureManager {
6464 "Must be in a git repo for automatic capture initialization. Use /capture init to manually enable captures."
6565 ) ;
6666 }
67-
68- let path = shadow_path. as_ref ( ) ;
69- os. fs . create_dir_all ( path) . await ?;
70-
71- let repo_root = get_git_repo_root ( ) ?;
72- let output = Command :: new ( "git" )
73- . args ( [ "clone" , & repo_root. to_string_lossy ( ) , & path. to_string_lossy ( ) ] )
74- . output ( ) ?;
75-
76- if !output. status . success ( ) {
77- bail ! ( "git clone failed: {}" , String :: from_utf8_lossy( & output. stdout) ) ;
78- }
79-
80- let cloned_git_dir = path. join ( ".git" ) ;
81-
82- config ( & cloned_git_dir. to_string_lossy ( ) ) ?;
83- stage_commit_tag ( & cloned_git_dir. to_string_lossy ( ) , "Initial capture" , "0" ) ?;
84-
85- let captures = vec ! [ Capture {
86- tag: "0" . to_string( ) ,
87- timestamp: Local :: now( ) ,
88- message: "Initial capture" . to_string( ) ,
89- history_index: 0 ,
90- is_turn: true ,
91- tool_name: None ,
92- } ] ;
93-
94- let mut tag_to_index = HashMap :: new ( ) ;
95- tag_to_index. insert ( "0" . to_string ( ) , 0 ) ;
96-
97- Ok ( Self {
98- shadow_repo_path : cloned_git_dir,
99- captures,
100- tag_to_index,
101- num_turns : 0 ,
102- num_tools_this_turn : 0 ,
103- last_user_message : None ,
104- user_message_lock : false ,
105- } )
67+ // Reuse bare repo init to keep storage model consistent.
68+ Self :: manual_init ( os, shadow_path) . await
10669 }
10770
10871 pub async fn manual_init ( os : & Os , path : impl AsRef < Path > ) -> Result < Self > {
@@ -192,13 +155,16 @@ impl CaptureManager {
192155 Ok ( ( ) )
193156 }
194157
195- pub async fn clean ( & self , os : & Os ) -> Result < ( ) > {
196- let path = if self . shadow_repo_path . file_name ( ) . unwrap ( ) == ".git" {
197- self . shadow_repo_path . parent ( ) . unwrap ( )
198- } else {
199- self . shadow_repo_path . as_path ( )
200- } ;
158+ pub async fn clean ( & self , os : & Os ) -> eyre:: Result < ( ) > {
159+ // In bare mode, shadow_repo_path is the session directory to delete.
160+ let path = & self . shadow_repo_path ;
161+
201162 println ! ( "Deleting path: {}" , path. display( ) ) ;
163+
164+ if !path. exists ( ) {
165+ return Ok ( ( ) ) ;
166+ }
167+
202168 os. fs . remove_dir_all ( path) . await ?;
203169 Ok ( ( ) )
204170 }
@@ -269,20 +235,6 @@ pub fn is_in_git_repo() -> bool {
269235 . unwrap_or ( false )
270236}
271237
272- pub fn get_git_repo_root ( ) -> Result < PathBuf > {
273- let output = Command :: new ( "git" ) . args ( [ "rev-parse" , "--show-toplevel" ] ) . output ( ) ?;
274-
275- if !output. status . success ( ) {
276- bail ! (
277- "Failed to get git repo root: {}" ,
278- String :: from_utf8_lossy( & output. stdout)
279- ) ;
280- }
281-
282- let root = String :: from_utf8 ( output. stdout ) ?. trim ( ) . to_string ( ) ;
283- Ok ( PathBuf :: from ( root) )
284- }
285-
286238pub fn stage_commit_tag ( shadow_path : & str , commit_message : & str , tag : & str ) -> Result < ( ) > {
287239 let git_dir_arg = format ! ( "--git-dir={}" , shadow_path) ;
288240 let output = Command :: new ( "git" )
0 commit comments