8000 revparse: ensure bare '@' is truly bare · libgit2/libgit2@a8e215b · GitHub
[go: up one dir, main page]

Skip to content

Commit a8e215b

Browse files
committed
revparse: ensure bare '@' is truly bare
Support a revspec of '@' to mean 'HEAD', but ensure that it's at the start of the revspec. Previously we were erroneously allowing 'foo@' to mean 'HEAD' as well. Instead, 'foo@' should be rejected.
1 parent c2247bf commit a8e215b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/libgit2/revparse.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,12 @@ static int revparse(
817817
base_rev = temp_object;
818818
break;
819819
} 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+
820826
spec = "HEAD";
821827
identifier_len = 4;
822828
parsed = true;

tests/libgit2/refs/revparse.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,3 +889,16 @@ void test_refs_revparse__parses_at_head(void)
889889
test_id("@{0}", "a65 871B fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVSPEC_SINGLE);
890890
test_id("@", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, GIT_REVSPEC_SINGLE);
891891
}
892+
893+
void test_refs_revparse__rejects_bogus_at(void)
894+
{
895+
git_repository *repo;
896+
git_object *target;
897+
char sha[GIT_OID_SHA1_HEXSIZE + 1];
898+
899+
repo = cl_git_sandbox_init("testrepo.git");
900+
901+
cl_git_fail_with(GIT_EINVALIDSPEC, git_revparse_single(&target, repo, "foo@"));
902+
903+
cl_git_sandbox_cleanup();
904+
}

0 commit comments

Comments
 (0)
0