Skip to content

Commit 60f219e

Browse files
committed
Revparse: Correctly accept ref with '@' at the end
Signed-off-by: Sven Strickroth <[email protected]>
1 parent e5e233c commit 60f219e

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/libgit2/revparse.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -816,13 +816,7 @@ static int revparse(
816816
if (temp_object != NULL)
817817
base_rev = temp_object;
818818
break;
819-
} else if (spec[pos+1] == '\0') {
820-
if (pos) {
821-
git_error_set(GIT_ERROR_REFERENCE, "invalid revspec");
822-
error = GIT_EINVALIDSPEC;
823-
goto cleanup;
824-
}
825-
819+
} else if (spec[pos + 1] == '\0' && !pos) {
826820
spec = "HEAD";
827821
identifier_len = 4;
828822
parsed = true;

tests/libgit2/refs/revparse.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,25 @@ void test_refs_revparse__try_to_retrieve_branch_before_abbrev_sha(void)
747747
cl_git_sandbox_cleanup();
748748
}
749749

750+
void test_refs_revparse__at_at_end_of_refname(void)
751+
{
752+
git_repository *repo;
753+
git_reference *branch;
754+
git_object *target;
755+
756+
repo = cl_git_sandbox_init("testrepo.git");
757+
758+
cl_git_pass(git_revparse_single(&target, repo, "HEAD"));
759+
cl_git_pass(git_branch_create(&branch, repo, "master@", (git_commit *)target, 0));
760+
git_object_free(target);
761+
762+
test_id_inrepo("master@", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVSPEC_SINGLE, repo);
763+
764+
cl_git_fail_with(GIT_ENOTFOUND, git_revparse_single(&target, repo, "foo@"));
765+
766+
git_reference_free(branch);
767+
cl_git_sandbox_cleanup();
768+
}
750769

751770
void test_refs_revparse__range(void)
752771
{
@@ -889,15 +908,3 @@ void test_refs_revparse__parses_at_head(void)
889908
test_id("@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVSPEC_SINGLE);
890909
test_id("@", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVSPEC_SINGLE);
891910
}
892-
893-
void test_refs_revparse__rejects_bogus_at(void)
894-
{
895-
git_repository *repo;
896-
git_object *target;
897-
898-
repo = cl_git_sandbox_init("testrepo.git");
899-
900-
cl_git_fail_with(GIT_EINVALIDSPEC, git_revparse_single(&target, repo, "foo@"));
901-
902-
cl_git_sandbox_cleanup();
903-
}

0 commit comments

Comments
 (0)