Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/libgit2/revparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -816,13 +816,7 @@ static int revparse(
if (temp_object != NULL)
base_rev = temp_object;
break;
} else if (spec[pos+1] == '\0') {
if (pos) {
git_error_set(GIT_ERROR_REFERENCE, "invalid revspec");
error = GIT_EINVALIDSPEC;
goto cleanup;
}

} else if (spec[pos + 1] == '\0' && !pos) {
spec = "HEAD";
identifier_len = 4;
parsed = true;
Expand Down
31 changes: 19 additions & 12 deletions tests/libgit2/refs/revparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,25 @@ void test_refs_revparse__try_to_retrieve_branch_before_abbrev_sha(void)
cl_git_sandbox_cleanup();
}

void test_refs_revparse__at_at_end_of_refname(void)
{
git_repository *repo;
git_reference *branch;
git_object *target;

repo = cl_git_sandbox_init("testrepo.git");

cl_git_pass(git_revparse_single(&target, repo, "HEAD"));
cl_git_pass(git_branch_create(&branch, repo, "master@", (git_commit *)target, 0));
git_object_free(target);

test_id_inrepo("master@", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVSPEC_SINGLE, repo);

cl_git_fail_with(GIT_ENOTFOUND, git_revparse_single(&target, repo, "foo@"));

git_reference_free(branch);
cl_git_sandbox_cleanup();
}

void test_refs_revparse__range(void)
{
Expand Down Expand Up @@ -889,15 +908,3 @@ void test_refs_revparse__parses_at_head(void)
test_id("@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVSPEC_SINGLE);
test_id("@", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVSPEC_SINGLE);
}

void test_refs_revparse__rejects_bogus_at(void)
{
git_repository *repo;
git_object *target;

repo = cl_git_sandbox_init("testrepo.git");

cl_git_fail_with(GIT_EINVALIDSPEC, git_revparse_single(&target, repo, "foo@"));

cl_git_sandbox_cleanup();
}