summaryrefslogtreecommitdiff
path: root/tests/libgit2
diff options
context:
space:
mode:
Diffstat (limited to 'tests/libgit2')
-rw-r--r--tests/libgit2/apply/apply_helpers.h1
-rw-r--r--tests/libgit2/apply/both.c52
-rw-r--r--tests/libgit2/apply/callbacks.c6
-rw-r--r--tests/libgit2/apply/check.c6
-rw-r--r--tests/libgit2/apply/index.c16
-rw-r--r--tests/libgit2/apply/tree.c2
-rw-r--r--tests/libgit2/apply/workdir.c20
-rw-r--r--tests/libgit2/checkout/index.c3
-rw-r--r--tests/libgit2/clone/nonetwork.c3
-rw-r--r--tests/libgit2/config/find.c11
-rw-r--r--tests/libgit2/core/opts.c29
-rw-r--r--tests/libgit2/diff/diff_helpers.c17
-rw-r--r--tests/libgit2/diff/diff_helpers.h4
-rw-r--r--tests/libgit2/diff/index.c3
-rw-r--r--tests/libgit2/diff/parse.c40
-rw-r--r--tests/libgit2/diff/patchid.c3
-rw-r--r--tests/libgit2/diff/stats.c3
-rw-r--r--tests/libgit2/graph/commitgraph.c17
-rw-r--r--tests/libgit2/index/cache.c10
-rw-r--r--tests/libgit2/index/inmemory.c5
-rw-r--r--tests/libgit2/index/racy.c4
-rw-r--r--tests/libgit2/index/read_index.c12
-rw-r--r--tests/libgit2/index/tests.c30
-rw-r--r--tests/libgit2/index/tests256.c1169
-rw-r--r--tests/libgit2/object/tree/update.c13
-rw-r--r--tests/libgit2/online/clone.c13
-rw-r--r--tests/libgit2/pack/midx.c7
-rw-r--r--tests/libgit2/repo/discover.c3
-rw-r--r--tests/libgit2/repo/env.c92
-rw-r--r--tests/libgit2/repo/setters.c3
-rw-r--r--tests/libgit2/reset/hard.c3
-rw-r--r--tests/libgit2/status/worktree_init.c13
-rw-r--r--tests/libgit2/stream/registration.c6
-rw-r--r--tests/libgit2/submodule/lookup.c3
34 files changed, 1488 insertions, 134 deletions
diff --git a/tests/libgit2/apply/apply_helpers.h b/tests/libgit2/apply/apply_helpers.h
index 82094773e..b1a1479de 100644
--- a/tests/libgit2/apply/apply_helpers.h
+++ b/tests/libgit2/apply/apply_helpers.h
@@ -1,4 +1,5 @@
#include "../merge/merge_helpers.h"
+#include "../diff/diff_helpers.h"
#define TEST_REPO_PATH "merge-recursive"
diff --git a/tests/libgit2/apply/both.c b/tests/libgit2/apply/both.c
index 1331e7ea4..44c5b1937 100644
--- a/tests/libgit2/apply/both.c
+++ b/tests/libgit2/apply/both.c
@@ -78,7 +78,7 @@ void test_apply_both__parsed_diff(void)
size_t both_expected_cnt = sizeof(both_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff,
+ cl_git_pass(diff_from_buffer(&diff,
DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -102,7 +102,7 @@ void test_apply_both__removes_file(void)
size_t both_expected_cnt = sizeof(both_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_DELETE_FILE,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_DELETE_FILE,
strlen(DIFF_DELETE_FILE)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -128,7 +128,7 @@ void test_apply_both__adds_file(void)
size_t both_expected_cnt = sizeof(both_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff,
+ cl_git_pass(diff_from_buffer(&diff,
DIFF_ADD_FILE, strlen(DIFF_ADD_FILE)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -161,7 +161,7 @@ void test_apply_both__application_failure_leaves_index_unmodified(void)
cl_git_pass(git_index_write(index));
git_index_free(index);
- cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
+ cl_git_pass(diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
validate_apply_index(repo, index_expected, index_expected_cnt);
@@ -198,7 +198,7 @@ void test_apply_both__index_must_match_workdir(void)
cl_git_pass(git_index_write(index));
git_index_free(index);
- cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
+ cl_git_pass(diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
git_diff_free(diff);
@@ -214,7 +214,7 @@ void test_apply_both__index_mode_must_match_workdir(void)
/* Set a file in the working directory executable. */
cl_must_pass(p_chmod("merge-recursive/asparagus.txt", 0755));
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_MODIFY_TWO_FILES,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_MODIFY_TWO_FILES,
strlen(DIFF_MODIFY_TWO_FILES)));
cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -248,7 +248,7 @@ void test_apply_both__application_failure_leaves_workdir_unmodified(void)
cl_git_pass(git_index_write(index));
git_index_free(index);
- cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
+ cl_git_pass(diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
@@ -301,7 +301,7 @@ void test_apply_both__keeps_nonconflicting_changes(void)
cl_git_rmfile("merge-recursive/oyster.txt");
cl_git_rewritefile("merge-recursive/gravy.txt", "Hello, world.\n");
- cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
+ cl_git_pass(diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
validate_apply_index(repo, index_expected, index_expected_cnt);
@@ -341,7 +341,7 @@ void test_apply_both__can_apply_nonconflicting_file_changes(void)
cl_git_pass(git_index_write(index));
git_index_free(index);
- cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
+ cl_git_pass(diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
validate_apply_index(repo, both_expected, both_expected_cnt);
@@ -391,7 +391,7 @@ void test_apply_both__honors_crlf_attributes(void)
cl_git_pass(git_reset(repo, (git_object *)commit, GIT_RESET_HARD, NULL));
git_commit_free(commit);
- cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
+ cl_git_pass(diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
validate_apply_index(repo, index_expected, index_expected_cnt);
@@ -415,7 +415,7 @@ void test_apply_both__rename(void)
size_t both_expected_cnt = sizeof(both_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_FILE,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_RENAME_FILE,
strlen(DIFF_RENAME_FILE)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -440,7 +440,7 @@ void test_apply_both__rename_and_modify(void)
size_t both_expected_cnt = sizeof(both_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_AND_MODIFY_FILE,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_RENAME_AND_MODIFY_FILE,
strlen(DIFF_RENAME_AND_MODIFY_FILE)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -465,7 +465,7 @@ void test_apply_both__rename_a_to_b_to_c(void)
size_t both_expected_cnt = sizeof(both_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_A_TO_B_TO_C,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_RENAME_A_TO_B_TO_C,
strlen(DIFF_RENAME_A_TO_B_TO_C)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -490,7 +490,7 @@ void test_apply_both__rename_a_to_b_to_c_exact(void)
size_t both_expected_cnt = sizeof(both_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_A_TO_B_TO_C_EXACT,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_RENAME_A_TO_B_TO_C_EXACT,
strlen(DIFF_RENAME_A_TO_B_TO_C_EXACT)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -515,7 +515,7 @@ void test_apply_both__rename_circular(void)
size_t both_expected_cnt = sizeof(both_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_CIRCULAR,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_RENAME_CIRCULAR,
strlen(DIFF_RENAME_CIRCULAR)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -539,7 +539,7 @@ void test_apply_both__rename_2_to_1(void)
size_t both_expected_cnt = sizeof(both_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_2_TO_1,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_RENAME_2_TO_1,
strlen(DIFF_RENAME_2_TO_1)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -565,7 +565,7 @@ void test_apply_both__rename_1_to_2(void)
size_t both_expected_cnt = sizeof(both_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_1_TO_2,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_RENAME_1_TO_2,
strlen(DIFF_RENAME_1_TO_2)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -590,7 +590,7 @@ void test_apply_both__two_deltas_one_file(void)
size_t both_expected_cnt = sizeof(both_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_TWO_DELTAS_ONE_FILE,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_TWO_DELTAS_ONE_FILE,
strlen(DIFF_TWO_DELTAS_ONE_FILE)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -616,7 +616,7 @@ void test_apply_both__two_deltas_one_new_file(void)
size_t both_expected_cnt = sizeof(both_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_TWO_DELTAS_ONE_NEW_FILE,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_TWO_DELTAS_ONE_NEW_FILE,
strlen(DIFF_TWO_DELTAS_ONE_NEW_FILE)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -641,7 +641,7 @@ void test_apply_both__rename_and_modify_deltas(void)
size_t both_expected_cnt = sizeof(both_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_AND_MODIFY_DELTAS,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_RENAME_AND_MODIFY_DELTAS,
strlen(DIFF_RENAME_AND_MODIFY_DELTAS)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -667,7 +667,7 @@ void test_apply_both__rename_delta_after_modify_delta(void)
size_t both_expected_cnt = sizeof(both_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_AFTER_MODIFY,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_RENAME_AFTER_MODIFY,
strlen(DIFF_RENAME_AFTER_MODIFY)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -681,7 +681,7 @@ void test_apply_both__cant_rename_after_modify_nonexistent_target_path(void)
{
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_AFTER_MODIFY_TARGET_PATH,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_RENAME_AFTER_MODIFY_TARGET_PATH,
strlen(DIFF_RENAME_AFTER_MODIFY_TARGET_PATH)));
cl_git_fail(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -692,7 +692,7 @@ void test_apply_both__cant_modify_source_path_after_rename(void)
{
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_RENAME_AND_MODIFY_SOURCE_PATH,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_RENAME_AND_MODIFY_SOURCE_PATH,
strlen(DIFF_RENAME_AND_MODIFY_SOURCE_PATH)));
cl_git_fail(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -714,7 +714,7 @@ void test_apply_both__readd_deleted_file(void)
size_t both_expected_cnt = sizeof(both_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_DELETE_AND_READD_FILE,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_DELETE_AND_READD_FILE,
strlen(DIFF_DELETE_AND_READD_FILE)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -728,7 +728,7 @@ void test_apply_both__cant_remove_file_twice(void)
{
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_REMOVE_FILE_TWICE,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_REMOVE_FILE_TWICE,
strlen(DIFF_REMOVE_FILE_TWICE)));
cl_git_fail(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
@@ -739,7 +739,7 @@ void test_apply_both__cant_add_invalid_filename(void)
{
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_ADD_INVALID_FILENAME,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_ADD_INVALID_FILENAME,
strlen(DIFF_ADD_INVALID_FILENAME)));
cl_git_fail(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
diff --git a/tests/libgit2/apply/callbacks.c b/tests/libgit2/apply/callbacks.c
index 2f9af3101..f076ca486 100644
--- a/tests/libgit2/apply/callbacks.c
+++ b/tests/libgit2/apply/callbacks.c
@@ -40,7 +40,7 @@ void test_apply_callbacks__delta_aborts(void)
opts.delta_cb = delta_abort_cb;
- cl_git_pass(git_diff_from_buffer(&diff,
+ cl_git_pass(diff_from_buffer(&diff,
DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES)));
cl_git_fail_with(-99,
git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, &opts));
@@ -79,7 +79,7 @@ void test_apply_callbacks__delta_can_skip(void)
opts.delta_cb = delta_skip_cb;
- cl_git_pass(git_diff_from_buffer(&diff,
+ cl_git_pass(diff_from_buffer(&diff,
DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, &opts));
@@ -117,7 +117,7 @@ void test_apply_callbacks__hunk_can_skip(void)
opts.hunk_cb = hunk_skip_odds_cb;
opts.payload = &count;
- cl_git_pass(git_diff_from_buffer(&diff,
+ cl_git_pass(diff_from_buffer(&diff,
DIFF_MANY_CHANGES_ONE, strlen(DIFF_MANY_CHANGES_ONE)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, &opts));
diff --git a/tests/libgit2/apply/check.c b/tests/libgit2/apply/check.c
index d055d455b..0c1f86dc5 100644
--- a/tests/libgit2/apply/check.c
+++ b/tests/libgit2/apply/check.c
@@ -60,7 +60,7 @@ void test_apply_check__parsed_diff(void)
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
opts.flags |= GIT_APPLY_CHECK;
- cl_git_pass(git_diff_from_buffer(&diff,
+ cl_git_pass(diff_from_buffer(&diff,
DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, &opts));
@@ -76,7 +76,7 @@ void test_apply_check__binary(void)
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
opts.flags |= GIT_APPLY_CHECK;
- cl_git_pass(git_diff_from_buffer(&diff,
+ cl_git_pass(diff_from_buffer(&diff,
DIFF_MODIFY_TWO_FILES_BINARY,
strlen(DIFF_MODIFY_TWO_FILES_BINARY)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, &opts));
@@ -112,7 +112,7 @@ void test_apply_check__does_not_apply(void)
git_index_free(index);
opts.flags |= GIT_APPLY_CHECK;
- cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
+ cl_git_pass(diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, &opts));
validate_apply_index(repo, index_expected, index_expected_cnt);
diff --git a/tests/libgit2/apply/index.c b/tests/libgit2/apply/index.c
index 2dc0d53cb..564d55c8c 100644
--- a/tests/libgit2/apply/index.c
+++ b/tests/libgit2/apply/index.c
@@ -78,7 +78,7 @@ void test_apply_index__parsed_diff(void)
size_t index_expected_cnt = sizeof(index_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff,
+ cl_git_pass(diff_from_buffer(&diff,
DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
@@ -102,7 +102,7 @@ void test_apply_index__removes_file(void)
size_t index_expected_cnt = sizeof(index_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_DELETE_FILE,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_DELETE_FILE,
strlen(DIFF_DELETE_FILE)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
@@ -128,7 +128,7 @@ void test_apply_index__adds_file(void)
size_t index_expected_cnt = sizeof(index_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff,
+ cl_git_pass(diff_from_buffer(&diff,
DIFF_ADD_FILE, strlen(DIFF_ADD_FILE)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
@@ -169,7 +169,7 @@ void test_apply_index__modified_workdir_with_unmodified_index_is_ok(void)
cl_git_rmfile("merge-recursive/asparagus.txt");
cl_git_rewritefile("merge-recursive/veal.txt", "Hello, world.\n");
- cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
+ cl_git_pass(diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
validate_apply_index(repo, index_expected, index_expected_cnt);
@@ -201,7 +201,7 @@ void test_apply_index__application_failure_leaves_index_unmodified(void)
cl_git_pass(git_index_write(index));
git_index_free(index);
- cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
+ cl_git_pass(diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
validate_apply_index(repo, index_expected, index_expected_cnt);
@@ -240,7 +240,7 @@ void test_apply_index__keeps_nonconflicting_changes(void)
cl_git_pass(git_index_write(index));
git_index_free(index);
- cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
+ cl_git_pass(diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
validate_apply_index(repo, index_expected, index_expected_cnt);
@@ -285,7 +285,7 @@ void test_apply_index__can_apply_nonconflicting_file_changes(void)
cl_git_pass(git_index_write(index));
git_index_free(index);
- cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
+ cl_git_pass(diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
validate_apply_index(repo, index_expected, index_expected_cnt);
@@ -311,7 +311,7 @@ void test_apply_index__change_mode(void)
size_t index_expected_cnt = sizeof(index_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
+ cl_git_pass(diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
validate_apply_index(repo, index_expected, index_expected_cnt);
diff --git a/tests/libgit2/apply/tree.c b/tests/libgit2/apply/tree.c
index 667bb9d40..b97fe8d35 100644
--- a/tests/libgit2/apply/tree.c
+++ b/tests/libgit2/apply/tree.c
@@ -81,7 +81,7 @@ void test_apply_tree__adds_file(void)
cl_git_pass(git_commit_tree(&a_tree, a_commit));
- cl_git_pass(git_diff_from_buffer(&diff,
+ cl_git_pass(diff_from_buffer(&diff,
DIFF_ADD_FILE, strlen(DIFF_ADD_FILE)));
cl_git_pass(git_apply_to_tree(&index, repo, a_tree, diff, NULL));
diff --git a/tests/libgit2/apply/workdir.c b/tests/libgit2/apply/workdir.c
index e1011d114..5ae56847a 100644
--- a/tests/libgit2/apply/workdir.c
+++ b/tests/libgit2/apply/workdir.c
@@ -77,7 +77,7 @@ void test_apply_workdir__parsed_diff(void)
size_t workdir_expected_cnt = sizeof(workdir_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff,
+ cl_git_pass(diff_from_buffer(&diff,
DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
@@ -101,7 +101,7 @@ void test_apply_workdir__removes_file(void)
size_t workdir_expected_cnt = sizeof(workdir_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff, DIFF_DELETE_FILE,
+ cl_git_pass(diff_from_buffer(&diff, DIFF_DELETE_FILE,
strlen(DIFF_DELETE_FILE)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
@@ -127,7 +127,7 @@ void test_apply_workdir__adds_file(void)
size_t workdir_expected_cnt = sizeof(workdir_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff,
+ cl_git_pass(diff_from_buffer(&diff,
DIFF_ADD_FILE, strlen(DIFF_ADD_FILE)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
@@ -177,7 +177,7 @@ void test_apply_workdir__modified_index_with_unmodified_workdir_is_ok(void)
cl_git_pass(git_index_remove(index, "asparagus.txt", 0));
cl_git_pass(git_index_write(index));
- cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
+ cl_git_pass(diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
validate_apply_index(repo, index_expected, index_expected_cnt);
@@ -208,7 +208,7 @@ void test_apply_workdir__application_failure_leaves_workdir_unmodified(void)
cl_git_rewritefile("merge-recursive/veal.txt",
"This is a modification.\n");
- cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
+ cl_git_pass(diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
@@ -233,7 +233,7 @@ void test_apply_workdir__keeps_nonconflicting_changes(void)
cl_git_rmfile("merge-recursive/oyster.txt");
cl_git_rewritefile("merge-recursive/gravy.txt", "Hello, world.\n");
- cl_git_pass(git_diff_from_buffer(&diff,
+ cl_git_pass(diff_from_buffer(&diff,
DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
@@ -268,7 +268,7 @@ void test_apply_workdir__can_apply_nonconflicting_file_changes(void)
cl_git_append2file("merge-recursive/asparagus.txt",
"This line is added in the workdir.\n");
- cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
+ cl_git_pass(diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
validate_index_unchanged(repo);
@@ -295,7 +295,7 @@ void test_apply_workdir__change_mode(void)
size_t workdir_expected_cnt = sizeof(workdir_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
+ cl_git_pass(diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
validate_index_unchanged(repo);
@@ -321,7 +321,7 @@ void test_apply_workdir__apply_many_changes_one(void)
size_t workdir_expected_cnt = sizeof(workdir_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff,
+ cl_git_pass(diff_from_buffer(&diff,
DIFF_MANY_CHANGES_ONE, strlen(DIFF_MANY_CHANGES_ONE)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, &opts));
@@ -347,7 +347,7 @@ void test_apply_workdir__apply_many_changes_two(void)
size_t workdir_expected_cnt = sizeof(workdir_expected) /
sizeof(struct merge_index_entry);
- cl_git_pass(git_diff_from_buffer(&diff,
+ cl_git_pass(diff_from_buffer(&diff,
DIFF_MANY_CHANGES_TWO, strlen(DIFF_MANY_CHANGES_TWO)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, &opts));
diff --git a/tests/libgit2/checkout/index.c b/tests/libgit2/checkout/index.c
index 6432cba84..3dfdaa630 100644
--- a/tests/libgit2/checkout/index.c
+++ b/tests/libgit2/checkout/index.c
@@ -4,6 +4,7 @@
#include "git2/checkout.h"
#include "futils.h"
#include "repository.h"
+#include "index.h"
#include "remote.h"
#include "repo/repo_helpers.h"
@@ -834,7 +835,7 @@ void test_checkout_index__adding_conflict_removes_stage_0(void)
git_index *new_index, *index;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
- cl_git_pass(git_index_new(&new_index));
+ cl_git_pass(git_index__new(&new_index, GIT_OID_SHA1));
add_conflict(new_index, "new.txt");
cl_git_pass(git_checkout_index(g_repo, new_index, &opts));
diff --git a/tests/libgit2/clone/nonetwork.c b/tests/libgit2/clone/nonetwork.c
index eab633635..5316003f8 100644
--- a/tests/libgit2/clone/nonetwork.c
+++ b/tests/libgit2/clone/nonetwork.c
@@ -5,6 +5,7 @@
#include "remote.h"
#include "futils.h"
#include "repository.h"
+#include "index.h"
#define LIVE_REPO_URL "git://github.com/libgit2/TestGitRepository"
@@ -271,7 +272,7 @@ void test_clone_nonetwork__clone_tag_to_tree(void)
stage = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_repository_odb(&odb, stage));
- cl_git_pass(git_index_new(&index));
+ cl_git_pass(git_index__new(&index, GIT_OID_SHA1));
memset(&entry, 0, sizeof(git_index_entry));
entry.path = file_path;
diff --git a/tests/libgit2/config/find.c b/tests/libgit2/config/find.c
new file mode 100644
index 000000000..7ca8ec767
--- /dev/null
+++ b/tests/libgit2/config/find.c
@@ -0,0 +1,11 @@
+#include "clar_libgit2.h"
+
+void test_config_find__one(void)
+{
+ git_buf buf = GIT_BUF_INIT;
+
+ cl_git_fail_with(GIT_ENOTFOUND, git_config_find_global(&buf));
+ cl_git_fail_with(GIT_ENOTFOUND, git_config_find_xdg(&buf));
+ cl_git_fail_with(GIT_ENOTFOUND, git_config_find_system(&buf));
+ cl_git_fail_with(GIT_ENOTFOUND, git_config_find_programdata(&buf));
+}
diff --git a/tests/libgit2/core/opts.c b/tests/libgit2/core/opts.c
index 486ff58c6..1aa095adf 100644
--- a/tests/libgit2/core/opts.c
+++ b/tests/libgit2/core/opts.c
@@ -50,9 +50,9 @@ void test_core_opts__extensions_add(void)
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, &out));
cl_assert_equal_sz(out.count, 3);
- cl_assert_equal_s("noop", out.strings[0]);
- cl_assert_equal_s("objectformat", out.strings[1]);
- cl_assert_equal_s("foo", out.strings[2]);
+ cl_assert_equal_s("foo", out.strings[0]);
+ cl_assert_equal_s("noop", out.strings[1]);
+ cl_assert_equal_s("objectformat", out.strings[2]);
git_strarray_dispose(&out);
}
@@ -66,9 +66,26 @@ void test_core_opts__extensions_remove(void)
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, &out));
cl_assert_equal_sz(out.count, 3);
- cl_assert_equal_s("objectformat", out.strings[0]);
- cl_assert_equal_s("bar", out.strings[1]);
- cl_assert_equal_s("baz", out.strings[2]);
+ cl_assert_equal_s("bar", out.strings[0]);
+ cl_assert_equal_s("baz", out.strings[1]);
+ cl_assert_equal_s("objectformat", out.strings[2]);
+
+ git_strarray_dispose(&out);
+}
+
+void test_core_opts__extensions_uniq(void)
+{
+ const char *in[] = { "foo", "noop", "bar", "bar", "foo", "objectformat" };
+ git_strarray out = { 0 };
+
+ cl_git_pass(git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, in, ARRAY_SIZE(in)));
+ cl_git_pass(git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, &out));
+
+ cl_assert_equal_sz(out.count, 4);
+ cl_assert_equal_s("bar", out.strings[0]);
+ cl_assert_equal_s("foo", out.strings[1]);
+ cl_assert_equal_s("noop", out.strings[2]);
+ cl_assert_equal_s("objectformat", out.strings[3]);
git_strarray_dispose(&out);
}
diff --git a/tests/libgit2/diff/diff_helpers.c b/tests/libgit2/diff/diff_helpers.c
index 341b0a448..5daebffeb 100644
--- a/tests/libgit2/diff/diff_helpers.c
+++ b/tests/libgit2/diff/diff_helpers.c
@@ -314,3 +314,20 @@ void diff_assert_equal(git_diff *a, git_diff *b)
}
}
+#ifdef GIT_EXPERIMENTAL_SHA256
+int diff_from_buffer(
+ git_diff **out,
+ const char *content,
+ size_t content_len)
+{
+ return git_diff_from_buffer(out, content, content_len, NULL);
+}
+#else
+int diff_from_buffer(
+ git_diff **out,
+ const char *content,
+ size_t content_len)
+{
+ return git_diff_from_buffer(out, content, content_len);
+}
+#endif
diff --git a/tests/libgit2/diff/diff_helpers.h b/tests/libgit2/diff/diff_helpers.h
index af855ce68..1be4b4780 100644
--- a/tests/libgit2/diff/diff_helpers.h
+++ b/tests/libgit2/diff/diff_helpers.h
@@ -71,3 +71,7 @@ extern void diff_print_raw(FILE *fp, git_diff *diff);
extern void diff_assert_equal(git_diff *a, git_diff *b);
+extern int diff_from_buffer(
+ git_diff **out,
+ const char *content,
+ size_t content_len);
diff --git a/tests/libgit2/diff/index.c b/tests/libgit2/diff/index.c
index 5773b748e..b7866750b 100644
--- a/tests/libgit2/diff/index.c
+++ b/tests/libgit2/diff/index.c
@@ -1,5 +1,6 @@
#include "clar_libgit2.h"
#include "diff_helpers.h"
+#include "index.h"
static git_repository *g_repo = NULL;
@@ -278,7 +279,7 @@ void test_diff_index__to_index(void)
git_diff *diff;
diff_expects exp;
- cl_git_pass(git_index_new(&old_index));
+ cl_git_pass(git_index__new(&old_index, GIT_OID_SHA1));
old_tree = resolve_commit_oid_to_tree(g_repo, a_commit);
cl_git_pass(git_index_read_tree(old_index, old_tree));
diff --git a/tests/libgit2/diff/parse.c b/tests/libgit2/diff/parse.c
index cae843cc8..79745b995 100644
--- a/tests/libgit2/diff/parse.c
+++ b/tests/libgit2/diff/parse.c
@@ -19,19 +19,19 @@ void test_diff_parse__nonpatches_fail_with_notfound(void)
const char *not_with_both = "Lead.\n" PATCH_NOT_A_PATCH "Trail.\n";
cl_git_fail_with(GIT_ENOTFOUND,
- git_diff_from_buffer(&diff,
+ diff_from_buffer(&diff,
not,
strlen(not)));
cl_git_fail_with(GIT_ENOTFOUND,
- git_diff_from_buffer(&diff,
+ diff_from_buffer(&diff,
not_with_leading,
strlen(not_with_leading)));
cl_git_fail_with(GIT_ENOTFOUND,
- git_diff_from_buffer(&diff,
+ diff_from_buffer(&diff,
not_with_trailing,
strlen(not_with_trailing)));
cl_git_fail_with(GIT_ENOTFOUND,
- git_diff_from_buffer(&diff,
+ diff_from_buffer(&diff,
not_with_both,
strlen(not_with_both)));
}
@@ -51,7 +51,7 @@ static void test_parse_invalid_diff(const char *invalid_diff)
git_str_puts(&buf, PATCH_BINARY_LITERAL);
cl_git_fail_with(GIT_ERROR,
- git_diff_from_buffer(&diff, buf.ptr, buf.size));
+ diff_from_buffer(&diff, buf.ptr, buf.size));
git_str_dispose(&buf);
}
@@ -72,7 +72,7 @@ void test_diff_parse__exact_rename(void)
"2.9.3\n";
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(
+ cl_git_pass(diff_from_buffer(
&diff, content, strlen(content)));
git_diff_free(diff);
}
@@ -92,7 +92,7 @@ void test_diff_parse__empty_file(void)
"2.20.1\n";
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(
+ cl_git_pass(diff_from_buffer(
&diff, content, strlen(content)));
git_diff_free(diff);
}
@@ -102,7 +102,7 @@ void test_diff_parse__no_extended_headers(void)
const char *content = PATCH_NO_EXTENDED_HEADERS;
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(
+ cl_git_pass(diff_from_buffer(
&diff, content, strlen(content)));
git_diff_free(diff);
}
@@ -125,7 +125,7 @@ void test_diff_parse__add_delete_no_index(void)
"-three\n";
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(
+ cl_git_pass(diff_from_buffer(
&diff, content, strlen(content)));
git_diff_free(diff);
}
@@ -166,7 +166,7 @@ static void test_tree_to_tree_computed_to_parsed(
cl_git_pass(git_diff_to_buf(&computed_buf,
computed, GIT_DIFF_FORMAT_PATCH));
- cl_git_pass(git_diff_from_buffer(&parsed,
+ cl_git_pass(diff_from_buffer(&parsed,
computed_buf.ptr, computed_buf.size));
diff_assert_equal(computed, parsed);
@@ -248,7 +248,7 @@ void test_diff_parse__get_patch_from_diff(void)
computed, GIT_DIFF_FORMAT_PATCH));
cl_git_pass(git_patch_from_diff(&patch_computed, computed, 0));
- cl_git_pass(git_diff_from_buffer(&parsed,
+ cl_git_pass(diff_from_buffer(&parsed,
computed_buf.ptr, computed_buf.size));
cl_git_pass(git_patch_from_diff(&patch_parsed, parsed, 0));
@@ -292,7 +292,7 @@ void test_diff_parse__foreach_works_with_parsed_patch(void)
int called = 0;
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(&diff, patch, strlen(patch)));
+ cl_git_pass(diff_from_buffer(&diff, patch, strlen(patch)));
cl_git_pass(git_diff_foreach(diff, file_cb, NULL, NULL, NULL, &called));
cl_assert_equal_i(called, 1);
@@ -312,7 +312,7 @@ void test_diff_parse__parsing_minimal_patch_succeeds(void)
git_buf buf = GIT_BUF_INIT;
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(&diff, patch, strlen(patch)));
+ cl_git_pass(diff_from_buffer(&diff, patch, strlen(patch)));
cl_git_pass(git_diff_to_buf(&buf, diff, GIT_DIFF_FORMAT_PATCH));
cl_assert_equal_s(patch, buf.ptr);
@@ -330,7 +330,7 @@ void test_diff_parse__patch_roundtrip_succeeds(void)
cl_git_pass(git_patch_from_buffers(&patch, buf1, strlen(buf1), "obj1", buf2, strlen(buf2), "obj2", NULL));
cl_git_pass(git_patch_to_buf(&patchbuf, patch));
- cl_git_pass(git_diff_from_buffer(&diff, patchbuf.ptr, patchbuf.size));
+ cl_git_pass(diff_from_buffer(&diff, patchbuf.ptr, patchbuf.size));
cl_git_pass(git_diff_to_buf(&diffbuf, diff, GIT_DIFF_FORMAT_PATCH));
cl_assert_equal_s(patchbuf.ptr, diffbuf.ptr);
@@ -372,7 +372,7 @@ void test_diff_parse__issue4672(void)
const git_diff_hunk *hunk;
size_t n, l = 0;
- cl_git_pass(git_diff_from_buffer(&diff, text, strlen(text)));
+ cl_git_pass(diff_from_buffer(&diff, text, strlen(text)));
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
cl_git_pass(git_patch_get_hunk(&hunk, &n, patch, 0));
@@ -393,7 +393,7 @@ void test_diff_parse__lineinfo(void)
const git_diff_hunk *hunk;
size_t n, l = 0;
- cl_git_pass(git_diff_from_buffer(&diff, text, strlen(text)));
+ cl_git_pass(diff_from_buffer(&diff, text, strlen(text)));
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
cl_git_pass(git_patch_get_hunk(&hunk, &n, patch, 0));
@@ -419,7 +419,7 @@ void test_diff_parse__new_file_with_space(void)
git_patch *patch;
git_diff *diff;
- cl_git_pass(git_diff_from_buffer(&diff, content, strlen(content)));
+ cl_git_pass(diff_from_buffer(&diff, content, strlen(content)));
cl_git_pass(git_patch_from_diff((git_patch **) &patch, diff, 0));
cl_assert_equal_p(patch->diff_opts.old_prefix, NULL);
@@ -437,7 +437,7 @@ void test_diff_parse__new_file_with_space_and_regenerate_patch(void)
git_diff *diff = NULL;
git_buf buf = GIT_BUF_INIT;
- cl_git_pass(git_diff_from_buffer(&diff, content, strlen(content)));
+ cl_git_pass(diff_from_buffer(&diff, content, strlen(content)));
cl_git_pass(git_diff_to_buf(&buf, diff, GIT_DIFF_FORMAT_PATCH));
git_buf_dispose(&buf);
@@ -450,7 +450,7 @@ void test_diff_parse__delete_file_with_space_and_regenerate_patch(void)
git_diff *diff = NULL;
git_buf buf = GIT_BUF_INIT;
- cl_git_pass(git_diff_from_buffer(&diff, content, strlen(content)));
+ cl_git_pass(diff_from_buffer(&diff, content, strlen(content)));
cl_git_pass(git_diff_to_buf(&buf, diff, GIT_DIFF_FORMAT_PATCH));
git_buf_dispose(&buf);
@@ -464,7 +464,7 @@ void test_diff_parse__crlf(void)
git_patch *patch;
const git_diff_delta *delta;
- cl_git_pass(git_diff_from_buffer(&diff, text, strlen(text)));
+ cl_git_pass(diff_from_buffer(&diff, text, strlen(text)));
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
delta = git_patch_get_delta(patch);
diff --git a/tests/libgit2/diff/patchid.c b/tests/libgit2/diff/patchid.c
index 1cc368e21..91807e7b7 100644
--- a/tests/libgit2/diff/patchid.c
+++ b/tests/libgit2/diff/patchid.c
@@ -1,5 +1,6 @@
#include "clar_libgit2.h"
#include "patch/patch_common.h"
+#include "diff_helpers.h"
static void verify_patch_id(const char *diff_content, const char *expected_id)
{
@@ -7,7 +8,7 @@ static void verify_patch_id(const char *diff_content, const char *expected_id)
git_diff *diff;
cl_git_pass(git_oid__fromstr(&expected_oid, expected_id, GIT_OID_SHA1));
- cl_git_pass(git_diff_from_buffer(&diff, diff_content, strlen(diff_content)));
+ cl_git_pass(diff_from_buffer(&diff, diff_content, strlen(diff_content)));
cl_git_pass(git_diff_patchid(&actual_oid, diff, NULL));
cl_assert_equal_oid(&expected_oid, &actual_oid);
diff --git a/tests/libgit2/diff/stats.c b/tests/libgit2/diff/stats.c
index b076ad5a9..7af891550 100644
--- a/tests/libgit2/diff/stats.c
+++ b/tests/libgit2/diff/stats.c
@@ -4,6 +4,7 @@
#include "commit.h"
#include "diff.h"
#include "diff_generate.h"
+#include "diff_helpers.h"
static git_repository *_repo;
static git_diff_stats *_stats;
@@ -368,7 +369,7 @@ void test_diff_stats__new_file(void)
" 1 file changed, 1 insertion(+)\n"
" create mode 100644 Gurjeet Singh\n";
- cl_git_pass(git_diff_from_buffer(&diff, input, strlen(input)));
+ cl_git_pass(diff_from_buffer(&diff, input, strlen(input)));
cl_git_pass(git_diff_get_stats(&_stats, diff));
cl_git_pass(git_diff_stats_to_buf(&buf, _stats, GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY, 0));
cl_assert_equal_s(stat, buf.ptr);
diff --git a/tests/libgit2/graph/commitgraph.c b/tests/libgit2/graph/commitgraph.c
index 82f7f936f..53869d61d 100644
--- a/tests/libgit2/graph/commitgraph.c
+++ b/tests/libgit2/graph/commitgraph.c
@@ -16,7 +16,7 @@ void test_graph_commitgraph__parse(void)
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_str_joinpath(&commit_graph_path, git_repository_path(repo), "objects/info/commit-graph"));
- cl_git_pass(git_commit_graph_file_open(&file, git_str_cstr(&commit_graph_path)));
+ cl_git_pass(git_commit_graph_file_open(&file, git_str_cstr(&commit_graph_path), GIT_OID_SHA1));
cl_assert_equal_i(git_commit_graph_file_needs_refresh(file, git_str_cstr(&commit_graph_path)), 0);
cl_git_pass(git_oid__fromstr(&id, "5001298e0c09ad9c34e4249bc5801c75e9754fa5", GIT_OID_SHA1));
@@ -60,7 +60,7 @@ void test_graph_commitgraph__parse_octopus_merge(void)
cl_git_pass(git_repository_open(&repo, cl_fixture("merge-recursive/.gitted")));
cl_git_pass(git_str_joinpath(&commit_graph_path, git_repository_path(repo), "objects/info/commit-graph"));
- cl_git_pass(git_commit_graph_file_open(&file, git_str_cstr(&commit_graph_path)));
+ cl_git_pass(git_commit_graph_file_open(&file, git_str_cstr(&commit_graph_path), GIT_OID_SHA1));
cl_git_pass(git_oid__fromstr(&id, "d71c24b3b113fd1d1909998c5bfe33b86a65ee03", GIT_OID_SHA1));
cl_git_pass(git_commit_graph_entry_find(&e, file, &id, GIT_OID_SHA1_HEXSIZE));
@@ -103,7 +103,12 @@ void test_graph_commitgraph__writer(void)
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_str_joinpath(&path, git_repository_path(repo), "objects/info"));
+
+#ifdef GIT_EXPERIMENTAL_SHA256
+ cl_git_pass(git_commit_graph_writer_new(&w, git_str_cstr(&path), GIT_OID_SHA1));
+#else
cl_git_pass(git_commit_graph_writer_new(&w, git_str_cstr(&path)));
+#endif
/* This is equivalent to `git commit-graph write --reachable`. */
cl_git_pass(git_revwalk_new(&walk, repo));
@@ -135,7 +140,11 @@ void test_graph_commitgraph__validate(void)
cl_git_pass(git_str_joinpath(&objects_dir, git_repository_path(repo), "objects"));
/* git_commit_graph_open() calls git_commit_graph_validate() */
+#ifdef GIT_EXPERIMENTAL_SHA256
+ cl_git_pass(git_commit_graph_open(&cgraph, git_str_cstr(&objects_dir), GIT_OID_SHA1));
+#else
cl_git_pass(git_commit_graph_open(&cgraph, git_str_cstr(&objects_dir)));
+#endif
git_commit_graph_free(cgraph);
git_str_dispose(&objects_dir);
@@ -158,7 +167,11 @@ void test_graph_commitgraph__validate_corrupt(void)
cl_must_pass(p_close(fd));
/* git_commit_graph_open() calls git_commit_graph_validate() */
+#ifdef GIT_EXPERIMENTAL_SHA256
+ cl_git_fail(git_commit_graph_open(&cgraph, cl_git_sandbox_path(1, "testrepo.git", "objects", NULL), GIT_OID_SHA1));
+#else
cl_git_fail(git_commit_graph_open(&cgraph, cl_git_sandbox_path(1, "testrepo.git", "objects", NULL)));
+#endif
git_commit_graph_free(cgraph);
git_repository_free(repo);
diff --git a/tests/libgit2/index/cache.c b/tests/libgit2/index/cache.c
index 7576331b0..77f19a50b 100644
--- a/tests/libgit2/index/cache.c
+++ b/tests/libgit2/index/cache.c
@@ -24,7 +24,7 @@ void test_index_cache__write_extension_at_root(void)
const char *tree_id_str = "45dd856fdd4d89b884c340ba0e047752d9b085d6";
const char *index_file = "index-tree";
- cl_git_pass(git_index_open(&index, index_file));
+ cl_git_pass(git_index__open(&index, index_file, GIT_OID_SHA1));
cl_assert(index->tree == NULL);
cl_git_pass(git_oid__fromstr(&id, tree_id_str, GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
@@ -35,7 +35,7 @@ void test_index_cache__write_extension_at_root(void)
cl_git_pass(git_index_write(index));
git_index_free(index);
- cl_git_pass(git_index_open(&index, index_file));
+ cl_git_pass(git_index__open(&index, index_file, GIT_OID_SHA1));
cl_assert(index->tree);
cl_assert_equal_i(git_index_entrycount(index), index->tree->entry_count);
@@ -56,7 +56,7 @@ void test_index_cache__write_extension_invalidated_root(void)
const char *index_file = "index-tree-invalidated";
git_index_entry entry;
- cl_git_pass(git_index_open(&index, index_file));
+ cl_git_pass(git_index__open(&index, index_file, GIT_OID_SHA1));
cl_assert(index->tree == NULL);
cl_git_pass(git_oid__fromstr(&id, tree_id_str, GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
@@ -77,7 +77,7 @@ void test_index_cache__write_extension_invalidated_root(void)
cl_git_pass(git_index_write(index));
git_index_free(index);
- cl_git_pass(git_index_open(&index, index_file));
+ cl_git_pass(git_index__open(&index, index_file, GIT_OID_SHA1));
cl_assert(index->tree);
cl_assert_equal_i(-1, index->tree->entry_count);
@@ -96,7 +96,7 @@ void test_index_cache__read_tree_no_children(void)
git_tree *tree;
git_oid id;
- cl_git_pass(git_index_new(&index));
+ cl_git_pass(git_index__new(&index, GIT_OID_SHA1));
cl_assert(index->tree == NULL);
cl_git_pass(git_oid__fromstr(&id, "45dd856fdd4d89b884c340ba0e047752d9b085d6", GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
diff --git a/tests/libgit2/index/inmemory.c b/tests/libgit2/index/inmemory.c
index 38e91e0fd..39374af67 100644
--- a/tests/libgit2/index/inmemory.c
+++ b/tests/libgit2/index/inmemory.c
@@ -1,10 +1,11 @@
#include "clar_libgit2.h"
+#include "index.h"
void test_index_inmemory__can_create_an_inmemory_index(void)
{
git_index *index;
- cl_git_pass(git_index_new(&index));
+ cl_git_pass(git_index__new(&index, GIT_OID_SHA1));
cl_assert_equal_i(0, (int)git_index_entrycount(index));
git_index_free(index);
@@ -14,7 +15,7 @@ void test_index_inmemory__cannot_add_bypath_to_an_inmemory_index(void)
{
git_index *index;
- cl_git_pass(git_index_new(&index));
+ cl_git_pass(git_index__new(&index, GIT_OID_SHA1));
cl_assert_equal_i(GIT_ERROR, git_index_add_bypath(index, "test.txt"));
diff --git a/tests/libgit2/index/racy.c b/tests/libgit2/index/racy.c
index 07b3b73d4..a1d6f9c6e 100644
--- a/tests/libgit2/index/racy.c
+++ b/tests/libgit2/index/racy.c
@@ -287,7 +287,7 @@ void test_index_racy__read_index_smudges(void)
setup_race();
cl_git_pass(git_repository_index(&index, g_repo));
- cl_git_pass(git_index_new(&newindex));
+ cl_git_pass(git_index__new(&newindex, GIT_OID_SHA1));
cl_git_pass(git_index_read_index(newindex, index));
cl_assert(entry = git_index_get_bypath(newindex, "A", 0));
@@ -305,7 +305,7 @@ void test_index_racy__read_index_clears_uptodate_bit(void)
setup_uptodate_files();
cl_git_pass(git_repository_index(&index, g_repo));
- cl_git_pass(git_index_new(&newindex));
+ cl_git_pass(git_index__new(&newindex, GIT_OID_SHA1));
cl_git_pass(git_index_read_index(newindex, index));
/* ensure that files brought in from the other index are not uptodate */
diff --git a/tests/libgit2/index/read_index.c b/tests/libgit2/index/read_index.c
index ac03cf177..9c80be299 100644
--- a/tests/libgit2/index/read_index.c
+++ b/tests/libgit2/index/read_index.c
@@ -42,7 +42,7 @@ void test_index_read_index__maintains_stat_cache(void)
/* read-tree, then read index */
git_tree_lookup(&tree, _repo, &index_id);
- cl_git_pass(git_index_new(&new_index));
+ cl_git_pass(git_index__new(&new_index, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(new_index, tree));
git_tree_free(tree);
@@ -81,7 +81,7 @@ static bool roundtrip_with_read_index(const char *tree_idstr)
cl_git_pass(git_oid__fromstr(&tree_id, tree_idstr, GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
- cl_git_pass(git_index_new(&tree_index));
+ cl_git_pass(git_index__new(&tree_index, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(tree_index, tree));
cl_git_pass(git_index_read_index(_index, tree_index));
cl_git_pass(git_index_write_tree(&new_tree_id, _index));
@@ -113,12 +113,12 @@ void test_index_read_index__read_and_writes(void)
cl_git_pass(git_oid__fromstr(&tree_id, "ae90f12eea699729ed24555e40b9fd669da12a12", GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
- cl_git_pass(git_index_new(&tree_index));
+ cl_git_pass(git_index__new(&tree_index, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(tree_index, tree));
cl_git_pass(git_index_read_index(_index, tree_index));
cl_git_pass(git_index_write(_index));
- cl_git_pass(git_index_open(&new_index, git_index_path(_index)));
+ cl_git_pass(git_index__open(&new_index, git_index_path(_index), GIT_OID_SHA1));
cl_git_pass(git_index_write_tree_to(&new_tree_id, new_index, _repo));
cl_assert_equal_oid(&tree_id, &new_tree_id);
@@ -174,8 +174,8 @@ void test_index_read_index__handles_conflicts(void)
cl_git_pass(git_oid__fromstr(&tree_id, "ae90f12eea699729ed24555e40b9fd669da12a12", GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
- cl_git_pass(git_index_new(&index));
- cl_git_pass(git_index_new(&new_index));
+ cl_git_pass(git_index__new(&index, GIT_OID_SHA1));
+ cl_git_pass(git_index__new(&new_index, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(index, tree));
cl_git_pass(git_index_read_tree(new_index, tree));
diff --git a/tests/libgit2/index/tests.c b/tests/libgit2/index/tests.c
index da3ff6dd7..b48eb0fc1 100644
--- a/tests/libgit2/index/tests.c
+++ b/tests/libgit2/index/tests.c
@@ -81,7 +81,7 @@ void test_index_tests__empty_index(void)
{
git_index *index;
- cl_git_pass(git_index_open(&index, "in-memory-index"));
+ cl_git_pass(git_index__open(&index, "in-memory-index", GIT_OID_SHA1));
cl_assert(index->on_disk == 0);
cl_assert(git_index_entrycount(index) == 0);
@@ -96,7 +96,7 @@ void test_index_tests__default_test_index(void)
unsigned int i;
git_index_entry **entries;
- cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_assert(index->on_disk);
cl_assert(git_index_entrycount(index) == index_entry_count);
@@ -119,7 +119,7 @@ void test_index_tests__gitgit_index(void)
{
git_index *index;
- cl_git_pass(git_index_open(&index, TEST_INDEX2_PATH));
+ cl_git_pass(git_index__open(&index, TEST_INDEX2_PATH, GIT_OID_SHA1));
cl_assert(index->on_disk);
cl_assert(git_index_entrycount(index) == index_entry_count_2);
@@ -134,7 +134,7 @@ void test_index_tests__find_in_existing(void)
git_index *index;
unsigned int i;
- cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
for (i = 0; i < ARRAY_SIZE(test_entries); ++i) {
size_t idx;
@@ -151,7 +151,7 @@ void test_index_tests__find_in_empty(void)
git_index *index;
unsigned int i;
- cl_git_pass(git_index_open(&index, "fake-index"));
+ cl_git_pass(git_index__open(&index, "fake-index", GIT_OID_SHA1));
for (i = 0; i < ARRAY_SIZE(test_entries); ++i) {
cl_assert(GIT_ENOTFOUND == git_index_find(NULL, index, test_entries[i].path));
@@ -166,7 +166,7 @@ void test_index_tests__find_prefix(void)
const git_index_entry *entry;
size_t pos;
- cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_git_pass(git_index_find_prefix(&pos, index, "src"));
entry = git_index_get_byindex(index, pos);
@@ -187,7 +187,7 @@ void test_index_tests__write(void)
copy_file(TEST_INDEXBIG_PATH, "index_rewrite");
- cl_git_pass(git_index_open(&index, "index_rewrite"));
+ cl_git_pass(git_index__open(&index, "index_rewrite", GIT_OID_SHA1));
cl_assert(index->on_disk);
cl_git_pass(git_index_write(index));
@@ -218,7 +218,7 @@ void test_index_tests__sort1(void)
/* sort the entries in an empty index */
git_index *index;
- cl_git_pass(git_index_open(&index, "fake-index"));
+ cl_git_pass(git_index__open(&index, "fake-index", GIT_OID_SHA1));
/* FIXME: this test is slightly dumb */
cl_assert(git_vector_is_sorted(&index->entries));
@@ -703,7 +703,7 @@ void test_index_tests__write_tree_invalid_unowned_index(void)
git_index_entry entry = {{0}};
git_oid tree_id;
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_oid__fromstr(&entry.id, "8312e0a89a9cbab77c732b6bc39b51a783e3a318", GIT_OID_SHA1));
entry.path = "foo";
@@ -966,7 +966,7 @@ void test_index_tests__reload_from_disk(void)
cl_git_pass(git_repository_index(&write_index, repo));
cl_assert_equal_i(false, write_index->on_disk);
- cl_git_pass(git_index_open(&read_index, write_index->index_file_path));
+ cl_git_pass(git_index__open(&read_index, write_index->index_file_path, GIT_OID_SHA1));
cl_assert_equal_i(false, read_index->on_disk);
/* Stage two new files against the write_index */
@@ -1004,7 +1004,7 @@ void test_index_tests__corrupted_extension(void)
{
git_index *index;
- cl_git_fail_with(git_index_open(&index, TEST_INDEXBAD_PATH), GIT_ERROR);
+ cl_git_fail_with(git_index__open(&index, TEST_INDEXBAD_PATH, GIT_OID_SHA1), GIT_ERROR);
}
void test_index_tests__reload_while_ignoring_case(void)
@@ -1012,7 +1012,7 @@ void test_index_tests__reload_while_ignoring_case(void)
git_index *index;
unsigned int caps;
- cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_git_pass(git_vector_verify_sorted(&index->entries));
caps = git_index_caps(index);
@@ -1037,7 +1037,7 @@ void test_index_tests__change_icase_on_instance(void)
unsigned int caps;
const git_index_entry *e;
- cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_git_pass(git_vector_verify_sorted(&index->entries));
caps = git_index_caps(index);
@@ -1093,7 +1093,7 @@ void test_index_tests__can_iterate(void)
size_t i, iterator_idx = 0, found = 0;
int ret;
- cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_git_pass(git_index_iterator_new(&iterator, index));
cl_assert(git_vector_is_sorted(&iterator->snap));
@@ -1136,7 +1136,7 @@ void test_index_tests__can_modify_while_iterating(void)
size_t expected = 0, seen = 0;
int ret;
- cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_git_pass(git_index_iterator_new(&iterator, index));
expected = git_index_entrycount(index);
diff --git a/tests/libgit2/index/tests256.c b/tests/libgit2/index/tests256.c
new file mode 100644
index 000000000..fed8bfb93
--- /dev/null
+++ b/tests/libgit2/index/tests256.c
@@ -0,0 +1,1169 @@
+#include "clar_libgit2.h"
+#include "index.h"
+
+#ifdef GIT_EXPERIMENTAL_SHA256
+
+static const size_t index_entry_count = 4344;
+#define TEST_INDEX_PATH cl_fixture("git-sha256.index")
+
+static git_repository_init_options repo_init_opts =
+ GIT_REPOSITORY_INIT_OPTIONS_INIT;
+
+/* Suite data */
+struct test_entry {
+ size_t index;
+ char path[128];
+ off64_t file_size;
+ git_time_t mtime;
+};
+
+static struct test_entry test_entries[] = {
+ { 892, "Makefile", 120084, 0x642c3a6e },
+ { 1542, "git.c", 27432, 0x642c3a6e },
+ { 1737, "perl/Git.pm", 48084, 0x642c3a6e },
+ { 1961, "t/Makefile", 4711, 0x642c3a6e },
+ { 4343, "zlib.c", 6271, 0x642c3a6f }
+};
+
+/* Helpers */
+static void copy_file(const char *src, const char *dst)
+{
+ git_str source_buf = GIT_STR_INIT;
+ git_file dst_fd;
+
+ cl_git_pass(git_futils_readbuffer(&source_buf, src));
+
+ dst_fd = git_futils_creat_withpath(dst, 0777, 0666); /* -V536 */
+ if (dst_fd < 0)
+ goto cleanup;
+
+ cl_git_pass(p_write(dst_fd, source_buf.ptr, source_buf.size));
+
+cleanup:
+ git_str_dispose(&source_buf);
+ p_close(dst_fd);
+}
+
+static void files_are_equal(const char *a, const char *b)
+{
+ git_str buf_a = GIT_STR_INIT;
+ git_str buf_b = GIT_STR_INIT;
+
+ if (git_futils_readbuffer(&buf_a, a) < 0)
+ cl_assert(0);
+
+ if (git_futils_readbuffer(&buf_b, b) < 0) {
+ git_str_dispose(&buf_a);
+ cl_assert(0);
+ }
+
+ cl_assert_equal_sz(buf_a.size, buf_b.size);
+ cl_assert(!memcmp(buf_a.ptr, buf_b.ptr, buf_a.size));
+
+ git_str_dispose(&buf_a);
+ git_str_dispose(&buf_b);
+}
+
+#endif
+
+/* Fixture setup and teardown */
+void test_index_tests256__initialize(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ repo_init_opts.flags |= GIT_REPOSITORY_INIT_MKPATH;
+ repo_init_opts.oid_type = GIT_OID_SHA256;
+#endif
+}
+
+void test_index_tests256__cleanup(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY, 0));
+#endif
+}
+
+void test_index_tests256__empty_index(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_index *index;
+
+ cl_git_pass(git_index__open(&index, "in-memory-index", GIT_OID_SHA256));
+ cl_assert(index->on_disk == 0);
+
+ cl_assert(git_index_entrycount(index) == 0);
+ cl_assert(git_vector_is_sorted(&index->entries));
+
+ git_index_free(index);
+#endif
+}
+
+void test_index_tests256__default_test_index(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_index *index;
+ unsigned int i;
+ git_index_entry **entries;
+
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256));
+ cl_assert(index->on_disk);
+
+ cl_assert_equal_sz(git_index_entrycount(index), index_entry_count);
+ cl_assert(git_vector_is_sorted(&index->entries));
+
+ entries = (git_index_entry **)index->entries.contents;
+
+ for (i = 0; i < ARRAY_SIZE(test_entries); ++i) {
+ git_index_entry *e = entries[test_entries[i].index];
+
+ cl_assert_equal_s(e->path, test_entries[i].path);
+ cl_assert_equal_i(e->mtime.seconds, test_entries[i].mtime);
+ cl_assert_equal_i(e->file_size, test_entries[i].file_size);
+ }
+
+ git_index_free(index);
+#endif
+}
+
+void test_index_tests256__find_in_existing(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_index *index;
+ unsigned int i;
+
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256));
+
+ for (i = 0; i < ARRAY_SIZE(test_entries); ++i) {
+ size_t idx;
+
+ cl_assert(!git_index_find(&idx, index, test_entries[i].path));
+ cl_assert(idx == test_entries[i].index);
+ }
+
+ git_index_free(index);
+#endif
+}
+
+void test_index_tests256__find_in_empty(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_index *index;
+ unsigned int i;
+
+ cl_git_pass(git_index__open(&index, "fake-index", GIT_OID_SHA256));
+
+ for (i = 0; i < ARRAY_SIZE(test_entries); ++i) {
+ cl_assert(GIT_ENOTFOUND == git_index_find(NULL, index, test_entries[i].path));
+ }
+
+ git_index_free(index);
+#endif
+}
+
+void test_index_tests256__find_prefix(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_index *index;
+ const git_index_entry *entry;
+ size_t pos;
+
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256));
+
+ cl_git_pass(git_index_find_prefix(&pos, index, "Documentation"));
+ entry = git_index_get_byindex(index, pos);
+ cl_assert(git__strcmp(entry->path, "Documentation/.gitattributes") == 0);
+
+ cl_git_pass(git_index_find_prefix(&pos, index, "contrib/RE"));
+ entry = git_index_get_byindex(index, pos);
+ cl_assert(git__strcmp(entry->path, "contrib/README") == 0);
+
+ cl_assert(GIT_ENOTFOUND == git_index_find_prefix(NULL, index, "blah"));
+
+ git_index_free(index);
+#endif
+}
+
+void test_index_tests256__write(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_index *index;
+
+ copy_file(TEST_INDEX_PATH, "index_rewrite");
+
+ cl_git_pass(git_index__open(&index, "index_rewrite", GIT_OID_SHA256));
+ cl_assert(index->on_disk);
+
+ cl_git_pass(git_index_write(index));
+ files_are_equal(TEST_INDEX_PATH, "index_rewrite");
+
+ git_index_free(index);
+
+ p_unlink("index_rewrite");
+#endif
+}
+
+void test_index_tests256__sort1(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ /* sort the entries in an empty index */
+ git_index *index;
+
+ cl_git_pass(git_index__open(&index, "fake-index", GIT_OID_SHA256));
+
+ /* FIXME: this test is slightly dumb */
+ cl_assert(git_vector_is_sorted(&index->entries));
+
+ git_index_free(index);
+#endif
+}
+
+#ifdef GIT_EXPERIMENTAL_SHA256
+static void cleanup_myrepo(void *opaque)
+{
+ GIT_UNUSED(opaque);
+ cl_fixture_cleanup("myrepo");
+}
+#endif
+
+void test_index_tests256__add(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_index *index;
+ git_filebuf file = GIT_FILEBUF_INIT;
+ git_repository *repo;
+ const git_index_entry *entry;
+ git_oid id1;
+
+ cl_set_cleanup(&cleanup_myrepo, NULL);
+
+ /* Initialize a new repository */
+ cl_git_pass(git_repository_init_ext(&repo, "./myrepo", &repo_init_opts));
+
+ /* Ensure we're the only guy in the room */
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert(git_index_entrycount(index) == 0);
+
+ /* Create a new file in the working directory */
+ cl_git_pass(git_futils_mkpath2file("myrepo/test.txt", 0777));
+ cl_git_pass(git_filebuf_open(&file, "myrepo/test.txt", 0, 0666));
+ cl_git_pass(git_filebuf_write(&file, "hey there\n", 10));
+ cl_git_pass(git_filebuf_commit(&file));
+
+ /* Store the expected hash of the file/blob
+ * This has been generated by executing the following
+ * $ echo "hey there" | git hash-object --stdin
+ */
+ cl_git_pass(git_oid__fromstr(&id1, "aea29dc305d40e362df25c3fdeed5502fd56b182af01b7740d297a24459333c5", GIT_OID_SHA256));
+
+ /* Add the new file to the index */
+ cl_git_pass(git_index_add_bypath(index, "test.txt"));
+
+ /* Wow... it worked! */
+ cl_assert(git_index_entrycount(index) == 1);
+ entry = git_index_get_byindex(index, 0);
+
+ /* And the built-in hashing mechanism worked as expected */
+ cl_assert_equal_oid(&id1, &entry->id);
+
+ /* Test access by path instead of index */
+ cl_assert((entry = git_index_get_bypath(index, "test.txt", 0)) != NULL);
+ cl_assert_equal_oid(&id1, &entry->id);
+
+ git_index_free(index);
+ git_repository_free(repo);
+#endif
+}
+
+void test_index_tests256__add_frombuffer(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_index *index;
+ git_repository *repo;
+ git_index_entry entry;
+ const git_index_entry *returned_entry;
+
+ git_oid id1;
+ git_blob *blob;
+
+ const char *content = "hey there\n";
+
+ cl_set_cleanup(&cleanup_myrepo, NULL);
+
+ /* Initialize a new repository */
+ cl_git_pass(git_repository_init_ext(&repo, "./myrepo", &repo_init_opts));
+
+ /* Ensure we're the only guy in the room */
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert(git_index_entrycount(index) == 0);
+
+ /* Store the expected hash of the file/blob
+ * This has been generated by executing the following
+ * $ echo "hey there" | git hash-object --stdin
+ */
+ cl_git_pass(git_oid__fromstr(&id1, "aea29dc305d40e362df25c3fdeed5502fd56b182af01b7740d297a24459333c5", GIT_OID_SHA256));
+
+ /* Add the new file to the index */
+ memset(&entry, 0x0, sizeof(git_index_entry));
+ entry.mode = GIT_FILEMODE_BLOB;
+ entry.path = "test.txt";
+ cl_git_pass(git_index_add_from_buffer(index, &entry,
+ content, strlen(content)));
+
+ /* Wow... it worked! */
+ cl_assert(git_index_entrycount(index) == 1);
+ returned_entry = git_index_get_byindex(index, 0);
+
+ /* And the built-in hashing mechanism worked as expected */
+ cl_assert_equal_oid(&id1, &returned_entry->id);
+ /* And mode is the one asked */
+ cl_assert_equal_i(GIT_FILEMODE_BLOB, returned_entry->mode);
+
+ /* Test access by path instead of index */
+ cl_assert((returned_entry = git_index_get_bypath(index, "test.txt", 0)) != NULL);
+ cl_assert_equal_oid(&id1, &returned_entry->id);
+
+ /* Test the blob is in the repository */
+ cl_git_pass(git_blob_lookup(&blob, repo, &id1));
+ cl_assert_equal_s(
+ content, git_blob_rawcontent(blob));
+ git_blob_free(blob);
+
+ git_index_free(index);
+ git_repository_free(repo);
+#endif
+}
+
+void test_index_tests256__dirty_and_clean(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_repository *repo;
+ git_index *index;
+ git_index_entry entry = {{0}};
+
+ /* Index is not dirty after opening */
+ cl_git_pass(git_repository_init_ext(&repo, "./myrepo", &repo_init_opts));
+ cl_git_pass(git_repository_index(&index, repo));
+
+ cl_assert(git_index_entrycount(index) == 0);
+ cl_assert(!git_index_is_dirty(index));
+
+ /* Index is dirty after adding an entry */
+ entry.mode = GIT_FILEMODE_BLOB;
+ entry.path = "test.txt";
+ cl_git_pass(git_index_add_from_buffer(index, &entry, "Hi.\n", 4));
+ cl_assert(git_index_entrycount(index) == 1);
+ cl_assert(git_index_is_dirty(index));
+
+ /* Index is not dirty after write */
+ cl_git_pass(git_index_write(index));
+ cl_assert(!git_index_is_dirty(index));
+
+ /* Index is dirty after removing an entry */
+ cl_git_pass(git_index_remove_bypath(index, "test.txt"));
+ cl_assert(git_index_entrycount(index) == 0);
+ cl_assert(git_index_is_dirty(index));
+
+ /* Index is not dirty after write */
+ cl_git_pass(git_index_write(index));
+ cl_assert(!git_index_is_dirty(index));
+
+ /* Index remains not dirty after read */
+ cl_git_pass(git_index_read(index, 0));
+ cl_assert(!git_index_is_dirty(index));
+
+ /* Index is dirty when we do an unforced read with dirty content */
+ cl_git_pass(git_index_add_from_buffer(index, &entry, "Hi.\n", 4));
+ cl_assert(git_index_entrycount(index) == 1);
+ cl_assert(git_index_is_dirty(index));
+
+ cl_git_pass(git_index_read(index, 0));
+ cl_assert(git_index_is_dirty(index));
+
+ /* Index is clean when we force a read with dirty content */
+ cl_git_pass(git_index_read(index, 1));
+ cl_assert(!git_index_is_dirty(index));
+
+ git_index_free(index);
+ git_repository_free(repo);
+#endif
+}
+
+void test_index_tests256__dirty_fails_optionally(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_repository *repo;
+ git_index *index;
+ git_index_entry entry = {{0}};
+
+ /* Index is not dirty after opening */
+ repo = cl_git_sandbox_init("testrepo");
+ cl_git_pass(git_repository_index(&index, repo));
+
+ /* Index is dirty after adding an entry */
+ entry.mode = GIT_FILEMODE_BLOB;
+ entry.path = "test.txt";
+ cl_git_pass(git_index_add_from_buffer(index, &entry, "Hi.\n", 4));
+ cl_assert(git_index_is_dirty(index));
+
+ cl_git_pass(git_checkout_head(repo, NULL));
+
+ /* Index is dirty (again) after adding an entry */
+ entry.mode = GIT_FILEMODE_BLOB;
+ entry.path = "test.txt";
+ cl_git_pass(git_index_add_from_buffer(index, &entry, "Hi.\n", 4));
+ cl_assert(git_index_is_dirty(index));
+
+ cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY, 1));
+ cl_git_fail_with(GIT_EINDEXDIRTY, git_checkout_head(repo, NULL));
+
+ git_index_free(index);
+ cl_git_sandbox_cleanup();
+#endif
+}
+
+void test_index_tests256__add_frombuffer_reset_entry(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_index *index;
+ git_repository *repo;
+ git_index_entry entry;
+ const git_index_entry *returned_entry;
+ git_filebuf file = GIT_FILEBUF_INIT;
+
+ git_oid id1;
+ git_blob *blob;
+ const char *old_content = "here\n";
+ const char *content = "hey there\n";
+
+ cl_set_cleanup(&cleanup_myrepo, NULL);
+
+ /* Initialize a new repository */
+ cl_git_pass(git_repository_init_ext(&repo, "./myrepo", &repo_init_opts));
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_futils_mkpath2file("myrepo/test.txt", 0777));
+ cl_git_pass(git_filebuf_open(&file, "myrepo/test.txt", 0, 0666));
+ cl_git_pass(git_filebuf_write(&file, old_content, strlen(old_content)));
+ cl_git_pass(git_filebuf_commit(&file));
+
+ /* Store the expected hash of the file/blob
+ * This has been generated by executing the following
+ * $ echo "hey there" | git hash-object --stdin
+ */
+ cl_git_pass(git_oid__fromstr(&id1, "aea29dc305d40e362df25c3fdeed5502fd56b182af01b7740d297a24459333c5", GIT_OID_SHA256));
+
+ cl_git_pass(git_index_add_bypath(index, "test.txt"));
+
+ /* Add the new file to the index */
+ memset(&entry, 0x0, sizeof(git_index_entry));
+ entry.mode = GIT_FILEMODE_BLOB;
+ entry.path = "test.txt";
+ cl_git_pass(git_index_add_from_buffer(index, &entry,
+ content, strlen(content)));
+
+ /* Wow... it worked! */
+ cl_assert(git_index_entrycount(index) == 1);
+ returned_entry = git_index_get_byindex(index, 0);
+
+ /* And the built-in hashing mechanism worked as expected */
+ cl_assert_equal_oid(&id1, &returned_entry->id);
+ /* And mode is the one asked */
+ cl_assert_equal_i(GIT_FILEMODE_BLOB, returned_entry->mode);
+
+ /* Test access by path instead of index */
+ cl_assert((returned_entry = git_index_get_bypath(index, "test.txt", 0)) != NULL);
+ cl_assert_equal_oid(&id1, &returned_entry->id);
+ cl_assert_equal_i(0, returned_entry->dev);
+ cl_assert_equal_i(0, returned_entry->ino);
+ cl_assert_equal_i(0, returned_entry->uid);
+ cl_assert_equal_i(0, returned_entry->uid);
+ cl_assert_equal_i(10, returned_entry->file_size);
+
+ /* Test the blob is in the repository */
+ cl_git_pass(git_blob_lookup(&blob, repo, &id1));
+ cl_assert_equal_s(content, git_blob_rawcontent(blob));
+ git_blob_free(blob);
+
+ git_index_free(index);
+ git_repository_free(repo);
+#endif
+}
+
+void test_index_tests256__add_bypath_to_a_bare_repository_returns_EBAREPO(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_repository *bare_repo;
+ git_index *index;
+
+ cl_git_pass(git_repository_open(&bare_repo, cl_fixture("testrepo.git")));
+ cl_git_pass(git_repository_index(&index, bare_repo));
+
+ cl_assert_equal_i(GIT_EBAREREPO, git_index_add_bypath(index, "test.txt"));
+
+ git_index_free(index);
+ git_repository_free(bare_repo);
+#endif
+}
+
+#ifdef GIT_EXPERIMENTAL_SHA256
+static void assert_add_bypath_fails(git_repository *repo, const char *fn)
+{
+ git_index *index;
+ git_str path = GIT_STR_INIT;
+
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert(git_index_entrycount(index) == 0);
+
+ git_str_joinpath(&path, "./invalid", fn);
+
+ cl_git_mkfile(path.ptr, NULL);
+ cl_git_fail(git_index_add_bypath(index, fn));
+ cl_must_pass(p_unlink(path.ptr));
+
+ cl_assert(git_index_entrycount(index) == 0);
+
+ git_str_dispose(&path);
+ git_index_free(index);
+}
+#endif
+
+/* Test that writing an invalid filename fails */
+void test_index_tests256__cannot_add_invalid_filename(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_repository *repo;
+
+ cl_must_pass(p_mkdir("invalid", 0700));
+ cl_git_pass(git_repository_init_ext(&repo, "./invalid", &repo_init_opts));
+ cl_must_pass(p_mkdir("./invalid/subdir", 0777));
+
+ /* cl_git_mkfile() needs the dir to exist */
+ if (!git_fs_path_exists("./invalid/.GIT"))
+ cl_must_pass(p_mkdir("./invalid/.GIT", 0777));
+ if (!git_fs_path_exists("./invalid/.GiT"))
+ cl_must_pass(p_mkdir("./invalid/.GiT", 0777));
+
+ assert_add_bypath_fails(repo, ".git/hello");
+ assert_add_bypath_fails(repo, ".GIT/hello");
+ assert_add_bypath_fails(repo, ".GiT/hello");
+ assert_add_bypath_fails(repo, "./.git/hello");
+ assert_add_bypath_fails(repo, "./foo");
+ assert_add_bypath_fails(repo, "./bar");
+ assert_add_bypath_fails(repo, "subdir/../bar");
+
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("invalid");
+#endif
+}
+
+#ifdef GIT_EXPERIMENTAL_SHA256
+static void assert_add_fails(git_repository *repo, const char *fn)
+{
+ git_index *index;
+ git_str path = GIT_STR_INIT;
+ git_index_entry entry = {{0}};
+
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert(git_index_entrycount(index) == 0);
+
+ entry.path = fn;
+ entry.mode = GIT_FILEMODE_BLOB;
+ cl_git_pass(git_oid__fromstr(&entry.id, "aea29dc305d40e362df25c3fdeed5502fd56b182af01b7740d297a24459333c5", GIT_OID_SHA256));
+
+ cl_git_fail(git_index_add(index, &entry));
+
+ cl_assert(git_index_entrycount(index) == 0);
+
+ git_str_dispose(&path);
+ git_index_free(index);
+}
+#endif
+
+/*
+ * Test that writing an invalid filename fails on filesystem
+ * specific protected names
+ */
+void test_index_tests256__cannot_add_protected_invalid_filename(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_repository *repo;
+ git_index *index;
+
+ cl_must_pass(p_mkdir("invalid", 0700));
+
+ cl_git_pass(git_repository_init(&repo, "./invalid", 0));
+
+ /* add a file to the repository so we can reference it later */
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_mkfile("invalid/dummy.txt", "");
+ cl_git_pass(git_index_add_bypath(index, "dummy.txt"));
+ cl_must_pass(p_unlink("invalid/dummy.txt"));
+ cl_git_pass(git_index_remove_bypath(index, "dummy.txt"));
+ git_index_free(index);
+
+ cl_repo_set_bool(repo, "core.protectHFS", true);
+ cl_repo_set_bool(repo, "core.protectNTFS", true);
+
+ assert_add_fails(repo, ".git./hello");
+ assert_add_fails(repo, ".git\xe2\x80\xad/hello");
+ assert_add_fails(repo, "git~1/hello");
+ assert_add_fails(repo, ".git\xe2\x81\xaf/hello");
+ assert_add_fails(repo, ".git::$INDEX_ALLOCATION/dummy-file");
+
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("invalid");
+#endif
+}
+
+#ifdef GIT_EXPERIMENTAL_SHA256
+static void replace_char(char *str, char in, char out)
+{
+ char *c = str;
+
+ while (*c++)
+ if (*c == in)
+ *c = out;
+}
+
+static void assert_write_fails(git_repository *repo, const char *fn_orig)
+{
+ git_index *index;
+ git_oid expected;
+ const git_index_entry *entry;
+ git_str path = GIT_STR_INIT;
+ char *fn;
+
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert(git_index_entrycount(index) == 0);
+
+ /*
+ * Sneak a valid path into the index, we'll update it
+ * to an invalid path when we try to write the index.
+ */
+ fn = git__strdup(fn_orig);
+ replace_char(fn, '/', '_');
+ replace_char(fn, ':', '!');
+
+ git_str_joinpath(&path, "./invalid", fn);
+
+ cl_git_mkfile(path.ptr, NULL);
+
+ cl_git_pass(git_index_add_bypath(index, fn));
+
+ cl_assert(entry = git_index_get_bypath(index, fn, 0));
+
+ /* kids, don't try this at home */
+ replace_char((char *)entry->path, '_', '/');
+ replace_char((char *)entry->path, '!', ':');
+
+ /* write-tree */
+ cl_git_fail(git_index_write_tree(&expected, index));
+
+ p_unlink(path.ptr);
+
+ cl_git_pass(git_index_remove_all(index, NULL, NULL, NULL));
+ git_str_dispose(&path);
+ git_index_free(index);
+ git__free(fn);
+}
+#endif
+
+void test_index_tests256__write_tree_invalid_unowned_index(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_index *idx;
+ git_repository *repo;
+ git_index_entry entry = {{0}};
+ git_oid tree_id;
+
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA256));
+
+ // TODO: this one is failing
+ cl_git_pass(git_oid__fromstr(&entry.id, "a8c2e0a89a9cbab77c732b6bc39b51a783e3a318a847f46cba7614cac9814291", GIT_OID_SHA256));
+ entry.path = "foo";
+ entry.mode = GIT_FILEMODE_BLOB;
+ cl_git_pass(git_index_add(idx, &entry));
+
+ cl_git_pass(git_repository_init_ext(&repo, "./invalid-id", &repo_init_opts));
+
+ cl_git_fail(git_index_write_tree_to(&tree_id, idx, repo));
+
+ git_index_free(idx);
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("invalid-id");
+#endif
+}
+
+/* Test that writing an invalid filename fails */
+void test_index_tests256__write_invalid_filename(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_repository *repo;
+
+ p_mkdir("invalid", 0700);
+
+ cl_git_pass(git_repository_init(&repo, "./invalid", 0));
+
+ assert_write_fails(repo, ".git/hello");
+ assert_write_fails(repo, ".GIT/hello");
+ assert_write_fails(repo, ".GiT/hello");
+ assert_write_fails(repo, "./.git/hello");
+ assert_write_fails(repo, "./foo");
+ assert_write_fails(repo, "./bar");
+ assert_write_fails(repo, "foo/../bar");
+
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("invalid");
+#endif
+}
+
+void test_index_tests256__honors_protect_filesystems(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_repository *repo;
+
+ p_mkdir("invalid", 0700);
+
+ cl_git_pass(git_repository_init(&repo, "./invalid", 0));
+
+ cl_repo_set_bool(repo, "core.protectHFS", true);
+ cl_repo_set_bool(repo, "core.protectNTFS", true);
+
+ assert_write_fails(repo, ".git./hello");
+ assert_write_fails(repo, ".git\xe2\x80\xad/hello");
+ assert_write_fails(repo, "git~1/hello");
+ assert_write_fails(repo, ".git\xe2\x81\xaf/hello");
+ assert_write_fails(repo, ".git::$INDEX_ALLOCATION/dummy-file");
+
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("invalid");
+#endif
+}
+
+void test_index_tests256__protectntfs_on_by_default(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_repository *repo;
+
+ p_mkdir("invalid", 0700);
+
+ cl_git_pass(git_repository_init(&repo, "./invalid", 0));
+ assert_write_fails(repo, ".git./hello");
+ assert_write_fails(repo, "git~1/hello");
+
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("invalid");
+#endif
+}
+
+void test_index_tests256__can_disable_protectntfs(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_repository *repo;
+ git_index *index;
+
+ cl_must_pass(p_mkdir("valid", 0700));
+ cl_git_rewritefile("valid/git~1", "steal the shortname");
+
+ cl_git_pass(git_repository_init(&repo, "./valid", 0));
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_repo_set_bool(repo, "core.protectNTFS", false);
+
+ cl_git_pass(git_index_add_bypath(index, "git~1"));
+
+ git_index_free(index);
+ git_repository_free(repo);
+
+ cl_fixture_cleanup("valid");
+#endif
+}
+
+void test_index_tests256__remove_entry(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_repository *repo;
+ git_index *index;
+
+ p_mkdir("index_test", 0770);
+
+ cl_git_pass(git_repository_init(&repo, "index_test", 0));
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert(git_index_entrycount(index) == 0);
+
+ cl_git_mkfile("index_test/hello", NULL);
+ cl_git_pass(git_index_add_bypath(index, "hello"));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(git_index_read(index, true)); /* reload */
+ cl_assert(git_index_entrycount(index) == 1);
+ cl_assert(git_index_get_bypath(index, "hello", 0) != NULL);
+
+ cl_git_pass(git_index_remove(index, "hello", 0));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(git_index_read(index, true)); /* reload */
+ cl_assert(git_index_entrycount(index) == 0);
+ cl_assert(git_index_get_bypath(index, "hello", 0) == NULL);
+
+ git_index_free(index);
+ git_repository_free(repo);
+ cl_fixture_cleanup("index_test");
+#endif
+}
+
+void test_index_tests256__remove_directory(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_repository *repo;
+ git_index *index;
+
+ p_mkdir("index_test", 0770);
+
+ cl_git_pass(git_repository_init(&repo, "index_test", 0));
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_assert_equal_i(0, (int)git_index_entrycount(index));
+
+ p_mkdir("index_test/a", 0770);
+ cl_git_mkfile("index_test/a/1.txt", NULL);
+ cl_git_mkfile("index_test/a/2.txt", NULL);
+ cl_git_mkfile("index_test/a/3.txt", NULL);
+ cl_git_mkfile("index_test/b.txt", NULL);
+
+ cl_git_pass(git_index_add_bypath(index, "a/1.txt"));
+ cl_git_pass(git_index_add_bypath(index, "a/2.txt"));
+ cl_git_pass(git_index_add_bypath(index, "a/3.txt"));
+ cl_git_pass(git_index_add_bypath(index, "b.txt"));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(git_index_read(index, true)); /* reload */
+ cl_assert_equal_i(4, (int)git_index_entrycount(index));
+ cl_assert(git_index_get_bypath(index, "a/1.txt", 0) != NULL);
+ cl_assert(git_index_get_bypath(index, "a/2.txt", 0) != NULL);
+ cl_assert(git_index_get_bypath(index, "b.txt", 0) != NULL);
+
+ cl_git_pass(git_index_remove(index, "a/1.txt", 0));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(git_index_read(index, true)); /* reload */
+ cl_assert_equal_i(3, (int)git_index_entrycount(index));
+ cl_assert(git_index_get_bypath(index, "a/1.txt", 0) == NULL);
+ cl_assert(git_index_get_bypath(index, "a/2.txt", 0) != NULL);
+ cl_assert(git_index_get_bypath(index, "b.txt", 0) != NULL);
+
+ cl_git_pass(git_index_remove_directory(index, "a", 0));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(git_index_read(index, true)); /* reload */
+ cl_assert_equal_i(1, (int)git_index_entrycount(index));
+ cl_assert(git_index_get_bypath(index, "a/1.txt", 0) == NULL);
+ cl_assert(git_index_get_bypath(index, "a/2.txt", 0) == NULL);
+ cl_assert(git_index_get_bypath(index, "b.txt", 0) != NULL);
+
+ git_index_free(index);
+ git_repository_free(repo);
+ cl_fixture_cleanup("index_test");
+#endif
+}
+
+void test_index_tests256__preserves_case(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_repository *repo;
+ git_index *index;
+ const git_index_entry *entry;
+ int index_caps;
+
+ cl_set_cleanup(&cleanup_myrepo, NULL);
+
+ cl_git_pass(git_repository_init_ext(&repo, "./myrepo", &repo_init_opts));
+ cl_git_pass(git_repository_index(&index, repo));
+
+ index_caps = git_index_caps(index);
+
+ cl_git_rewritefile("myrepo/test.txt", "hey there\n");
+ cl_git_pass(git_index_add_bypath(index, "test.txt"));
+
+ cl_git_pass(p_rename("myrepo/test.txt", "myrepo/TEST.txt"));
+ cl_git_rewritefile("myrepo/TEST.txt", "hello again\n");
+ cl_git_pass(git_index_add_bypath(index, "TEST.txt"));
+
+ if (index_caps & GIT_INDEX_CAPABILITY_IGNORE_CASE)
+ cl_assert_equal_i(1, (int)git_index_entrycount(index));
+ else
+ cl_assert_equal_i(2, (int)git_index_entrycount(index));
+
+ /* Test access by path instead of index */
+ cl_assert((entry = git_index_get_bypath(index, "test.txt", 0)) != NULL);
+ /* The path should *not* have changed without an explicit remove */
+ cl_assert(git__strcmp(entry->path, "test.txt") == 0);
+
+ cl_assert((entry = git_index_get_bypath(index, "TEST.txt", 0)) != NULL);
+ if (index_caps & GIT_INDEX_CAPABILITY_IGNORE_CASE)
+ /* The path should *not* have changed without an explicit remove */
+ cl_assert(git__strcmp(entry->path, "test.txt") == 0);
+ else
+ cl_assert(git__strcmp(entry->path, "TEST.txt") == 0);
+
+ git_index_free(index);
+ git_repository_free(repo);
+#endif
+}
+
+void test_index_tests256__elocked(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_repository *repo;
+ git_index *index;
+ git_filebuf file = GIT_FILEBUF_INIT;
+ const git_error *err;
+ int error;
+
+ cl_set_cleanup(&cleanup_myrepo, NULL);
+
+ cl_git_pass(git_repository_init_ext(&repo, "./myrepo", &repo_init_opts));
+ cl_git_pass(git_repository_index(&index, repo));
+
+ /* Lock the index file so we fail to lock it */
+ cl_git_pass(git_filebuf_open(&file, index->index_file_path, 0, 0666));
+ error = git_index_write(index);
+ cl_assert_equal_i(GIT_ELOCKED, error);
+
+ err = git_error_last();
+ cl_assert_equal_i(err->klass, GIT_ERROR_INDEX);
+
+ git_filebuf_cleanup(&file);
+ git_index_free(index);
+ git_repository_free(repo);
+#endif
+}
+
+void test_index_tests256__reload_from_disk(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_repository *repo;
+ git_index *read_index;
+ git_index *write_index;
+
+ cl_set_cleanup(&cleanup_myrepo, NULL);
+
+ cl_git_pass(git_futils_mkdir("./myrepo", 0777, GIT_MKDIR_PATH));
+ cl_git_mkfile("./myrepo/a.txt", "a\n");
+ cl_git_mkfile("./myrepo/b.txt", "b\n");
+
+ cl_git_pass(git_repository_init_ext(&repo, "./myrepo", &repo_init_opts));
+ cl_git_pass(git_repository_index(&write_index, repo));
+ cl_assert_equal_i(false, write_index->on_disk);
+
+ cl_git_pass(git_index__open(&read_index, write_index->index_file_path, GIT_OID_SHA256));
+ cl_assert_equal_i(false, read_index->on_disk);
+
+ /* Stage two new files against the write_index */
+ cl_git_pass(git_index_add_bypath(write_index, "a.txt"));
+ cl_git_pass(git_index_add_bypath(write_index, "b.txt"));
+
+ cl_assert_equal_sz(2, git_index_entrycount(write_index));
+
+ /* Persist the index changes to disk */
+ cl_git_pass(git_index_write(write_index));
+ cl_assert_equal_i(true, write_index->on_disk);
+
+ /* Sync the changes back into the read_index */
+ cl_assert_equal_sz(0, git_index_entrycount(read_index));
+
+ cl_git_pass(git_index_read(read_index, true));
+ cl_assert_equal_i(true, read_index->on_disk);
+
+ cl_assert_equal_sz(2, git_index_entrycount(read_index));
+
+ /* Remove the index file from the filesystem */
+ cl_git_pass(p_unlink(write_index->index_file_path));
+
+ /* Sync the changes back into the read_index */
+ cl_git_pass(git_index_read(read_index, true));
+ cl_assert_equal_i(false, read_index->on_disk);
+ cl_assert_equal_sz(0, git_index_entrycount(read_index));
+
+ git_index_free(read_index);
+ git_index_free(write_index);
+ git_repository_free(repo);
+#endif
+}
+
+void test_index_tests256__reload_while_ignoring_case(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_index *index;
+ unsigned int caps;
+
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256));
+ cl_git_pass(git_vector_verify_sorted(&index->entries));
+
+ caps = git_index_caps(index);
+ cl_git_pass(git_index_set_caps(index, caps &= ~GIT_INDEX_CAPABILITY_IGNORE_CASE));
+ cl_git_pass(git_index_read(index, true));
+ cl_git_pass(git_vector_verify_sorted(&index->entries));
+ cl_assert(git_index_get_bypath(index, "contrib/README", 0));
+ cl_assert_equal_p(NULL, git_index_get_bypath(index, "CONTRIB/readme", 0));
+
+ cl_git_pass(git_index_set_caps(index, caps | GIT_INDEX_CAPABILITY_IGNORE_CASE));
+ cl_git_pass(git_index_read(index, true));
+ cl_git_pass(git_vector_verify_sorted(&index->entries));
+ cl_assert(git_index_get_bypath(index, "contrib/README", 0));
+ cl_assert(git_index_get_bypath(index, "CONTRIB/readme", 0));
+
+ git_index_free(index);
+#endif
+}
+
+void test_index_tests256__change_icase_on_instance(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_index *index;
+ unsigned int caps;
+ const git_index_entry *e;
+
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256));
+ cl_git_pass(git_vector_verify_sorted(&index->entries));
+
+ caps = git_index_caps(index);
+ cl_git_pass(git_index_set_caps(index, caps &= ~GIT_INDEX_CAPABILITY_IGNORE_CASE));
+ cl_assert_equal_i(false, index->ignore_case);
+ cl_git_pass(git_vector_verify_sorted(&index->entries));
+ cl_assert(e = git_index_get_bypath(index, "contrib/README", 0));
+ cl_assert_equal_p(NULL, e = git_index_get_bypath(index, "CONTRIB/readme", 0));
+ cl_assert(e = git_index_get_bypath(index, "config.h", 0));
+ cl_assert_equal_p(NULL, e = git_index_get_bypath(index, "CONFIG.H", 0));
+
+ cl_git_pass(git_index_set_caps(index, caps | GIT_INDEX_CAPABILITY_IGNORE_CASE));
+ cl_assert_equal_i(true, index->ignore_case);
+ cl_git_pass(git_vector_verify_sorted(&index->entries));
+ cl_assert(e = git_index_get_bypath(index, "config.h", 0));
+ cl_assert_equal_s("config.h", e->path);
+ cl_assert(e = git_index_get_bypath(index, "CONFIG.H", 0));
+ cl_assert_equal_s("config.h", e->path);
+
+ git_index_free(index);
+#endif
+}
+
+void test_index_tests256__can_lock_index(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_repository *repo;
+ git_index *index;
+ git_indexwriter one = GIT_INDEXWRITER_INIT,
+ two = GIT_INDEXWRITER_INIT;
+
+ repo = cl_git_sandbox_init("testrepo.git");
+
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_indexwriter_init(&one, index));
+
+ cl_git_fail_with(GIT_ELOCKED, git_indexwriter_init(&two, index));
+ cl_git_fail_with(GIT_ELOCKED, git_index_write(index));
+
+ cl_git_pass(git_indexwriter_commit(&one));
+
+ cl_git_pass(git_index_write(index));
+
+ git_indexwriter_cleanup(&one);
+ git_indexwriter_cleanup(&two);
+ git_index_free(index);
+ cl_git_sandbox_cleanup();
+#endif
+}
+
+void test_index_tests256__can_iterate(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_index *index;
+ git_index_iterator *iterator;
+ const git_index_entry *entry;
+ size_t i, iterator_idx = 0, found = 0;
+ int ret;
+
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256));
+ cl_git_pass(git_index_iterator_new(&iterator, index));
+
+ cl_assert(git_vector_is_sorted(&iterator->snap));
+
+ for (i = 0; i < ARRAY_SIZE(test_entries); i++) {
+ /* Advance iterator to next test entry index */
+ do {
+ ret = git_index_iterator_next(&entry, iterator);
+
+ if (ret == GIT_ITEROVER)
+ cl_fail("iterator did not contain all test entries");
+
+ cl_git_pass(ret);
+ } while (iterator_idx++ < test_entries[i].index);
+
+ cl_assert_equal_s(entry->path, test_entries[i].path);
+ cl_assert_equal_i(entry->mtime.seconds, test_entries[i].mtime);
+ cl_assert_equal_i(entry->file_size, test_entries[i].file_size);
+ found++;
+ }
+
+ while ((ret = git_index_iterator_next(&entry, iterator)) == 0)
+ ;
+
+ if (ret != GIT_ITEROVER)
+ cl_git_fail(ret);
+
+ cl_assert_equal_i(found, ARRAY_SIZE(test_entries));
+
+ git_index_iterator_free(iterator);
+ git_index_free(index);
+#endif
+}
+
+void test_index_tests256__can_modify_while_iterating(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_index *index;
+ git_index_iterator *iterator;
+ const git_index_entry *entry;
+ git_index_entry new_entry = {{0}};
+ size_t expected = 0, seen = 0;
+ int ret;
+
+ cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA256));
+ cl_git_pass(git_index_iterator_new(&iterator, index));
+
+ expected = git_index_entrycount(index);
+ cl_assert(git_vector_is_sorted(&iterator->snap));
+
+ /*
+ * After we've counted the entries, add a new one and change another;
+ * ensure that our iterator is backed by a snapshot and thus returns
+ * the number of entries from when the iterator was created.
+ */
+ cl_git_pass(git_oid__fromstr(&new_entry.id, "8312e0a89a9cbab77c732b6bc39b51a783e3a318a847f46cba7614cac9814291", GIT_OID_SHA256));
+ new_entry.path = "newfile";
+ new_entry.mode = GIT_FILEMODE_BLOB;
+ cl_git_pass(git_index_add(index, &new_entry));
+
+ cl_git_pass(git_oid__fromstr(&new_entry.id, "4141414141414141414141414141414141414141414141414141414141414141", GIT_OID_SHA256));
+ new_entry.path = "Makefile";
+ new_entry.mode = GIT_FILEMODE_BLOB;
+ cl_git_pass(git_index_add(index, &new_entry));
+
+ while (true) {
+ ret = git_index_iterator_next(&entry, iterator);
+
+ if (ret == GIT_ITEROVER)
+ break;
+
+ seen++;
+ }
+
+ cl_assert_equal_i(expected, seen);
+
+ git_index_iterator_free(iterator);
+ git_index_free(index);
+#endif
+}
diff --git a/tests/libgit2/object/tree/update.c b/tests/libgit2/object/tree/update.c
index 1861ac838..1e82bdcd6 100644
--- a/tests/libgit2/object/tree/update.c
+++ b/tests/libgit2/object/tree/update.c
@@ -1,5 +1,6 @@
#include "clar_libgit2.h"
#include "tree.h"
+#include "index.h"
static git_repository *g_repo;
@@ -28,7 +29,7 @@ void test_object_tree_update__remove_blob(void)
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
/* Create it with an index */
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(idx, base_tree));
cl_git_pass(git_index_remove(idx, path, 0));
cl_git_pass(git_index_write_tree_to(&tree_index_id, idx, g_repo));
@@ -57,7 +58,7 @@ void test_object_tree_update__remove_blob_deeper(void)
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
/* Create it with an index */
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(idx, base_tree));
cl_git_pass(git_index_remove(idx, path, 0));
cl_git_pass(git_index_write_tree_to(&tree_index_id, idx, g_repo));
@@ -88,7 +89,7 @@ void test_object_tree_update__remove_all_entries(void)
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
/* Create it with an index */
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(idx, base_tree));
cl_git_pass(git_index_remove(idx, path1, 0));
cl_git_pass(git_index_remove(idx, path2, 0));
@@ -119,7 +120,7 @@ void test_object_tree_update__replace_blob(void)
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
/* Create it with an index */
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(idx, base_tree));
entry.path = path;
@@ -171,7 +172,7 @@ void test_object_tree_update__add_blobs(void)
int j;
/* Create it with an index */
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
base_tree = NULL;
if (i == 1) {
@@ -228,7 +229,7 @@ void test_object_tree_update__add_blobs_unsorted(void)
int j;
/* Create it with an index */
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
base_tree = NULL;
if (i == 1) {
diff --git a/tests/libgit2/online/clone.c b/tests/libgit2/online/clone.c
index 1a4cdb520..b635739b6 100644
--- a/tests/libgit2/online/clone.c
+++ b/tests/libgit2/online/clone.c
@@ -580,6 +580,17 @@ static int succeed_certificate_check(git_cert *cert, int valid, const char *host
return 0;
}
+static int x509_succeed_certificate_check(git_cert *cert, int valid, const char *host, void *payload)
+{
+ GIT_UNUSED(valid);
+ GIT_UNUSED(payload);
+
+ cl_assert_equal_s("github.com", host);
+ cl_assert_equal_i(GIT_CERT_X509, cert->cert_type);
+
+ return 0;
+}
+
static int fail_certificate_check(git_cert *cert, int valid, const char *host, void *payload)
{
GIT_UNUSED(cert);
@@ -901,7 +912,7 @@ void test_online_clone__certificate_invalid(void)
void test_online_clone__certificate_valid(void)
{
- g_options.fetch_opts.callbacks.certificate_check = succeed_certificate_check;
+ g_options.fetch_opts.callbacks.certificate_check = x509_succeed_certificate_check;
cl_git_pass(git_clone(&g_repo, "https://github.com/libgit2/TestGitRepository", "./foo", &g_options));
}
diff --git a/tests/libgit2/pack/midx.c b/tests/libgit2/pack/midx.c
index f7d680165..4c4dfc511 100644
--- a/tests/libgit2/pack/midx.c
+++ b/tests/libgit2/pack/midx.c
@@ -16,7 +16,7 @@ void test_pack_midx__parse(void)
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_str_joinpath(&midx_path, git_repository_path(repo), "objects/pack/multi-pack-index"));
- cl_git_pass(git_midx_open(&idx, git_str_cstr(&midx_path)));
+ cl_git_pass(git_midx_open(&idx, git_str_cstr(&midx_path), GIT_OID_SHA1));
cl_assert_equal_i(git_midx_needs_refresh(idx, git_str_cstr(&midx_path)), 0);
cl_git_pass(git_oid__fromstr(&id, "5001298e0c09ad9c34e4249bc5801c75e9754fa5", GIT_OID_SHA1));
@@ -57,7 +57,12 @@ void test_pack_midx__writer(void)
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_str_joinpath(&path, git_repository_path(repo), "objects/pack"));
+
+#ifdef GIT_EXPERIMENTAL_SHA256
+ cl_git_pass(git_midx_writer_new(&w, git_str_cstr(&path), GIT_OID_SHA1));
+#else
cl_git_pass(git_midx_writer_new(&w, git_str_cstr(&path)));
+#endif
cl_git_pass(git_midx_writer_add(w, "pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx"));
cl_git_pass(git_midx_writer_add(w, "pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx"));
diff --git a/tests/libgit2/repo/discover.c b/tests/libgit2/repo/discover.c
index 523fdf8e3..983d75e3a 100644
--- a/tests/libgit2/repo/discover.c
+++ b/tests/libgit2/repo/discover.c
@@ -122,7 +122,10 @@ void test_repo_discover__cleanup(void)
void test_repo_discover__discovering_repo_with_exact_path_succeeds(void)
{
cl_git_pass(git_repository_discover(&discovered, DISCOVER_FOLDER, 0, ceiling_dirs.ptr));
+ git_buf_dispose(&discovered);
+
cl_git_pass(git_repository_discover(&discovered, SUB_REPOSITORY_FOLDER, 0, ceiling_dirs.ptr));
+ git_buf_dispose(&discovered);
}
void test_repo_discover__discovering_nonexistent_dir_fails(void)
diff --git a/tests/libgit2/repo/env.c b/tests/libgit2/repo/env.c
index 790ffd40f..0e6cc59d5 100644
--- a/tests/libgit2/repo/env.c
+++ b/tests/libgit2/repo/env.c
@@ -31,6 +31,10 @@ void test_repo_env__cleanup(void)
if (git_fs_path_isdir("peeled.git"))
git_futils_rmdir_r("peeled.git", NULL, GIT_RMDIR_REMOVE_FILES);
+ cl_fixture_cleanup("test_workdir");
+ cl_fixture_cleanup("test_global_conf");
+ cl_fixture_cleanup("test_system_conf");
+
clear_git_env();
}
@@ -275,3 +279,91 @@ void test_repo_env__open(void)
clear_git_env();
}
+
+void test_repo_env__work_tree(void)
+{
+ git_repository *repo;
+ const char *test_path;
+
+ cl_fixture_sandbox("attr");
+ cl_git_pass(p_rename("attr/.gitted", "attr/.git"));
+
+ cl_must_pass(p_mkdir("test_workdir", 0777));
+ test_path = cl_git_sandbox_path(1, "test_workdir", NULL);
+
+ cl_setenv("GIT_WORK_TREE", test_path);
+ cl_git_pass(git_repository_open_ext(&repo, "attr", GIT_REPOSITORY_OPEN_FROM_ENV, NULL));
+ cl_assert_equal_s(test_path, git_repository_workdir(repo));
+ git_repository_free(repo);
+ cl_setenv("GIT_WORK_TREE", NULL);
+}
+
+void test_repo_env__commondir(void)
+{
+ git_repository *repo;
+ const char *test_path;
+
+ cl_fixture_sandbox("attr");
+ cl_git_pass(p_rename("attr/.gitted", "attr/.git"));
+
+ cl_fixture_sandbox("testrepo.git");
+ cl_git_pass(p_rename("testrepo.git", "test_commondir"));
+
+ test_path = cl_git_sandbox_path(1, "test_commondir", NULL);
+
+ cl_setenv("GIT_COMMON_DIR", test_path);
+ cl_git_pass(git_repository_open_ext(&repo, "attr", GIT_REPOSITORY_OPEN_FROM_ENV, NULL));
+ cl_assert_equal_s(test_path, git_repository_commondir(repo));
+ git_repository_free(repo);
+ cl_setenv("GIT_COMMON_DIR", NULL);
+}
+
+void test_repo_env__config(void)
+{
+ git_repository *repo;
+ git_config *config;
+ const char *system_path, *global_path;
+ int s, g;
+
+ cl_fixture_sandbox("attr");
+ cl_git_pass(p_rename("attr/.gitted", "attr/.git"));
+
+ cl_git_rewritefile("test_system_conf", "[tttest]\n\tsys = true\n");
+ cl_git_rewritefile("test_global_conf", "[tttest]\n\tglb = true\n");
+
+ system_path = cl_git_sandbox_path(0, "test_system_conf", NULL);
+ cl_setenv("GIT_CONFIG_SYSTEM", system_path);
+
+ global_path = cl_git_sandbox_path(0, "test_global_conf", NULL);
+ cl_setenv("GIT_CONFIG_GLOBAL", global_path);
+
+ /* Ensure we can override the system and global files */
+
+ cl_git_pass(git_repository_open_ext(&repo, "attr", GIT_REPOSITORY_OPEN_FROM_ENV, NULL));
+ cl_git_pass(git_repository_config(&config, repo));
+
+ cl_git_pass(git_config_get_bool(&s, config, "tttest.sys"));
+ cl_assert_equal_i(1, s);
+ cl_git_pass(git_config_get_bool(&g, config, "tttest.glb"));
+ cl_assert_equal_i(1, g);
+
+ git_config_free(config);
+ git_repository_free(repo);
+
+ /* Further ensure we can ignore the system file. */
+ cl_setenv("GIT_CONFIG_NOSYSTEM", "TrUe");
+
+ cl_git_pass(git_repository_open_ext(&repo, "attr", GIT_REPOSITORY_OPEN_FROM_ENV, NULL));
+ cl_git_pass(git_repository_config(&config, repo));
+
+ cl_git_fail_with(GIT_ENOTFOUND, git_config_get_bool(&s, config, "tttest.sys"));
+ cl_git_pass(git_config_get_bool(&g, config, "tttest.glb"));
+ cl_assert_equal_i(1, g);
+
+ git_config_free(config);
+ git_repository_free(repo);
+
+ cl_setenv("GIT_CONFIG_NOSYSTEM", NULL);
+ cl_setenv("GIT_CONFIG_SYSTEM", NULL);
+ cl_setenv("GIT_CONFIG_GLOBAL", NULL);
+}
diff --git a/tests/libgit2/repo/setters.c b/tests/libgit2/repo/setters.c
index 66ec7706c..5c91ed390 100644
--- a/tests/libgit2/repo/setters.c
+++ b/tests/libgit2/repo/setters.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "git2/sys/repository.h"
+#include "index.h"
#include "odb.h"
#include "posix.h"
#include "util.h"
@@ -70,7 +71,7 @@ void test_repo_setters__setting_a_new_index_on_a_repo_which_has_already_loaded_o
{
git_index *new_index;
- cl_git_pass(git_index_open(&new_index, "./my-index"));
+ cl_git_pass(git_index__open(&new_index, "./my-index", GIT_OID_SHA1));
cl_assert(((git_refcount *)new_index)->refcount.val == 1);
git_repository_set_index(repo, new_index);
diff --git a/tests/libgit2/reset/hard.c b/tests/libgit2/reset/hard.c
index 0b6342cb2..06a8a049a 100644
--- a/tests/libgit2/reset/hard.c
+++ b/tests/libgit2/reset/hard.c
@@ -3,6 +3,7 @@
#include "reset_helpers.h"
#include "path.h"
#include "futils.h"
+#include "index.h"
static git_repository *repo;
static git_object *target;
@@ -252,7 +253,7 @@ void test_reset_hard__switch_file_to_dir(void)
git_odb_free(odb);
entry.mode = GIT_FILEMODE_BLOB;
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_signature_now(&sig, "foo", "bar"));
/* Create the old tree */
diff --git a/tests/libgit2/status/worktree_init.c b/tests/libgit2/status/worktree_init.c
index 40f1b2a31..db6e71f12 100644
--- a/tests/libgit2/status/worktree_init.c
+++ b/tests/libgit2/status/worktree_init.c
@@ -7,6 +7,7 @@
#include "posix.h"
#include "util.h"
#include "path.h"
+#include "index.h"
static void cleanup_new_repo(void *path)
{
@@ -65,7 +66,7 @@ void test_status_worktree_init__status_file_without_index_or_workdir(void)
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_repository_set_workdir(repo, "wd", false));
- cl_git_pass(git_index_open(&index, "empty-index"));
+ cl_git_pass(git_index__open(&index, "empty-index", GIT_OID_SHA1));
cl_assert_equal_i(0, (int)git_index_entrycount(index));
git_repository_set_index(repo, index);
@@ -106,7 +107,7 @@ void test_status_worktree_init__status_file_with_clean_index_and_empty_workdir(v
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_repository_set_workdir(repo, "wd", false));
- cl_git_pass(git_index_open(&index, "my-index"));
+ cl_git_pass(git_index__open(&index, "my-index", GIT_OID_SHA1));
fill_index_wth_head_entries(repo, index);
git_repository_set_index(repo, index);
@@ -283,7 +284,7 @@ void test_status_worktree_init__disable_pathspec_match(void)
{
git_repository *repo;
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
- char *file_with_bracket = "LICENSE[1].md",
+ char *file_with_bracket = "LICENSE[1].md",
*imaginary_file_with_bracket = "LICENSE[1-2].md";
cl_set_cleanup(&cleanup_new_repo, "pathspec");
@@ -291,18 +292,18 @@ void test_status_worktree_init__disable_pathspec_match(void)
cl_git_mkfile("pathspec/LICENSE[1].md", "screaming bracket\n");
cl_git_mkfile("pathspec/LICENSE1.md", "no bracket\n");
- opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH;
opts.pathspec.count = 1;
opts.pathspec.strings = &file_with_bracket;
cl_git_pass(
- git_status_foreach_ext(repo, &opts, cb_status__expected_path,
+ git_status_foreach_ext(repo, &opts, cb_status__expected_path,
file_with_bracket)
);
/* Test passing a pathspec matching files in the workdir. */
- /* Must not match because pathspecs are disabled. */
+ /* Must not match because pathspecs are disabled. */
opts.pathspec.strings = &imaginary_file_with_bracket;
cl_git_pass(
git_status_foreach_ext(repo, &opts, cb_status__expected_path, NULL)
diff --git a/tests/libgit2/stream/registration.c b/tests/libgit2/stream/registration.c
index bf3c20502..ccaecee8c 100644
--- a/tests/libgit2/stream/registration.c
+++ b/tests/libgit2/stream/registration.c
@@ -81,10 +81,10 @@ void test_stream_registration__tls(void)
cl_git_pass(git_stream_register(GIT_STREAM_TLS, NULL));
error = git_tls_stream_new(&stream, "localhost", "443");
- /* We don't have TLS support enabled, or we're on Windows,
- * which has no arbitrary TLS stream support.
+ /* We don't have TLS support enabled, or we're on Windows
+ * with WinHTTP, which is not actually TLS stream support.
*/
-#if defined(GIT_WIN32) || !defined(GIT_HTTPS)
+#if defined(GIT_WINHTTP) || !defined(GIT_HTTPS)
cl_git_fail_with(-1, error);
#else
cl_git_pass(error);
diff --git a/tests/libgit2/submodule/lookup.c b/tests/libgit2/submodule/lookup.c
index acfdc838c..febb7dfad 100644
--- a/tests/libgit2/submodule/lookup.c
+++ b/tests/libgit2/submodule/lookup.c
@@ -3,6 +3,7 @@
#include "git2/sys/repository.h"
#include "repository.h"
#include "futils.h"
+#include "index.h"
static git_repository *g_repo = NULL;
@@ -210,7 +211,7 @@ void test_submodule_lookup__lookup_even_with_missing_index(void)
git_index *idx;
/* give the repo an empty index */
- cl_git_pass(git_index_new(&idx));
+ cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
git_repository_set_index(g_repo, idx);
git_index_free(idx);