@@ -20,7 +20,7 @@ fn spawn_git_command(
2020 args : & [ & str ] ,
2121 env : & [ ( & str , & str ) ] ,
2222) -> anyhow:: Result < ( ) > {
23- log :: debug !( "spawn_git_command: {:?}" , args) ;
23+ eprintln ! ( "spawn_git_command: {:?}" , args) ;
2424
2525 let mut command = ProcessCommand :: new ( "git" ) ;
2626 command. current_dir ( cwd) . args ( args) ;
@@ -292,12 +292,9 @@ fn apply_josh_filtering(
292292 ) ;
293293
294294 // Open Josh transaction
295- let transaction = josh:: cache:: TransactionContext :: from_env ( cache. clone ( ) )
296- . map_err ( from_josh_err)
297- . context ( "Failed TransactionContext::from_env" ) ?
295+ let transaction = josh:: cache:: TransactionContext :: new ( repo_path, cache. clone ( ) )
298296 . open ( None )
299- . map_err ( from_josh_err)
300- . context ( "Failed TransactionContext::open" ) ?;
297+ . map_err ( from_josh_err) ?;
301298
302299 let repo = transaction. repo ( ) ;
303300
@@ -355,6 +352,24 @@ fn apply_josh_filtering(
355352 Ok ( ( ) )
356353}
357354
355+ fn to_absolute_remote_url ( url : & str ) -> anyhow:: Result < String > {
356+ if url. starts_with ( "http://" )
357+ || url. starts_with ( "https://" )
358+ || url. starts_with ( "ssh://" )
359+ || url. starts_with ( "file://" )
360+ {
361+ Ok ( url. to_owned ( ) )
362+ } else {
363+ // For local paths, make them absolute
364+ let path = std:: fs:: canonicalize ( & url)
365+ . with_context ( || format ! ( "Failed to resolve path {}" , url) ) ?
366+ . display ( )
367+ . to_string ( ) ;
368+
369+ Ok ( format ! ( "file://{}" , path) )
370+ }
371+ }
372+
358373fn handle_clone ( args : & CloneArgs ) -> anyhow:: Result < ( ) > {
359374 // Use the provided output directory
360375 let output_dir = args. out . clone ( ) ;
@@ -365,30 +380,10 @@ fn handle_clone(args: &CloneArgs) -> anyhow::Result<()> {
365380 // Initialize a new git repository inside the directory using git2
366381 git2:: Repository :: init ( & output_dir) . context ( "Failed to initialize git repository" ) ?;
367382
368- let original_dir = std:: env:: current_dir ( ) ?;
369-
370- // Make the URL absolute if it's a relative path (for local repositories)
371- let absolute_url = if args. url . starts_with ( "http://" )
372- || args. url . starts_with ( "https://" )
373- || args. url . starts_with ( "ssh://" )
374- {
375- args. url . clone ( )
376- } else {
377- // For local paths, make them absolute relative to the original directory
378- let absolute_path = if args. url . starts_with ( '/' ) {
379- // Already absolute
380- args. url . clone ( )
381- } else {
382- // Relative to original directory
383- original_dir. join ( & args. url ) . to_string_lossy ( ) . to_string ( )
384- } ;
385- absolute_path
386- } ;
387-
388383 // Use handle_remote_add to add the remote with the filter
389384 let remote_add_args = RemoteAddArgs {
390385 name : "origin" . to_string ( ) ,
391- url : absolute_url ,
386+ url : to_absolute_remote_url ( & args . url ) ? ,
392387 filter : args. filter . clone ( ) ,
393388 keep_trivial_merges : args. keep_trivial_merges ,
394389 } ;
@@ -816,15 +811,7 @@ fn handle_remote_add_repo(args: &RemoteAddArgs, repo_path: &std::path::Path) ->
816811 let repo = git2:: Repository :: open ( repo_path) . context ( "Failed to open repository" ) ?;
817812
818813 // Store the remote information in josh-remote config instead of adding a git remote
819- let remote_path = if args. url . starts_with ( "http" ) || args. url . starts_with ( "ssh://" ) {
820- args. url . clone ( )
821- } else {
822- // For local paths, make them absolute
823- std:: fs:: canonicalize ( & args. url )
824- . with_context ( || format ! ( "Failed to resolve path {}" , args. url) ) ?
825- . display ( )
826- . to_string ( )
827- } ;
814+ let remote_url = to_absolute_remote_url ( & args. url ) ?;
828815
829816 // Store the filter in git config per remote
830817 // Append ":prune=trivial-merge" to all filters unless --keep-trivial-merges flag is set
@@ -838,7 +825,7 @@ fn handle_remote_add_repo(args: &RemoteAddArgs, repo_path: &std::path::Path) ->
838825
839826 // Store remote URL in josh-remote section
840827 config
841- . set_str ( & format ! ( "josh-remote.{}.url" , args. name) , & remote_path )
828+ . set_str ( & format ! ( "josh-remote.{}.url" , args. name) , & remote_url )
842829 . context ( "Failed to store remote URL in git config" ) ?;
843830
844831 // Store filter in josh-remote section
@@ -857,17 +844,8 @@ fn handle_remote_add_repo(args: &RemoteAddArgs, repo_path: &std::path::Path) ->
857844
858845 // Set up a git remote that points to "." with a refspec to fetch filtered refs
859846 // Add remote pointing to current directory
860- spawn_git_command (
861- repo_path,
862- & [
863- "remote" ,
864- "add" ,
865- & args. name ,
866- & format ! ( "file://{}" , repo_path. to_string_lossy( ) ) ,
867- ] ,
868- & [ ] ,
869- )
870- . context ( "Failed to add git remote" ) ?;
847+ spawn_git_command ( repo_path, & [ "remote" , "add" , & args. name , & remote_url] , & [ ] )
848+ . context ( "Failed to add git remote" ) ?;
871849
872850 // Set up namespace configuration for the remote
873851 let namespace = format ! ( "josh-{}" , args. name) ;
0 commit comments