Skip to content

Commit 6c0d536

Browse files
committed
Cause error when date parsing is failed
1 parent 776a6a8 commit 6c0d536

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

src/date.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ static git_time_t approxidate_str(const char *date,
853853
}
854854
pending_number(&tm, &number);
855855
if (!touched)
856-
*error_ret = 1;
856+
*error_ret = -1;
857857
return update_tm(&tm, &now, 0);
858858
}
859859

@@ -872,7 +872,7 @@ int git__date_parse(git_time_t *out, const char *date)
872872
return -1;
873873

874874
*out = approxidate_str(date, time_sec, &error_ret);
875-
return error_ret;
875+
return error_ret;
876876
}
877877

878878
int git__date_rfc2822_fmt(char *out, size_t len, const git_time *date)

src/revparse.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,10 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s
348348
goto cleanup;
349349
}
350350

351-
if (git__date_parse(&timestamp, curly_braces_content) < 0)
351+
if (git__date_parse(&timestamp, curly_braces_content) < 0) {
352+
error = GIT_EINVALIDSPEC;
352353
goto cleanup;
354+
}
353355

354356
error = retrieve_revobject_from_reflog(out, ref, repo, git_str_cstr(&identifier), (size_t)timestamp);
355357

tests/date/date.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@ void test_date_date__overflow(void)
1313
cl_assert(d2038 < d2039);
1414
#endif
1515
}
16+
17+
void test_date_date__invalid_date(void)
18+
{
19+
git_time_t d;
20+
cl_git_fail(git__date_parse(&d, ""));
21+
cl_git_fail(git__date_parse(&d, "NEITHER_INTEGER_NOR_DATETIME"));
22+
}

tests/refs/revparse.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,19 @@ void test_refs_revparse__date(void)
460460
test_object("with-empty-log@{2 days ago}", NULL);
461461
}
462462

463+
void test_refs_revparse__invalid_date(void)
464+
{
465+
/*
466+
* $ git rev-parse HEAD@{} --
467+
* fatal: bad revision 'HEAD@{}'
468+
*
469+
* $ git rev-parse HEAD@{NEITHER_INTEGER_NOR_DATETIME} --
470+
* fatal: bad revision 'HEAD@{NEITHER_INTEGER_NOR_DATETIME}'
471+
*/
472+
test_object("HEAD@{}", NULL);
473+
test_object("HEAD@{NEITHER_INTEGER_NOR_DATETIME}", NULL);
474+
}
475+
463476
void test_refs_revparse__colon(void)
464477
{
465478
assert_invalid_single_spec(":/");

0 commit comments

Comments
 (0)