Commit 0d23c62c480d155b8ba446ca2ec536758a567bcc

nulltoken 2012-06-28T11:09:16

revparse: handle specs with caret and colon

diff --git a/src/revparse.c b/src/revparse.c
index 1b466cd..dd3886e 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -732,6 +732,10 @@ int git_revparse_single(git_object **out, git_repository *repo, const char *spec
 				if (retcode < 0) {
 					next_state = REVPARSE_STATE_DONE;
 				}
+			} else if (*spec_cur == ':') {
+				retcode = handle_caret_syntax(&next_obj, repo, cur_obj, git_buf_cstr(&stepbuffer));
+				git_buf_clear(&stepbuffer);
+				next_state = !retcode ? REVPARSE_STATE_COLON : REVPARSE_STATE_DONE;
 			} else {
 				git_buf_putc(&stepbuffer, *spec_cur);
 			}
diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c
index aaef90b..e2e82cf 100644
--- a/tests-clar/refs/revparse.c
+++ b/tests-clar/refs/revparse.c
@@ -170,6 +170,7 @@ void test_refs_revparse__colon(void)
 	cl_assert_equal_i(GIT_ENOTFOUND, git_revparse_single(&g_obj, g_repo, "subtrees:ab/42.txt"));
 	cl_assert_equal_i(GIT_ENOTFOUND, git_revparse_single(&g_obj, g_repo, "subtrees:ab/4.txt/nope"));
 	cl_assert_equal_i(GIT_ENOTFOUND, git_revparse_single(&g_obj, g_repo, "subtrees:nope"));
+	cl_assert_equal_i(GIT_ENOTFOUND, git_revparse_single(&g_obj, g_repo, "test/master^1:branch_file.txt"));
 
 	/* Trees */
 	test_object("master:", "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
@@ -184,4 +185,5 @@ void test_refs_revparse__colon(void)
 	test_object(":/Merge", "a4a7dce85cf63874e984719f4fdd239f5145052f");
 	test_object(":/one", "c47800c7266a2be04c571c04d5a6614691ea99bd");
 	test_object(":/packed commit t", "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9");
+	test_object("test/master^2:branch_file.txt", "45b983be36b73c0788dc9cbcb76cbb80fc7bb057");
 }