From c843736d63532b38df9e679850b914f9bb631b27 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Tue, 7 Apr 2015 14:43:04 +0200 Subject: [PATCH 1/2] describe example: enable building by default. --- examples/.gitignore | 1 + examples/Makefile | 1 + 2 files changed, 2 insertions(+) diff --git a/examples/.gitignore b/examples/.gitignore index fb96d7925..0e491598a 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -11,4 +11,5 @@ remote status tag for-each-ref +describe *.dSYM diff --git a/examples/Makefile b/examples/Makefile index 01f8592d9..bd7e92dc9 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -5,6 +5,7 @@ CFLAGS = -g -I../include -I../src -Wall -Wextra -Wmissing-prototypes -Wno-missin LFLAGS = -L../build -lgit2 -lz APPS = general showindex diff rev-list cat-file status log rev-parse init blame tag remote APPS += for-each-ref +APPS += describe all: $(APPS) From 08e1fd651716b2fd13b4e594c057ba30edadd23c Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Tue, 7 Apr 2015 14:44:08 +0200 Subject: [PATCH 2/2] describe: only abort without tags if fallback is not allowed. When no reference names could be found we did error out when trying to describe a commit. This is wrong, though, when the option to fall back to a commit's object ID is set. --- src/describe.c | 2 +- tests/describe/describe.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/describe.c b/src/describe.c index 68bac2d2f..5aea927c1 100644 --- a/src/describe.c +++ b/src/describe.c @@ -693,7 +693,7 @@ int git_describe_commit( get_name, &data)) < 0) goto cleanup; - if (git_oidmap_size(data.names) == 0) { + if (git_oidmap_size(data.names) == 0 && !opts->show_commit_oid_as_fallback) { giterr_set(GITERR_DESCRIBE, "Cannot describe - " "No reference found, cannot describe anything."); error = -1; diff --git a/tests/describe/describe.c b/tests/describe/describe.c index 9a523a169..a8c57d874 100644 --- a/tests/describe/describe.c +++ b/tests/describe/describe.c @@ -28,7 +28,7 @@ static int delete_cb(git_reference *ref, void *payload) return 0; } -void test_describe_describe__cannot_describe_against_a_repo_with_no_ref(void) +void test_describe_describe__describe_a_repo_with_no_refs(void) { git_repository *repo; git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT; @@ -41,8 +41,13 @@ void test_describe_describe__cannot_describe_against_a_repo_with_no_ref(void) cl_git_pass(git_reference_foreach(repo, delete_cb, NULL)); + /* Impossible to describe without falling back to OIDs */ cl_git_fail(git_describe_commit(&result, object, &opts)); + /* Try again with OID fallbacks */ + opts.show_commit_oid_as_fallback = 1; + cl_git_pass(git_describe_commit(&result, object, &opts)); + git_describe_result_free(result); git_object_free(object); git_buf_free(&buf);