Merge pull request #998 from nulltoken/topic/explicit-errors Enhance test coverage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
diff --git a/src/diff.c b/src/diff.c
index 7f500b8..9f693be 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -933,12 +933,14 @@ int git_diff_workdir_to_index(
git_diff_list **diff)
{
git_iterator *a = NULL, *b = NULL;
+ int error;
+
char *prefix = opts ? diff_prefix_from_pathspec(&opts->pathspec) : NULL;
assert(repo && diff);
- if (git_iterator_for_index_range(&a, repo, prefix, prefix) < 0 ||
- git_iterator_for_workdir_range(&b, repo, prefix, prefix) < 0)
+ if ((error = git_iterator_for_index_range(&a, repo, prefix, prefix)) < 0 ||
+ (error = git_iterator_for_workdir_range(&b, repo, prefix, prefix)) < 0)
goto on_error;
git__free(prefix);
@@ -948,7 +950,7 @@ int git_diff_workdir_to_index(
on_error:
git__free(prefix);
git_iterator_free(a);
- return -1;
+ return error;
}
@@ -959,12 +961,14 @@ int git_diff_workdir_to_tree(
git_diff_list **diff)
{
git_iterator *a = NULL, *b = NULL;
+ int error;
+
char *prefix = opts ? diff_prefix_from_pathspec(&opts->pathspec) : NULL;
assert(repo && old_tree && diff);
- if (git_iterator_for_tree_range(&a, repo, old_tree, prefix, prefix) < 0 ||
- git_iterator_for_workdir_range(&b, repo, prefix, prefix) < 0)
+ if ((error = git_iterator_for_tree_range(&a, repo, old_tree, prefix, prefix)) < 0 ||
+ (error = git_iterator_for_workdir_range(&b, repo, prefix, prefix)) < 0)
goto on_error;
git__free(prefix);
@@ -974,7 +978,7 @@ int git_diff_workdir_to_tree(
on_error:
git__free(prefix);
git_iterator_free(a);
- return -1;
+ return error;
}
diff --git a/tests-clar/diff/workdir.c b/tests-clar/diff/workdir.c
index e184c28..3e388ea 100644
--- a/tests-clar/diff/workdir.c
+++ b/tests-clar/diff/workdir.c
@@ -1,5 +1,6 @@
#include "clar_libgit2.h"
#include "diff_helpers.h"
+#include "repository.h"
static git_repository *g_repo = NULL;
@@ -818,3 +819,19 @@ void test_diff_workdir__submodules(void)
git_diff_list_free(diff);
git_tree_free(a);
}
+
+void test_diff_workdir__cannot_diff_against_a_bare_repository(void)
+{
+ git_diff_options opts = {0};
+ git_diff_list *diff = NULL;
+ git_tree *tree;
+
+ g_repo = cl_git_sandbox_init("testrepo.git");
+
+ cl_assert_equal_i(GIT_EBAREREPO, git_diff_workdir_to_index(g_repo, &opts, &diff));
+
+ cl_git_pass(git_repository_head_tree(&tree, g_repo));
+ cl_assert_equal_i(GIT_EBAREREPO, git_diff_workdir_to_tree(g_repo, &opts, tree, &diff));
+
+ git_tree_free(tree);
+}
diff --git a/tests-clar/refs/isvalidname.c b/tests-clar/refs/isvalidname.c
index 8a31f5c..3cc838d 100644
--- a/tests-clar/refs/isvalidname.c
+++ b/tests-clar/refs/isvalidname.c
@@ -21,4 +21,7 @@ void test_refs_isvalidname__wont_hopefully_choke_on_valid_formats(void)
cl_assert_equal_i(true, git_reference_is_valid_name("ONE_LEVEL"));
cl_assert_equal_i(true, git_reference_is_valid_name("refs/stash"));
cl_assert_equal_i(true, git_reference_is_valid_name("refs/remotes/origin/bim_with_3d@11296"));
+ cl_assert_equal_i(true, git_reference_is_valid_name("refs/master{yesterday"));
+ cl_assert_equal_i(true, git_reference_is_valid_name("refs/master}yesterday"));
+ cl_assert_equal_i(true, git_reference_is_valid_name("refs/master{yesterday}"));
}
diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c
index 4f03643..fae43a1 100644
--- a/tests-clar/status/worktree.c
+++ b/tests-clar/status/worktree.c
@@ -419,10 +419,7 @@ void test_status_worktree__cannot_retrieve_the_status_of_a_bare_repository(void)
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
- error = git_status_file(&status, repo, "dummy");
-
- cl_git_fail(error);
- cl_assert(error != GIT_ENOTFOUND);
+ cl_assert_equal_i(GIT_EBAREREPO, git_status_file(&status, repo, "dummy"));
git_repository_free(repo);
}