Merge pull request #995 from nulltoken/fix/issue_994 revparse: properly handle refnames containing a @
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
diff --git a/src/revparse.c b/src/revparse.c
index 191f637..83eea7d 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -795,20 +795,24 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec
case '@':
{
- git_object *temp_object = NULL;
+ if (spec[pos+1] == '{') {
+ git_object *temp_object = NULL;
- if ((error = extract_curly_braces_content(&buf, spec, &pos)) < 0)
- goto cleanup;
+ if ((error = extract_curly_braces_content(&buf, spec, &pos)) < 0)
+ goto cleanup;
- if ((error = ensure_base_rev_is_not_known_yet(base_rev, spec)) < 0)
- goto cleanup;
+ if ((error = ensure_base_rev_is_not_known_yet(base_rev, spec)) < 0)
+ goto cleanup;
- if ((error = handle_at_syntax(&temp_object, &reference, spec, identifier_len, repo, git_buf_cstr(&buf))) < 0)
- goto cleanup;
+ if ((error = handle_at_syntax(&temp_object, &reference, spec, identifier_len, repo, git_buf_cstr(&buf))) < 0)
+ goto cleanup;
- if (temp_object != NULL)
- base_rev = temp_object;
- break;
+ if (temp_object != NULL)
+ base_rev = temp_object;
+ break;
+ } else {
+ /* Fall through */
+ }
}
default:
diff --git a/tests-clar/refs/isvalidname.c b/tests-clar/refs/isvalidname.c
index 99761de..8a31f5c 100644
--- a/tests-clar/refs/isvalidname.c
+++ b/tests-clar/refs/isvalidname.c
@@ -20,4 +20,5 @@ void test_refs_isvalidname__wont_hopefully_choke_on_valid_formats(void)
cl_assert_equal_i(true, git_reference_is_valid_name("HEAD"));
cl_assert_equal_i(true, git_reference_is_valid_name("ONE_LEVEL"));
cl_assert_equal_i(true, git_reference_is_valid_name("refs/stash"));
+ cl_assert_equal_i(true, git_reference_is_valid_name("refs/remotes/origin/bim_with_3d@11296"));
}
diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c
index 14bd9fb..a1f0dbf 100644
--- a/tests-clar/refs/revparse.c
+++ b/tests-clar/refs/revparse.c
@@ -451,3 +451,37 @@ void test_refs_revparse__a_too_short_objectid_returns_EAMBIGUOUS(void)
cl_assert_equal_i(GIT_EAMBIGUOUS, result);
}
+
+void test_refs_revparse__issue_994(void)
+{
+ git_repository *repo;
+ git_reference *head, *with_at;
+ git_object *target;
+
+ repo = cl_git_sandbox_init("testrepo.git");
+
+ cl_assert_equal_i(GIT_ENOTFOUND,
+ git_revparse_single(&target, repo, "origin/bim_with_3d@11296"));
+
+ cl_assert_equal_i(GIT_ENOTFOUND,
+ git_revparse_single(&target, repo, "refs/remotes/origin/bim_with_3d@11296"));
+
+
+ cl_git_pass(git_repository_head(&head, repo));
+ cl_git_pass(git_reference_create_oid(
+ &with_at,
+ repo,
+ "refs/remotes/origin/bim_with_3d@11296",
+ git_reference_oid(head),
+ 0));
+
+ cl_git_pass(git_revparse_single(&target, repo, "origin/bim_with_3d@11296"));
+ git_object_free(target);
+
+ cl_git_pass(git_revparse_single(&target, repo, "refs/remotes/origin/bim_with_3d@11296"));
+ git_object_free(target);
+
+ git_reference_free(with_at);
+ git_reference_free(head);
+ cl_git_sandbox_cleanup();
+}