Skip to content

git_object_short_id fails with core.abbrev string values #6878

@ehuss

Description

@ehuss

Reproduction steps

  1. Set up a global config setting core.abbrev to a string value: git config --global core.abbrev no
  2. Run a program that uses git_object_short_id.
#include <assert.h>
#include <git2/repository.h>
#include <git2/errors.h>
#include <git2/revparse.h>
#include <git2/oid.h>
#include <git2/global.h>
#include <stdio.h>
#include <unistd.h>

int main() {
  git_repository *repo;
  assert(git_libgit2_init() == 1);
  assert(git_repository_open(&repo, "..") == 0);

  git_object *obj;
  assert(git_revparse_single(&obj, repo, "HEAD") == 0);
  git_buf buf = {0};
  int rc;
  rc = git_object_short_id(&buf, obj);
  if (rc == 0) {
    fprintf(stderr, "short: %s", buf.ptr);
  } else {
    git_error const *err;
    err = git_error_last();
    fprintf(stderr, "error: class=%i: %s", err->klass, err->message);
  }

  return 0;
}

Note that the config value can take the values:

Expected behavior

Should be able to handle string values.

Actual behavior

Fails with:

error: class=7: failed to map 'no'

Version of libgit2 (release number or SHA1)

403a03b

Operating system(s) tested

any

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions