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
3 changes: 3 additions & 0 deletions src/backend/spm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ impl SPMBackend {
debug!("Checking out revision: {revision}");
repo.update_tag(revision.to_string())?;

// Updates submodules ensuring they match the checked-out revision
repo.update_submodules()?;

Copilot AI Dec 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new submodule update functionality lacks test coverage. Consider adding a unit test for the update_submodules method or an integration test that verifies submodules are properly initialized for SPM packages that depend on them (e.g., testing with a package like apple/swift-protobuf >= 1.31.0 which uses submodules).

Copilot uses AI. Check for mistakes.

Ok(repo.dir)
}

Expand Down
26 changes: 26 additions & 0 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,32 @@ impl Git {
Ok(())
}

pub fn update_submodules(&self) -> Result<()> {
debug!("updating submodules in {}", self.dir.display());

let exec = |cmd: Expression| match cmd.stderr_to_stdout().stdout_capture().unchecked().run()
{
Ok(res) => {
if res.status.success() {
Ok(())
} else {
Err(eyre!(
"git failed: {cmd:?} {}",
String::from_utf8(res.stdout).unwrap()

Copilot AI Dec 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unwrap() call on String::from_utf8(res.stdout) could panic if the git output contains invalid UTF-8 sequences. Consider using String::from_utf8_lossy() or handling the error case explicitly to prevent potential panics.

Suggested change
String::from_utf8(res.stdout).unwrap()
String::from_utf8_lossy(&res.stdout)

Copilot uses AI. Check for mistakes.
))
}
}
Err(err) => Err(eyre!("git failed: {cmd:?} {err:#}")),
};
Comment on lines +177 to +190

Copilot AI Dec 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exec closure is duplicated from the update_ref method above (lines 73-86). Consider extracting this into a private helper method to eliminate code duplication and improve maintainability. This pattern appears to be used for executing git commands with consistent error handling.

Copilot uses AI. Check for mistakes.

exec(
git_cmd!(&self.dir, "submodule", "update", "--init", "--recursive")
.env("GIT_TERMINAL_PROMPT", "0"),
)?;

Ok(())
}

pub fn current_branch(&self) -> Result<String> {
let dir = &self.dir;
if let Ok(repo) = self.repo() {
Expand Down
Loading