Commit 6c0d5366 by Yoichi Nakayama

Cause error when date parsing is failed

parent 776a6a8e
......@@ -853,7 +853,7 @@ static git_time_t approxidate_str(const char *date,
}
pending_number(&tm, &number);
if (!touched)
*error_ret = 1;
*error_ret = -1;
return update_tm(&tm, &now, 0);
}
......
......@@ -348,8 +348,10 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s
goto cleanup;
}
if (git__date_parse(&timestamp, curly_braces_content) < 0)
if (git__date_parse(&timestamp, curly_braces_content) < 0) {
error = GIT_EINVALIDSPEC;
goto cleanup;
}
error = retrieve_revobject_from_reflog(out, ref, repo, git_str_cstr(&identifier), (size_t)timestamp);
......
......@@ -13,3 +13,10 @@ void test_date_date__overflow(void)
cl_assert(d2038 < d2039);
#endif
}
void test_date_date__invalid_date(void)
{
git_time_t d;
cl_git_fail(git__date_parse(&d, ""));
cl_git_fail(git__date_parse(&d, "NEITHER_INTEGER_NOR_DATETIME"));
}
......@@ -460,6 +460,19 @@ void test_refs_revparse__date(void)
test_object("with-empty-log@{2 days ago}", NULL);
}
void test_refs_revparse__invalid_date(void)
{
/*
* $ git rev-parse HEAD@{} --
* fatal: bad revision 'HEAD@{}'
*
* $ git rev-parse HEAD@{NEITHER_INTEGER_NOR_DATETIME} --
* fatal: bad revision 'HEAD@{NEITHER_INTEGER_NOR_DATETIME}'
*/
test_object("HEAD@{}", NULL);
test_object("HEAD@{NEITHER_INTEGER_NOR_DATETIME}", NULL);
}
void test_refs_revparse__colon(void)
{
assert_invalid_single_spec(":/");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment