MCPcopy Create free account
hub / github.com/dtormoen/tsk-tsk / fetch_single_submodule_changes

Method fetch_single_submodule_changes

src/git.rs:976–1133  ·  view source on GitHub ↗

Fetch changes for a single submodule from copied repo to original repo. The branch_name is used to create a matching branch in the original submodule.

(
        &self,
        copied_repo: &Path,
        original_repo: &Path,
        submodule: &SubmoduleInfo,
        branch_name: &str,
    )

Source from the content-addressed store, hash-verified

974 /// Fetch changes for a single submodule from copied repo to original repo.
975 /// The branch_name is used to create a matching branch in the original submodule.
976 async fn fetch_single_submodule_changes(
977 &self,
978 copied_repo: &Path,
979 original_repo: &Path,
980 submodule: &SubmoduleInfo,
981 branch_name: &str,
982 ) -> Result<(), String> {
983 // Find the module git directory by reading the submodule's .git file
984 let copied_submodule_path = copied_repo.join(&submodule.path);
985 let copied_git_file = copied_submodule_path.join(".git");
986
987 if !copied_git_file.exists() {
988 // Submodule wasn't properly set up in copied repo, skip it
989 return Ok(());
990 }
991
992 // Read the .git file to find the module directory
993 let git_content = tokio::fs::read_to_string(&copied_git_file)
994 .await
995 .map_err(|e| format!("Failed to read .git file: {}", e))?;
996
997 let gitdir_line = git_content.trim();
998 if !gitdir_line.starts_with("gitdir: ") {
999 return Err("Invalid .git file format in submodule".to_string());
1000 }
1001
1002 let gitdir_rel_path = gitdir_line.strip_prefix("gitdir: ").unwrap_or("").trim();
1003
1004 // Resolve the gitdir path relative to the submodule directory
1005 let copied_module_git = if gitdir_rel_path.starts_with('/') {
1006 // Absolute path (unusual, but handle it)
1007 PathBuf::from(gitdir_rel_path)
1008 } else {
1009 // Relative path - resolve from submodule directory
1010 copied_submodule_path.join(gitdir_rel_path)
1011 };
1012
1013 // Canonicalize to resolve .. components
1014 let copied_module_git = copied_module_git.canonicalize().map_err(|e| {
1015 format!(
1016 "Failed to resolve module git path '{}': {}",
1017 copied_module_git.display(),
1018 e
1019 )
1020 })?;
1021
1022 if !copied_module_git.exists() {
1023 return Err(format!(
1024 "Module git directory does not exist: {}",
1025 copied_module_git.display()
1026 ));
1027 }
1028
1029 // Check if original submodule exists and is a valid git repository
1030 let original_submodule = original_repo.join(&submodule.path);
1031 if !original_submodule.exists() {
1032 // Submodule doesn't exist in original - nothing to fetch to
1033 return Ok(());

Callers 1

Calls 4

is_git_repositoryFunction · 0.85
add_remoteFunction · 0.85
remove_remoteFunction · 0.85
successMethod · 0.80

Tested by

no test coverage detected