Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,27 +782,27 @@ impl SubmoduleEntries {
}

/// Add a sparse checkout
pub fn add_checkout(&mut self, name: SubmoduleName, checkout: Vec<String>, replace: bool) {
pub fn add_checkout(&mut self, name: SubmoduleName, checkout: &[String], replace: bool) {
if let Some(sparse_checkouts) = &mut self.sparse_checkouts {
if let Some(existing_checkout) = sparse_checkouts.get(&name) {
match replace {
true => {
// Replace the existing checkout with the new one
sparse_checkouts.insert(name, checkout);
sparse_checkouts.insert(name, checkout.to_vec());
}
false => {
// Append to the existing checkout
let mut new_checkout = existing_checkout.clone();
new_checkout.extend(checkout);
new_checkout.extend_from_slice(checkout);
sparse_checkouts.insert(name, new_checkout);
}
}
} else {
// No existing checkout, just insert the new one
sparse_checkouts.insert(name, checkout);
sparse_checkouts.insert(name, checkout.to_vec());
}
} else {
self.sparse_checkouts = Some(HashMap::from([(name, checkout)]));
self.sparse_checkouts = Some(HashMap::from([(name, checkout.to_vec())]));
}
}

Expand Down
28 changes: 16 additions & 12 deletions src/git_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,14 @@ impl GitManager {
mut entry: crate::config::SubmoduleEntry,
sparse_paths: Option<Vec<String>>,
) -> Result<(), SubmoduleError> {
if let Some(ref paths) = sparse_paths {
entry.sparse_paths = Some(paths.clone());
// Also populate sparse_checkouts so consumers using sparse_checkouts() see the paths
self.config.submodules.add_checkout(name.clone(), paths.clone(), true);
if let Some(paths) = sparse_paths {
// Move the Vec into entry.sparse_paths to avoid cloning,
// then borrow it for add_checkout.
entry.sparse_paths = Some(paths);
if let Some(ref stored_paths) = entry.sparse_paths {
// Also populate sparse_checkouts so consumers using sparse_checkouts() see the paths
self.config.submodules.add_checkout(name.clone(), stored_paths, true);
}
}
// Normalize: convert Unspecified variants to None so they serialize cleanly
if matches!(entry.ignore, Some(SerializableIgnore::Unspecified)) {
Expand Down Expand Up @@ -1425,18 +1429,18 @@ impl GitManager {
.iter()
.map(|p| p.to_string_lossy().to_string())
.collect();
if append_sparse {
let existing = updated.sparse_paths.get_or_insert_with(Vec::new);
existing.extend(new_paths.clone());
} else {
updated.sparse_paths = Some(new_paths.clone());
}

// Keep SubmoduleEntries.sparse_checkouts in sync with sparse_paths
let replace = !append_sparse;
self.config
.submodules
.add_checkout(name.to_string(), new_paths, replace);
.add_checkout(name.to_string(), &new_paths, replace);

if append_sparse {
let existing = updated.sparse_paths.get_or_insert_with(Vec::new);
existing.extend(new_paths);
} else {
updated.sparse_paths = Some(new_paths);
}
}
self.config.submodules.update_entry(name.to_string(), updated);
}
Expand Down
Loading