Skip to main content

hyprstream_p2p/git/
remote_helper.rs

1//! Git Remote Helper for gittorrent:// protocol
2//!
3//! This module implements the git-remote-gittorrent binary that allows
4//! standard Git commands to work with gittorrent:// URLs transparently.
5//!
6//! Usage: git clone gittorrent://example.com/user/repo
7
8use crate::service::{GitTorrentConfig, GitTorrentService};
9use crate::{Error, GitTorrentUrl, Result};
10
11use std::collections::HashMap;
12use std::io::{self, BufRead, Write};
13use std::path::{Path, PathBuf};
14
15/// Git remote helper for gittorrent:// protocol
16pub struct GitRemoteHelper {
17    /// GitTorrent service instance
18    service: GitTorrentService,
19    /// Remote repository URL
20    remote_url: Option<GitTorrentUrl>,
21    /// Local repository path
22    local_repo: Option<PathBuf>,
23    /// Git capabilities
24    capabilities: Vec<String>,
25}
26
27impl GitRemoteHelper {
28    /// Create a new Git remote helper with default config
29    pub async fn new() -> Result<Self> {
30        let config = GitTorrentConfig::default();
31        Self::new_with_config(config).await
32    }
33
34    /// Create a new Git remote helper with custom config
35    pub async fn new_with_config(config: GitTorrentConfig) -> Result<Self> {
36        let service = GitTorrentService::new(config).await?;
37
38        Ok(Self {
39            service,
40            remote_url: None,
41            local_repo: None,
42            capabilities: vec![
43                "connect".to_owned(),
44                "list".to_owned(),
45                "fetch".to_owned(),
46                "push".to_owned(),
47                "option".to_owned(),
48            ],
49        })
50    }
51
52    /// Run the Git remote helper protocol
53    pub async fn run(&mut self) -> Result<()> {
54        let stdin = io::stdin();
55        let mut stdout = io::stdout();
56        let mut batch_commands = Vec::new();
57        let mut in_batch = false;
58
59        // Read commands from stdin and respond
60        for line in stdin.lock().lines() {
61            let line = line.map_err(Error::from)?;
62            let line = line.trim();
63
64            tracing::debug!("Git remote helper received: '{}'", line);
65
66            // Handle blank lines (end of batch or empty input)
67            if line.is_empty() {
68                if in_batch {
69                    // Process the batch of commands
70                    match self.process_batch(&batch_commands).await {
71                        Ok(()) => {
72                            // Send blank line to indicate batch completion
73                            writeln!(stdout).map_err(Error::from)?;
74                            stdout.flush().map_err(Error::from)?;
75                        }
76                        Err(e) => {
77                            writeln!(stdout, "error {e}").map_err(Error::from)?;
78                            stdout.flush().map_err(Error::from)?;
79                            return Err(e);
80                        }
81                    }
82                    batch_commands.clear();
83                    in_batch = false;
84                } else {
85                    // Just an empty line, ignore
86                    continue;
87                }
88            } else {
89                // Check if this is a batch command
90                let parts: Vec<&str> = line.split_whitespace().collect();
91                if !parts.is_empty() && (parts[0] == "fetch" || parts[0] == "push") {
92                    // Start or continue a batch
93                    batch_commands.push(line.to_owned());
94                    in_batch = true;
95                } else {
96                    // Handle single command immediately
97                    match self.handle_command(line).await {
98                        Ok(response) => {
99                            if let Some(resp) = response {
100                                // Git remote helper protocol: write response to stdout
101                                write!(stdout, "{resp}").map_err(Error::from)?;
102                                stdout.flush().map_err(Error::from)?;
103                            }
104                        }
105                        Err(e) => {
106                            writeln!(stdout, "error {e}").map_err(Error::from)?;
107                            stdout.flush().map_err(Error::from)?;
108                            return Err(e);
109                        }
110                    }
111                }
112            }
113        }
114
115        // Handle any remaining batch commands
116        if !batch_commands.is_empty() {
117            self.process_batch(&batch_commands).await?;
118            writeln!(stdout).map_err(Error::from)?;
119            stdout.flush().map_err(Error::from)?;
120        }
121
122        Ok(())
123    }
124
125    /// Handle a single Git remote helper command
126    async fn handle_command(&mut self, command: &str) -> Result<Option<String>> {
127        let parts: Vec<&str> = command.split_whitespace().collect();
128        tracing::debug!("Handling command: '{}' -> parts: {:?}", command, parts);
129        if parts.is_empty() {
130            return Ok(None);
131        }
132
133        match parts[0] {
134            "capabilities" => Ok(Some(self.handle_capabilities())),
135            "list" => self.handle_list(&parts[1..]).await,
136            "connect" => self.handle_connect(&parts[1..]).await,
137            "option" => self.handle_option(&parts[1..]).await,
138            "" => Ok(None), // Empty line
139            _ => {
140                tracing::warn!("Unknown git remote helper command: {}", command);
141                Ok(None)
142            }
143        }
144    }
145
146    /// Process a batch of commands (for fetch/push)
147    async fn process_batch(&mut self, commands: &[String]) -> Result<()> {
148        for command in commands {
149            let parts: Vec<&str> = command.split_whitespace().collect();
150            if parts.is_empty() {
151                continue;
152            }
153
154            match parts[0] {
155                "fetch" => {
156                    self.handle_fetch(&parts[1..]).await?;
157                }
158                "push" => {
159                    let result = self.handle_push(&parts[1..]).await?;
160                    // Git remote helper protocol: write push result to stdout
161                    write!(io::stdout(), "{result}").map_err(Error::from)?;
162                }
163                _ => {
164                    return Err(Error::other(format!("Invalid batch command: {}", parts[0])));
165                }
166            }
167        }
168        Ok(())
169    }
170
171    /// Handle capabilities command
172    fn handle_capabilities(&self) -> String {
173        let mut response = String::new();
174        for cap in &self.capabilities {
175            response.push_str(&format!("{cap}\n"));
176        }
177        response.push('\n'); // End with empty line
178        response
179    }
180
181    /// Handle list command - list remote references
182    async fn handle_list(&mut self, args: &[&str]) -> Result<Option<String>> {
183        let for_push = args.first().map(|&s| s == "for-push").unwrap_or(false);
184        tracing::debug!("List command, for_push: {}", for_push);
185
186        let url = self
187            .remote_url
188            .as_ref()
189            .ok_or_else(|| Error::other("No remote URL set"))?;
190
191        // Try to get refs from P2P network, fall back to defaults if not available
192        let refs = self.query_remote_refs(url).await?;
193
194        let mut response = String::new();
195        for (ref_name, commit_hash) in &refs {
196            response.push_str(&format!("{commit_hash} {ref_name}\n"));
197        }
198
199        // Set HEAD to point to main or master if available
200        if refs.contains_key("refs/heads/main") {
201            response.push_str("@refs/heads/main HEAD\n");
202        } else if refs.contains_key("refs/heads/master") {
203            response.push_str("@refs/heads/master HEAD\n");
204        }
205
206        response.push('\n'); // End with empty line
207
208        tracing::info!(
209            "Listed {} references for {}",
210            refs.len(),
211            match url {
212                GitTorrentUrl::Commit { hash } => format!("commit {hash}"),
213                GitTorrentUrl::CommitWithRefs { hash } => format!("commit {hash} (with refs)"),
214                GitTorrentUrl::GitServer { server, repo } => format!("{server}/{repo}"),
215                GitTorrentUrl::Username { username } => username.clone(),
216            }
217        );
218
219        Ok(Some(response))
220    }
221
222    /// Handle connect command - establish connection to remote
223    async fn handle_connect(&mut self, args: &[&str]) -> Result<Option<String>> {
224        tracing::debug!("Connect called with {} args: {:?}", args.len(), args);
225        if args.is_empty() {
226            return Err(Error::other("connect command requires service"));
227        }
228
229        let service_name = args[0];
230
231        // URL should already be set from command line arguments
232        if self.remote_url.is_none() {
233            return Err(Error::other("Remote URL not set"));
234        }
235
236        tracing::info!(
237            "Connected for service {} to {:?}",
238            service_name,
239            self.remote_url
240        );
241
242        // For GitTorrent, we don't support the bidirectional Git protocol directly.
243        // Instead, we use the import/export capabilities through the remote helper protocol.
244        // Tell Git to fall back to using the remote helper commands (list, fetch, push)
245        Ok(Some("fallback\n".to_owned()))
246    }
247
248    /// Handle fetch command in batch
249    async fn handle_fetch(&mut self, args: &[&str]) -> Result<()> {
250        if args.is_empty() {
251            return Err(Error::other("fetch command requires arguments"));
252        }
253
254        let commit_hash = args[0];
255        let ref_name = if args.len() > 1 {
256            args[1]
257        } else {
258            "refs/heads/main"
259        };
260
261        let url = self
262            .remote_url
263            .as_ref()
264            .ok_or_else(|| Error::other("No remote URL set"))?;
265
266        let local_repo = self
267            .local_repo
268            .as_ref()
269            .ok_or_else(|| Error::other("No local repository path set"))?;
270
271        tracing::info!("Fetching {} {} from GitTorrent", commit_hash, ref_name);
272
273        // In a full implementation, this would:
274        // 1. Query the P2P network for the repository
275        // 2. Download Git objects from peers
276        // 3. Process LFS/XET files
277        // 4. Import objects into local Git repository
278
279        self.fetch_repository_data(url, local_repo, commit_hash, ref_name)
280            .await?;
281        Ok(())
282    }
283
284    /// Handle push command in batch
285    async fn handle_push(&mut self, args: &[&str]) -> Result<String> {
286        if args.is_empty() {
287            return Err(Error::other("push command requires refspec"));
288        }
289
290        let refspec = args[0];
291        let (src_ref, dst_ref) = if let Some(colon_pos) = refspec.find(':') {
292            let src = &refspec[..colon_pos];
293            let dst = &refspec[colon_pos + 1..];
294            // Handle force push prefix
295            let src = src.strip_prefix('+').unwrap_or(src);
296            (src, dst)
297        } else {
298            // If no colon, assume same ref name for both src and dst
299            (refspec, refspec)
300        };
301
302        let url = self
303            .remote_url
304            .as_ref()
305            .ok_or_else(|| Error::other("No remote URL set"))?;
306
307        let local_repo = self
308            .local_repo
309            .as_ref()
310            .ok_or_else(|| Error::other("No local repository path set"))?;
311
312        tracing::info!("Pushing {} to {} on GitTorrent", src_ref, dst_ref);
313
314        // In a full implementation, this would:
315        // 1. Extract Git objects to push
316        // 2. Process large files with LFS/XET
317        // 3. Distribute chunks to P2P network
318        // 4. Announce updated repository metadata
319
320        match self
321            .push_repository_data(url, local_repo, src_ref, dst_ref)
322            .await
323        {
324            Ok(()) => Ok(format!("ok {dst_ref}\n")),
325            Err(e) => Ok(format!("error {dst_ref} {e}\n")),
326        }
327    }
328
329    /// Handle option command - set options
330    async fn handle_option(&mut self, args: &[&str]) -> Result<Option<String>> {
331        if args.len() < 2 {
332            return Err(Error::other("option command requires key and value"));
333        }
334
335        let key = args[0];
336        let value = args[1];
337
338        match key {
339            "verbosity" => {
340                tracing::debug!("Set verbosity to {}", value);
341                Ok(Some("ok\n".to_owned()))
342            }
343            "progress" => {
344                tracing::debug!("Set progress to {}", value);
345                Ok(Some("ok\n".to_owned()))
346            }
347            _ => {
348                tracing::debug!("Unknown option: {} = {}", key, value);
349                Ok(Some("unsupported\n".to_owned()))
350            }
351        }
352    }
353
354    /// Set local repository path
355    pub fn set_local_repo(&mut self, path: PathBuf) -> Result<()> {
356        self.local_repo = Some(path);
357        Ok(())
358    }
359
360    /// Fetch repository data from P2P network
361    async fn fetch_repository_data(
362        &self,
363        url: &GitTorrentUrl,
364        local_repo: &Path,
365        commit_hash: &str,
366        ref_name: &str,
367    ) -> Result<()> {
368        tracing::info!(
369            "Fetching repository data for {} at {}",
370            ref_name,
371            commit_hash
372        );
373
374        // Handle commit-based URLs differently
375        match url {
376            GitTorrentUrl::Commit { hash } | GitTorrentUrl::CommitWithRefs { hash } => {
377                // For commit-based URLs, try to clone from DHT directly
378                if let Err(e) = self
379                    .clone_from_dht(hash, local_repo, url.includes_refs())
380                    .await
381                {
382                    tracing::warn!(
383                        "Failed to clone from DHT: {}, falling back to basic repository",
384                        e
385                    );
386                    self.create_basic_repository(local_repo, hash.as_str(), ref_name, url)
387                        .await?;
388                }
389            }
390            _ => {
391                // Legacy behavior for other URL types
392                let repo_identifier = match url {
393                    GitTorrentUrl::GitServer { server, repo } => format!("{server}/{repo}"),
394                    GitTorrentUrl::Username { username } => username.clone(),
395                    _ => unreachable!(),
396                };
397
398                // Try to query repository metadata from P2P network
399                match self.service.query_repository(&repo_identifier).await? {
400                    Some(metadata) => {
401                        let path = local_repo.to_path_buf();
402                        let ref_name = ref_name.to_owned();
403                        let url_clone = url.clone();
404                        tokio::task::spawn_blocking(move || {
405                            let repo = if !path.join(".git").exists() {
406                                git2::Repository::init_bare(&path)?
407                            } else {
408                                git2::Repository::open(&path)?
409                            };
410                            Self::create_git_repo_from_metadata_sync(
411                                &repo, &metadata, &ref_name, &url_clone,
412                            )
413                        })
414                        .await
415                        .map_err(|e| crate::Error::other(format!("Task join error: {e}")))??;
416                    }
417                    None => {
418                        tracing::info!("Repository metadata not found in P2P network, creating basic repository");
419                        self.create_basic_repository(local_repo, &repo_identifier, ref_name, url)
420                            .await?;
421                    }
422                }
423            }
424        }
425
426        tracing::debug!(
427            "Successfully fetched repository data to {}",
428            local_repo.display()
429        );
430        Ok(())
431    }
432
433    /// Clone repository for a commit hash via the object facade.
434    ///
435    /// The libp2p Kademlia DHT path this once wrapped was retired in F3 (#901).
436    /// Object-plane clone-over-iroh-blobs is not wired through the remote helper
437    /// yet, so this still returns `Err` until that lands.
438    async fn clone_from_dht(
439        &self,
440        commit_hash: &crate::types::Sha256Hash,
441        _target_path: &Path,
442        _include_refs: bool,
443    ) -> Result<()> {
444        tracing::info!(
445            "Clone for commit {} requested; object-plane clone not wired into the remote helper yet",
446            commit_hash
447        );
448
449        Err(crate::Error::other(
450            "object-plane cloning not yet implemented in remote helper",
451        ))
452    }
453
454    /// Create a basic functional repository
455    async fn create_basic_repository(
456        &self,
457        local_repo: &Path,
458        _identifier: &str,
459        ref_name: &str,
460        url: &GitTorrentUrl,
461    ) -> Result<()> {
462        let path = local_repo.to_path_buf();
463        let ref_name = ref_name.to_owned();
464        let url_str = url.to_string();
465
466        tokio::task::spawn_blocking(move || {
467            // Init or open the repository
468            let repo = if !path.join(".git").exists() {
469                git2::Repository::init_bare(&path)?
470            } else {
471                git2::Repository::open(&path)?
472            };
473
474            // Create initial commit with empty tree (same as create_functional_git_repo)
475            let sig = git2::Signature::new("GitTorrent", "gittorrent@example.com", &git2::Time::new(1234567890, 0))?;
476
477            let tree_id = {
478                let mut tree_builder = repo.treebuilder(None)?;
479                let readme_content = format!("# GitTorrent Repository\n\nThis repository is hosted via GitTorrent.\n\nURL: {url_str}\n");
480                let readme_oid = repo.blob(readme_content.as_bytes())?;
481                tree_builder.insert("README.md", readme_oid, 0o100644)?;
482                tree_builder.write()?
483            };
484
485            let tree = repo.find_tree(tree_id)?;
486
487            let commit_id = repo.commit(
488                None,
489                &sig,
490                &sig,
491                "Initial GitTorrent commit",
492                &tree,
493                &[],
494            )?;
495
496            let ref_name_normalized = if ref_name.starts_with("refs/") {
497                ref_name.clone()
498            } else {
499                format!("refs/heads/{ref_name}")
500            };
501
502            repo.reference(&ref_name_normalized, commit_id, true, "Initial commit")?;
503
504            if ref_name.contains("main") || ref_name.contains("master") {
505                repo.set_head(&ref_name_normalized)?;
506            }
507
508            tracing::debug!("Created functional Git repository with commit {}", commit_id);
509            Ok(())
510        })
511        .await
512        .map_err(|e| crate::Error::other(format!("Task join error: {e}")))?
513    }
514
515    /// Push repository data to P2P network
516    async fn push_repository_data(
517        &self,
518        _url: &GitTorrentUrl,
519        local_repo: &Path,
520        src_ref: &str,
521        dst_ref: &str,
522    ) -> Result<()> {
523        tracing::info!("Pushing {} to {} for repository", src_ref, dst_ref);
524
525        // Announce repository to P2P network
526        self.service.announce_repository(local_repo).await?;
527
528        // In a real implementation, this would:
529        // 1. Extract objects to be pushed
530        // 2. Create and distribute Git pack files
531        // 3. Store XET chunks in P2P network
532        // 4. Update repository metadata in DHT
533
534        Ok(())
535    }
536
537    /// Create a Git repository from P2P network metadata
538    fn create_git_repo_from_metadata_sync(
539        repo: &git2::Repository,
540        metadata: &crate::service::RepositoryMetadata,
541        ref_name: &str,
542        url: &GitTorrentUrl,
543    ) -> Result<()> {
544        let sig = git2::Signature::new(
545            "GitTorrent",
546            "gittorrent@example.com",
547            &git2::Time::new(1234567890, 0),
548        )?;
549
550        let tree_id = {
551            let mut tree_builder = repo.treebuilder(None)?;
552
553            let readme_content = format!(
554                "# GitTorrent Repository\n\nThis repository is hosted via GitTorrent P2P network.\n\n\
555                URL: {}\n\
556                Publisher: {}\n\
557                Size: {} bytes\n\
558                References: {}\n\
559                LFS Files: {}\n\
560                Last Updated: {}\n",
561                url,
562                metadata.publisher.as_deref().unwrap_or("Unknown"),
563                metadata.size_bytes,
564                metadata.refs.len(),
565                metadata.lfs_chunks.len(),
566                metadata.last_updated
567            );
568
569            let readme_oid = repo.blob(readme_content.as_bytes())?;
570            tree_builder.insert("README.md", readme_oid, 0o100644)?;
571
572            let metadata_content = serde_json::to_string_pretty(metadata)
573                .map_err(|e| Error::other(format!("Failed to serialize metadata: {e}")))?;
574            let metadata_oid = repo.blob(metadata_content.as_bytes())?;
575            tree_builder.insert(".gittorrent-metadata.json", metadata_oid, 0o100644)?;
576
577            tree_builder.write()?
578        };
579
580        let tree = repo.find_tree(tree_id)?;
581
582        let commit_id = repo.commit(
583            None,
584            &sig,
585            &sig,
586            "Initial GitTorrent commit from P2P network",
587            &tree,
588            &[],
589        )?;
590
591        let ref_name_normalized = if ref_name.starts_with("refs/") {
592            ref_name.to_owned()
593        } else {
594            format!("refs/heads/{ref_name}")
595        };
596
597        repo.reference(
598            &ref_name_normalized,
599            commit_id,
600            true,
601            "Initial commit from P2P",
602        )?;
603
604        if ref_name.contains("main") || ref_name.contains("master") {
605            repo.set_head(&ref_name_normalized)?;
606        }
607
608        tracing::debug!(
609            "Created Git repository from P2P metadata with commit {}",
610            commit_id
611        );
612        Ok(())
613    }
614
615    /// Query remote repository references (via P2P or fallback)
616    async fn query_remote_refs(&self, url: &GitTorrentUrl) -> Result<HashMap<String, String>> {
617        // TODO: In a full implementation, this would query the P2P network
618        // For now, check if we have a local copy or return defaults
619
620        // Check if we have cached repository locally
621        if let Some(local_repo) = &self.local_repo {
622            if let Ok(refs) = self.get_repository_refs_git2(local_repo).await {
623                return Ok(refs);
624            }
625        }
626
627        // Try to query via GitTorrent service
628        // TODO: Implement P2P repository discovery
629
630        // Fallback to common default references
631        let mut refs = HashMap::new();
632
633        // Create a default commit SHA (empty tree)
634        let empty_tree_sha = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
635
636        refs.insert("refs/heads/main".to_owned(), empty_tree_sha.to_owned());
637        refs.insert("refs/heads/master".to_owned(), empty_tree_sha.to_owned());
638
639        tracing::debug!("Using fallback references for {}", url.to_string());
640
641        Ok(refs)
642    }
643
644    /// Get repository references using git2
645    async fn get_repository_refs_git2(&self, repo_path: &Path) -> Result<HashMap<String, String>> {
646        if !repo_path.exists() {
647            return Ok(HashMap::new());
648        }
649
650        let path = repo_path.to_path_buf();
651        let refs = super::with_repo_blocking(path.clone(), |repo| {
652            let mut refs = HashMap::new();
653
654            let ref_iter = repo.references().map_err(Error::from)?;
655            for reference in ref_iter {
656                let reference = reference.map_err(Error::from)?;
657
658                if let Some(name) = reference.name() {
659                    if let Some(target) = reference.target() {
660                        refs.insert(name.to_owned(), target.to_string());
661                    } else if let Some(symbolic_target) = reference.symbolic_target() {
662                        if let Ok(resolved) =
663                            repo.resolve_reference_from_short_name(symbolic_target)
664                        {
665                            if let Some(target) = resolved.target() {
666                                refs.insert(name.to_owned(), target.to_string());
667                            }
668                        }
669                    }
670                }
671            }
672
673            Ok(refs)
674        })
675        .await;
676
677        // If open fails (not a git repo), return empty map
678        match refs {
679            Ok(r) => {
680                tracing::debug!(
681                    "Found {} references in repository at {}",
682                    r.len(),
683                    repo_path.display()
684                );
685                Ok(r)
686            }
687            Err(_) => Ok(HashMap::new()),
688        }
689    }
690}
691
692/// Entry point for git-remote-gittorrent binary
693pub async fn run_git_remote_helper(
694    config: Option<GitTorrentConfig>,
695    url: Option<&str>,
696) -> Result<()> {
697    let mut helper = match config {
698        Some(config) => GitRemoteHelper::new_with_config(config).await?,
699        None => {
700            tracing_subscriber::fmt::init();
701            GitRemoteHelper::new().await?
702        }
703    };
704
705    // Parse and set the remote URL if provided
706    if let Some(url) = url {
707        helper.remote_url = Some(GitTorrentUrl::parse(url)?);
708    }
709
710    // Get repository path from environment
711    if let Ok(git_dir) = std::env::var("GIT_DIR") {
712        let repo_path = PathBuf::from(git_dir);
713        helper.set_local_repo(repo_path)?;
714    }
715
716    // Run the helper protocol
717    helper.run().await?;
718
719    Ok(())
720}
721
722#[cfg(test)]
723mod tests {
724    use super::*;
725    use tempfile::TempDir;
726
727    #[tokio::test]
728    async fn test_git_remote_helper_creation() -> crate::error::Result<()> {
729        let helper = GitRemoteHelper::new().await?;
730        assert_eq!(helper.capabilities.len(), 5);
731        assert!(helper.capabilities.contains(&"connect".to_owned()));
732        assert!(helper.capabilities.contains(&"list".to_owned()));
733        Ok(())
734    }
735
736    #[tokio::test]
737    async fn test_capabilities_command() -> crate::error::Result<()> {
738        let helper = GitRemoteHelper::new().await?;
739        let response = helper.handle_capabilities();
740
741        assert!(response.contains("connect"));
742        assert!(response.contains("list"));
743        assert!(response.contains("fetch"));
744        assert!(response.contains("push"));
745        assert!(response.ends_with("\n\n"));
746        Ok(())
747    }
748
749    #[tokio::test]
750    async fn test_connect_command() -> crate::error::Result<()> {
751        let mut helper = GitRemoteHelper::new().await?;
752
753        // Set remote URL first (as would be done during argument parsing)
754        helper.remote_url = Some(GitTorrentUrl::parse("gittorrent://example.com/user/repo")?);
755
756        let result = helper.handle_connect(&["git-upload-pack"]).await;
757        assert!(result.is_ok());
758        assert!(helper.remote_url.is_some());
759        Ok(())
760    }
761
762    #[tokio::test]
763    async fn test_local_repo_setup() -> crate::error::Result<()> {
764        let temp_dir = TempDir::new()?;
765        let mut helper = GitRemoteHelper::new().await?;
766
767        helper.set_local_repo(temp_dir.path().to_path_buf())?;
768        assert!(helper.local_repo.is_some());
769        Ok(())
770    }
771}