Skip to content

Commit 9529113

Browse files
committed
Workaround repo.submodules() to deal with unborn repositories.
This fix will come from `gitoxide`, but until that's released we handle it here. Doing so is fine becuase of the following. The order in which submodule files are tried is this: - worktree - index - HEAD:.gitmodules If the `HEAD^{commit}` can't be read, this means there is definitely no gitmodules file there. And since it's the last stage, there is nothing we'd fail to discover.
1 parent 46ad7af commit 9529113

File tree

1 file changed

+10
-1
lines changed
  • src/cargo/ops/cargo_package

1 file changed

+10
-1
lines changed

src/cargo/ops/cargo_package/vcs.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,16 @@ fn status_submodules(
335335
dirty_files: &mut Vec<PathBuf>,
336336
dirty_files_outside_of_package_root: &mut Vec<PathBuf>,
337337
) -> CargoResult<()> {
338-
let Some(submodules) = repo.submodules()? else {
338+
let Some(submodules) = repo.submodules().or_else(|err| {
339+
// TODO(@Byron): remove this `or_else()` once `submodules()` fixed in `gitoxide`,
340+
// and the release is available.
341+
if matches!(err, gix::submodule::modules::Error::FindHeadCommit(_)) {
342+
Ok(None)
343+
} else {
344+
Err(err)
345+
}
346+
})?
347+
else {
339348
return Ok(());
340349
};
341350
for submodule in submodules {

0 commit comments

Comments
 (0)