diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2014-09-30 08:54:52 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2014-09-30 08:56:20 +0200 |
commit | fd8126e4c605e749ed6ab1e31ac32366adc8cc8f (patch) | |
tree | 813de2cce7edc976daac6e3f34198ade5e4cea84 /tests/describe | |
parent | 3b6534b80768e8751b398cd3aeffb888e374c8d4 (diff) | |
download | libgit2-fd8126e4c605e749ed6ab1e31ac32366adc8cc8f.tar.gz |
describe: implement describing the workdir
When we describe the workdir, we perform a describe on HEAD and then
check to see if the worktree is dirty. If it is and we have a suffix
string, we append that to the buffer.
Diffstat (limited to 'tests/describe')
-rw-r--r-- | tests/describe/describe_helpers.c | 26 | ||||
-rw-r--r-- | tests/describe/describe_helpers.h | 8 | ||||
-rw-r--r-- | tests/describe/t6120.c | 14 |
3 files changed, 48 insertions, 0 deletions
diff --git a/tests/describe/describe_helpers.c b/tests/describe/describe_helpers.c index d975ddf4b..230e1bd15 100644 --- a/tests/describe/describe_helpers.c +++ b/tests/describe/describe_helpers.c @@ -26,3 +26,29 @@ void assert_describe( git_object_free(object); git_buf_free(&label); } + +void assert_describe_workdir( + const char *expected_output, + const char *expected_suffix, + git_repository *repo, + git_describe_opts *opts, + git_describe_format_options *fmt_opts, + bool is_prefix_match) +{ + git_buf label = GIT_BUF_INIT; + git_describe_result *result; + + cl_git_pass(git_describe_workdir(&result, repo, opts)); + cl_git_pass(git_describe_format(&label, result, fmt_opts)); + + if (is_prefix_match) + cl_assert_equal_i(0, git__prefixcmp(git_buf_cstr(&label), expected_output)); + else + cl_assert_equal_s(expected_output, label); + + if (expected_suffix) + cl_assert_equal_i(0, git__suffixcmp(git_buf_cstr(&label), expected_suffix)); + + git_describe_result_free(result); + git_buf_free(&label); +} diff --git a/tests/describe/describe_helpers.h b/tests/describe/describe_helpers.h index a666b46cf..6f793582c 100644 --- a/tests/describe/describe_helpers.h +++ b/tests/describe/describe_helpers.h @@ -8,3 +8,11 @@ extern void assert_describe( git_describe_opts *opts, git_describe_format_options *fmt_opts, bool is_prefix_match); + +extern void assert_describe_workdir( + const char *expected_output, + const char *expected_suffix, + git_repository *repo, + git_describe_opts *opts, + git_describe_format_options *fmt_opts, + bool is_prefix_match); diff --git a/tests/describe/t6120.c b/tests/describe/t6120.c index 39489f3c5..2ac59a6bc 100644 --- a/tests/describe/t6120.c +++ b/tests/describe/t6120.c @@ -77,6 +77,20 @@ void test_describe_t6120__firstparent(void) assert_describe("e-3-", "HEAD", repo, &opts, &fmt_opts, true); } +void test_describe_t6120__workdir(void) +{ + git_describe_opts opts = GIT_DESCRIBE_OPTIONS_INIT; + git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT; + + assert_describe_workdir("A-", NULL, repo, &opts, &fmt_opts, true); + cl_git_mkfile("describe/file", "something different"); + + fmt_opts.dirty_suffix = "-dirty"; + assert_describe_workdir("A-", "-dirty", repo, &opts, &fmt_opts, true); + fmt_opts.dirty_suffix = ".mod"; + assert_describe_workdir("A-", ".mod", repo, &opts, &fmt_opts, true); +} + static void commit_and_tag( git_time_t *time, const char *commit_msg, |