Skip to content

::describe() fails with depth-cloned + detached head #190

Closed
@lukaslueg

Description

@lukaslueg

I have a build on travis failing because of a weird git2 error that happens while trying to get a description from a local repo; roughly this code

use std::path;
extern crate git2;

    match git2::Repository::open(root) {
        Ok(repo) => {
            let mut desc_opt = git2::DescribeOptions::new();
            desc_opt.describe_tags()
                .show_commit_oid_as_fallback(true);
            Ok(Some(repo.describe(&desc_opt).and_then(|desc| desc.format(None))?))
        }
        Err(ref e) if e.class() == git2::ErrorClass::Repository &&
                      e.code() == git2::ErrorCode::NotFound => Ok(None),
        Err(e) => Err(e),
    }

results in

Error { code: -3, klass: 9, message: "object not found - no match for id (77f95f14776deb7e120a2a26f7b56abf2903bc62)" }'

The id 77f95f1 from the error message refers to a commit that is of no particular interest and actually weeks behind; I never asked for it.

I was finally able to reproduce the problem Travis encounters by very carefully following how Travis clones the repo:

git clone --depth=50 https://... crate_root
cd crate_root
git fetch origin +refs/pull/414/merge:
git checkout -qf FETCH_HEAD
cargo test

If and only if the repo is cloned recursively the call to ::describe() results in this error, always referring to 77f95f1. The repo does not even have submodules.

My local git client does the right thing and get's the latest commit oid without problems.

Any idea what's going on here? The issue may be related to this one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions