Skip to content

git_revparse_single ignores content before trailing @ #6735

@ehuss

Description

@ehuss

The git_revparse_single function seems to ignore any content before the @ symbol if it is the last character in the string. It treats this as the bare @ alias for HEAD. I would expect it to fail with a bad revision.

Reproduction steps

#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;
  if (git_revparse_single(&obj, repo, "abcd@") == 0) {
    char oidstr[GIT_OID_SHA1_HEXSIZE+1] = {0};
    git_oid_tostr(oidstr, sizeof(oidstr), git_object_id(obj));
    fprintf(stderr, "oid: %s", oidstr);
  }

  return 0;
}

Expected behavior

git_revparse_single returns an error (same as git rev-parse foo@).

Actual behavior

git_revparse_single returns the object for HEAD.

Version of libgit2 (release number or SHA1)

8535fdb (current 1.8 dev).

Operating system(s) tested

any

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