Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tests/clar/clar_libgit2.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,26 @@ void cl_repo_set_string(git_repository *repo, const char *cfg, const char *value
git_config_free(config);
}

int cl_repo_has_ref_format(git_repository *repo, const char *format)
{
const char *configured_format;
git_config *config;
int result;

cl_git_pass(git_repository_config_snapshot(&config, repo));
result = git_config_get_string(&configured_format, config,
"extensions.refStorage");
if (result < 0 && result != GIT_ENOTFOUND)
cl_fail("cannot read extensions.refStorage");
if (result < 0)
configured_format = "files";

result = !strcmp(configured_format, format);

git_config_free(config);
return result;
}

/* this is essentially the code from git__unescape modified slightly */
static size_t strip_cr_from_buf(char *start, size_t len)
{
Expand Down
2 changes: 2 additions & 0 deletions tests/clar/clar_libgit2.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ int cl_repo_get_int(git_repository *repo, const char *cfg);

void cl_repo_set_string(git_repository *repo, const char *cfg, const char *value);

int cl_repo_has_ref_format(git_repository *repo, const char *format);

/*
* set up a fake "home" directory -- automatically configures cleanup
* function to restore the home directory, although you can call it
Expand Down
8 changes: 6 additions & 2 deletions tests/libgit2/cherrypick/workdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void test_cherrypick_workdir__automerge(void)
git_commit *head = NULL, *commit = NULL;
git_oid cherry_oid, cherrypicked_oid, cherrypicked_tree_oid;
git_tree *cherrypicked_tree = NULL;
git_reference *ref;

cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL));
Expand All @@ -71,7 +72,7 @@ void test_cherrypick_workdir__automerge(void)
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
cl_git_pass(git_cherrypick(repo, commit, NULL));

cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
cl_git_pass(git_reference_lookup(&ref, repo, "CHERRY_PICK_HEAD"));
cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));

cl_git_pass(git_index_write_tree(&cherrypicked_tree_oid, repo_index));
Expand All @@ -84,6 +85,7 @@ void test_cherrypick_workdir__automerge(void)
git_oid_cpy(&head_oid, &cherrypicked_oid);

git_tree_free(cherrypicked_tree);
git_reference_free(ref);
git_commit_free(head);
git_commit_free(commit);
}
Expand Down Expand Up @@ -140,6 +142,7 @@ void test_cherrypick_workdir__conflicts(void)
git_commit *head = NULL, *commit = NULL;
git_oid head_oid, cherry_oid;
git_str conflicting_buf = GIT_STR_INIT, mergemsg_buf = GIT_STR_INIT;
git_reference *ref;

struct merge_index_entry merge_index_entries[] = {
{ 0100644, "242e7977ba73637822ffb265b46004b9b0e5153b", 0, "file1.txt" },
Expand All @@ -160,7 +163,7 @@ void test_cherrypick_workdir__conflicts(void)
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
cl_git_pass(git_cherrypick(repo, commit, NULL));

cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
cl_git_pass(git_reference_lookup(&ref, repo, "CHERRY_PICK_HEAD"));
cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));

cl_assert(merge_test_index(repo_index, merge_index_entries, 7));
Expand Down Expand Up @@ -225,6 +228,7 @@ void test_cherrypick_workdir__conflicts(void)
"File 3!\n" \
">>>>>>> e9b63f3... Change all files\n") == 0);

git_reference_free(ref);
git_commit_free(commit);
git_commit_free(head);
git_str_dispose(&mergemsg_buf);
Expand Down
17 changes: 11 additions & 6 deletions tests/libgit2/config/conditionals.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ void test_config_conditionals__cleanup(void)
static void assert_condition_includes(const char *keyword, const char *path, bool expected)
{
git_buf value = GIT_BUF_INIT;
git_str key = GIT_STR_INIT;
git_str buf = GIT_STR_INIT;
git_config *cfg;

cl_git_pass(git_str_printf(&buf, "[includeIf \"%s:%s\"]\n", keyword, path));
cl_git_pass(git_str_puts(&buf, "path = other\n"));
cl_git_pass(git_repository_config(&cfg, _repo));
cl_git_pass(git_str_printf(&key, "includeIf.%s:%s.path", keyword, path));
cl_git_pass(git_config_set_string(cfg, key.ptr, "other"));
git_config_free(cfg);

cl_git_mkfile("empty_standard_repo/.git/config", buf.ptr);
cl_git_mkfile("empty_standard_repo/.git/other", "[foo]\nbar=baz\n");
_repo = cl_git_sandbox_reopen();

Expand All @@ -45,6 +47,9 @@ static void assert_condition_includes(const char *keyword, const char *path, boo
git_config_get_string_buf(&value, cfg, "foo.bar"));
}

cl_git_pass(git_config_delete_entry(cfg, key.ptr));

git_str_dispose(&key);
git_str_dispose(&buf);
git_buf_dispose(&value);
git_config_free(cfg);
Expand Down Expand Up @@ -155,10 +160,10 @@ void test_config_conditionals__empty(void)
git_str buf = GIT_STR_INIT;
git_config *cfg;

cl_git_pass(git_str_puts(&buf, "[includeIf]\n"));
cl_git_pass(git_str_puts(&buf, "path = other\n"));
cl_git_pass(git_repository_config(&cfg, _repo));
cl_git_pass(git_config_set_string(cfg, "includeIf.path", "other"));
git_config_free(cfg);

cl_git_mkfile("empty_standard_repo/.git/config", buf.ptr);
cl_git_mkfile("empty_standard_repo/.git/other", "[foo]\nbar=baz\n");
_repo = cl_git_sandbox_reopen();

Expand Down
6 changes: 1 addition & 5 deletions tests/libgit2/merge/analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,11 @@ void test_merge_analysis__unborn(void)
{
git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref;
git_str master = GIT_STR_INIT;

cl_git_pass(git_str_joinpath(&master, git_repository_path(repo), "refs/heads/master"));
cl_must_pass(p_unlink(git_str_cstr(&master)));
cl_git_pass(git_reference_remove(repo, "refs/heads/master"));

analysis_from_branch(&merge_analysis, &merge_pref, NULL, NOFASTFORWARD_BRANCH);
cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD|GIT_MERGE_ANALYSIS_UNBORN, merge_analysis);

git_str_dispose(&master);
}

void test_merge_analysis__fastforward_with_config_noff(void)
Expand Down
44 changes: 7 additions & 37 deletions tests/libgit2/merge/workdir/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,45 +462,15 @@ void test_merge_workdir_setup__three_same_oids(void)

static int create_remote_tracking_branch(const char *branch_name, const char *oid_str)
{
int error = 0;
git_str refname = GIT_STR_INIT;
git_oid oid;

git_str remotes_path = GIT_STR_INIT,
origin_path = GIT_STR_INIT,
filename = GIT_STR_INIT,
data = GIT_STR_INIT;
cl_git_pass(git_oid_from_string(&oid, oid_str, GIT_OID_SHA1));
cl_git_pass(git_str_printf(&refname, GIT_REFS_REMOTES_DIR "origin/%s", branch_name));
cl_git_pass(git_reference_create(NULL, repo, refname.ptr, &oid, 0, NULL));

if ((error = git_str_puts(&remotes_path, git_repository_path(repo))) < 0 ||
(error = git_str_puts(&remotes_path, GIT_REFS_REMOTES_DIR)) < 0)
goto done;

if (!git_fs_path_exists(git_str_cstr(&remotes_path)) &&
(error = p_mkdir(git_str_cstr(&remotes_path), 0777)) < 0)
goto done;

if ((error = git_str_puts(&origin_path, git_str_cstr(&remotes_path))) < 0 ||
(error = git_str_puts(&origin_path, "origin")) < 0)
goto done;

if (!git_fs_path_exists(git_str_cstr(&origin_path)) &&
(error = p_mkdir(git_str_cstr(&origin_path), 0777)) < 0)
goto done;

if ((error = git_str_puts(&filename, git_str_cstr(&origin_path))) < 0 ||
(error = git_str_puts(&filename, "/")) < 0 ||
(error = git_str_puts(&filename, branch_name)) < 0 ||
(error = git_str_puts(&data, oid_str)) < 0 ||
(error = git_str_puts(&data, "\n")) < 0)
goto done;

cl_git_rewritefile(git_str_cstr(&filename), git_str_cstr(&data));

done:
git_str_dispose(&remotes_path);
git_str_dispose(&origin_path);
git_str_dispose(&filename);
git_str_dispose(&data);

return error;
git_str_dispose(&refname);
return 0;
}

/* git merge refs/remotes/origin/octo1 */
Expand Down
32 changes: 22 additions & 10 deletions tests/libgit2/rebase/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ void test_rebase_setup__cleanup(void)
cl_git_sandbox_cleanup();
}

static void cl_assert_equal_ref(const char *oid_str, const char *refname)
{
git_reference *ref;
git_oid oid;

cl_git_pass(git_oid_from_string(&oid, oid_str, GIT_OID_SHA1));
cl_git_pass(git_reference_lookup(&ref, repo, refname));
cl_assert_equal_oid(&oid, git_reference_target(ref));

git_reference_free(ref);
}

/* git checkout beef ; git rebase --merge master
* git checkout beef ; git rebase --merge master */
void test_rebase_setup__blocked_when_in_progress(void)
Expand Down Expand Up @@ -79,7 +91,7 @@ void test_rebase_setup__merge(void)
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));

cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_ref("b146bd7608eac53d9bf9e1a6963543588b555c64", "ORIG_HEAD");

cl_assert_equal_file("da9c51a23d02d931a486f45ad18cda05cf5d2b94\n", 41, "rebase/.git/rebase-merge/cmt.1");
cl_assert_equal_file("8d1f13f93c4995760ac07d129246ac1ff64c0be9\n", 41, "rebase/.git/rebase-merge/cmt.2");
Expand Down Expand Up @@ -125,7 +137,7 @@ void test_rebase_setup__merge_root(void)
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));

cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_ref("b146bd7608eac53d9bf9e1a6963543588b555c64", "ORIG_HEAD");

cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));

Expand Down Expand Up @@ -175,7 +187,7 @@ void test_rebase_setup__merge_onto_and_upstream(void)
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));

cl_assert_equal_file("d616d97082eb7bb2dc6f180a7cca940993b7a56f\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_ref("d616d97082eb7bb2dc6f180a7cca940993b7a56f", "ORIG_HEAD");

cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));

Expand Down Expand Up @@ -229,7 +241,7 @@ void test_rebase_setup__merge_onto_upstream_and_branch(void)
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));

cl_assert_equal_file("f87d14a4a236582a0278a916340a793714256864\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_ref("f87d14a4a236582a0278a916340a793714256864", "ORIG_HEAD");

cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));

Expand Down Expand Up @@ -287,7 +299,7 @@ void test_rebase_setup__merge_onto_upstream_and_branch_by_id(void)
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));

cl_assert_equal_file("d616d97082eb7bb2dc6f180a7cca940993b7a56f\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_ref("d616d97082eb7bb2dc6f180a7cca940993b7a56f", "ORIG_HEAD");

cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));

Expand Down Expand Up @@ -333,7 +345,7 @@ void test_rebase_setup__branch_with_merges(void)
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));

cl_assert_equal_file("f87d14a4a236582a0278a916340a793714256864\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_ref("f87d14a4a236582a0278a916340a793714256864", "ORIG_HEAD");

cl_assert_equal_file("4bed71df7017283cac61bbf726197ad6a5a18b84\n", 41, "rebase/.git/rebase-merge/cmt.1");
cl_assert_equal_file("2aa3ce842094e08ebac152b3d6d5b0fff39f9c6e\n", 41, "rebase/.git/rebase-merge/cmt.2");
Expand Down Expand Up @@ -381,7 +393,7 @@ void test_rebase_setup__orphan_branch(void)
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));

cl_assert_equal_file("12c084412b952396962eb420716df01022b847cc\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_ref("12c084412b952396962eb420716df01022b847cc", "ORIG_HEAD");

cl_assert_equal_file("aa4c42aecdfc7cd989bbc3209934ea7cda3f4d88\n", 41, "rebase/.git/rebase-merge/cmt.1");
cl_assert_equal_file("e4f809f826c1a9fc929874bc0e4644dd2f2a1af4\n", 41, "rebase/.git/rebase-merge/cmt.2");
Expand Down Expand Up @@ -432,7 +444,7 @@ void test_rebase_setup__merge_null_branch_uses_HEAD(void)
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));

cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_ref("b146bd7608eac53d9bf9e1a6963543588b555c64", "ORIG_HEAD");

cl_assert_equal_file("da9c51a23d02d931a486f45ad18cda05cf5d2b94\n", 41, "rebase/.git/rebase-merge/cmt.1");
cl_assert_equal_file("8d1f13f93c4995760ac07d129246ac1ff64c0be9\n", 41, "rebase/.git/rebase-merge/cmt.2");
Expand Down Expand Up @@ -479,7 +491,7 @@ void test_rebase_setup__merge_from_detached(void)
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));

cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_ref("b146bd7608eac53d9bf9e1a6963543588b555c64", "ORIG_HEAD");

cl_assert_equal_file("da9c51a23d02d931a486f45ad18cda05cf5d2b94\n", 41, "rebase/.git/rebase-merge/cmt.1");
cl_assert_equal_file("8d1f13f93c4995760ac07d129246ac1ff64c0be9\n", 41, "rebase/.git/rebase-merge/cmt.2");
Expand Down Expand Up @@ -527,7 +539,7 @@ void test_rebase_setup__merge_branch_by_id(void)
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));

cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_ref("b146bd7608eac53d9bf9e1a6963543588b555c64", "ORIG_HEAD");

cl_assert_equal_file("da9c51a23d02d931a486f45ad18cda05cf5d2b94\n", 41, "rebase/.git/rebase-merge/cmt.1");
cl_assert_equal_file("8d1f13f93c4995760ac07d129246ac1ff64c0be9\n", 41, "rebase/.git/rebase-merge/cmt.2");
Expand Down
3 changes: 3 additions & 0 deletions tests/libgit2/refs/branches/delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ void test_refs_branches_delete__removes_empty_folders(void)
git_str ref_folder = GIT_STR_INIT;
git_str reflog_folder = GIT_STR_INIT;

if (!cl_repo_has_ref_format(repo, "files"))
cl_skip();

/* Create a new branch with a nested name */
cl_git_pass(git_oid_from_string(&commit_id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1));
cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
Expand Down
21 changes: 16 additions & 5 deletions tests/libgit2/refs/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ void test_refs_create__symbolic(void)
/* Ensure the reference can be looked-up... */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head_tracker));
cl_assert(git_reference_type(looked_up_ref) & GIT_REFERENCE_SYMBOLIC);
cl_assert(reference_is_packed(looked_up_ref) == 0);
if (cl_repo_has_ref_format(g_repo, "files"))
cl_assert(reference_is_packed(looked_up_ref) == 0);
cl_assert_equal_s(looked_up_ref->name, new_head_tracker);

/* ...peeled.. */
Expand Down Expand Up @@ -92,7 +93,8 @@ void test_refs_create__symbolic_with_arbitrary_content(void)
/* Ensure the reference can be looked-up... */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head_tracker));
cl_assert(git_reference_type(looked_up_ref) & GIT_REFERENCE_SYMBOLIC);
cl_assert(reference_is_packed(looked_up_ref) == 0);
if (cl_repo_has_ref_format(g_repo, "files"))
cl_assert(reference_is_packed(looked_up_ref) == 0);
cl_assert_equal_s(looked_up_ref->name, new_head_tracker);
git_reference_free(looked_up_ref);

Expand All @@ -105,7 +107,8 @@ void test_refs_create__symbolic_with_arbitrary_content(void)
/* Ensure the reference can be looked-up... */
cl_git_pass(git_reference_lookup(&looked_up_ref, repo2, new_head_tracker));
cl_assert(git_reference_type(looked_up_ref) & GIT_REFERENCE_SYMBOLIC);
cl_assert(reference_is_packed(looked_up_ref) == 0);
if (cl_repo_has_ref_format(g_repo, "files"))
cl_assert(reference_is_packed(looked_up_ref) == 0);
cl_assert_equal_s(looked_up_ref->name, new_head_tracker);

/* Ensure the target is what we expect it to be */
Expand Down Expand Up @@ -153,7 +156,8 @@ void test_refs_create__oid(void)
/* Ensure the reference can be looked-up... */
cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head));
cl_assert(git_reference_type(looked_up_ref) & GIT_REFERENCE_DIRECT);
cl_assert(reference_is_packed(looked_up_ref) == 0);
if (cl_repo_has_ref_format(g_repo, "files"))
cl_assert(reference_is_packed(looked_up_ref) == 0);
cl_assert_equal_s(looked_up_ref->name, new_head);

/* ...and that it points to the current master tip */
Expand Down Expand Up @@ -332,8 +336,9 @@ static void count_fsyncs(size_t *create_count, size_t *compress_count)
void test_refs_create__does_not_fsync_by_default(void)
{
size_t create_count, compress_count;
if (!cl_repo_has_ref_format(g_repo, "files"))
cl_skip();
count_fsyncs(&create_count, &compress_count);

cl_assert_equal_i(0, create_count);
cl_assert_equal_i(0, compress_count);
}
Expand All @@ -342,6 +347,9 @@ void test_refs_create__fsyncs_when_global_opt_set(void)
{
size_t create_count, compress_count;

if (!cl_repo_has_ref_format(g_repo, "files"))
cl_skip();

cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_FSYNC_GITDIR, 1));
count_fsyncs(&create_count, &compress_count);

Expand All @@ -353,6 +361,9 @@ void test_refs_create__fsyncs_when_repo_config_set(void)
{
size_t create_count, compress_count;

if (!cl_repo_has_ref_format(g_repo, "files"))
cl_skip();

cl_repo_set_bool(g_repo, "core.fsyncObjectFiles", true);

count_fsyncs(&create_count, &compress_count);
Expand Down
Loading
Loading