Skip to content

Submodule update fails when submodule OID is detached #1164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jkoppel opened this issue May 27, 2025 · 0 comments
Open

Submodule update fails when submodule OID is detached #1164

jkoppel opened this issue May 27, 2025 · 0 comments

Comments

@jkoppel
Copy link

jkoppel commented May 27, 2025

Summary

Tried to clone and submodule-update repo where some submodules point to detached commits; got "object not found" error; could not find any configuration option in git2-rs that would help.

Expected to work with default settings, since it works fine in git command line.

Details

I have a program built using git2-rs, and am trying to run it on the repo https://github.com/Cork-Technology/Depeg-swap .

This repo is interesting in that two of its submodules point to commits which are not in any branch in the target repo, namely Uniswap/v2-core@89b08b5 and Uniswap/v2-periphery@6820d8b .

Submodule::update fails when running on these submodules.

Simplified code:

    info!("Cloning repo");
    let path = Path::new("/some/tmp/path");
    let mut repo = git2::build::RepoBuilder::new();
    repo.clone("https://github.com/Cork-Technology/Depeg-swap", path)?;

    let local_repo = git2::Repository::open(path)?;
    for mut submodule in local_repo.submodules()? {
        info!("Updating submodule: {:?}", submodule.name());
        let mut update_opts = git2::SubmoduleUpdateOptions::new();
        update_opts.allow_fetch(true);
        match submodule.update(true, Some(&mut update_opts)) {
            Ok(_) => (),
            Err(e) => warn!("Failed to update submodule: {:?}", e),
        }
    }

Output (error lines bolded):

T08:15:59.175948Z  INFO myprogram Cloning repo
2025-05-27T08:16:01.035119Z  INFO myprogram: Updating submodule: Some("lib/BokkyPooBahsDateTimeLibrary")
2025-05-27T08:16:01.931884Z  INFO myprogram: Updating submodule: Some("lib/Cork-Hook")
2025-05-27T08:16:02.528602Z  INFO myprogram: Updating submodule: Some("lib/forge-std")
2025-05-27T08:16:03.243375Z  INFO myprogram: Updating submodule: Some("lib/openzeppelin-contracts")
2025-05-27T08:16:19.119010Z  INFO myprogram: Updating submodule: Some("lib/openzeppelin-contracts-upgradeable")
2025-05-27T08:16:31.146724Z  INFO  myprogram: Updating submodule: Some("lib/openzeppelin-foundry-upgrades")
2025-05-27T08:16:31.903167Z  INFO myprogram: Updating submodule: Some("lib/permit2")
2025-05-27T08:16:33.215988Z  INFO myprogram: Updating submodule: Some("lib/prb-math")
2025-05-27T08:16:35.373183Z  INFO myprogram: Updating submodule: Some("lib/v2-core")
**2025-05-27T08:16:36.121215Z  WARN myprogram: Failed to update submodule: Error { code: -3, klass: 9, message: "object not found - no match for id (89b08b5b8deac65f7bea81c5eea2183e31dc5dad)" }**
2025-05-27T08:16:36.121263Z  INFO myprogram: Updating submodule: Some("lib/v2-periphery")
**2025-05-27T08:16:36.954935Z  WARN myprogram: Failed to update submodule: Error { code: -3, klass: 9, message: "object not found - no match for id (6820d8be7e111cbda3358226cc3a13489b6a625e)" }**

I have scoured the docs and source of git2-rs looking for options that could potentially allow this operation to succeed. The only one I found is allow_fetch, which is already on. I tried looking through libgit2 as well, though I did not get very far.

Running git submodule update from the command line works without a hitch, so it seems sensible to hope that this would work with default settings. Interestingly, when cloning the v2-core and v2-periphery repositories directly, I am not able to checkout the respective revisions (89b08b and 6820d8be7e) without first doing a git fetch origin.

Anyway,

Ask

Either

  1. There is a way to make this work with git2-rs that I did not find, or
  2. This is a missing configuration option in git2-rs, or
  3. This is a missing configuration option in libgit2, or
  4. It should just work; this is a bug in either git2-rs or libgit2

Which one is it?

And if it's (1), I would really appreciate some help making this work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant