Unnamed: 0
int64 0
0
| repo_id
stringlengths 5
186
| file_path
stringlengths 15
223
| content
stringlengths 1
32.8M
⌀ |
---|---|---|---|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs/branches/upstream.c
|
#include "clar_libgit2.h"
#include "config/config_helpers.h"
#include "refs.h"
static git_repository *repo;
static git_reference *branch, *upstream;
void test_refs_branches_upstream__initialize(void)
{
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
branch = NULL;
upstream = NULL;
}
void test_refs_branches_upstream__cleanup(void)
{
git_reference_free(upstream);
git_reference_free(branch);
branch = NULL;
git_repository_free(repo);
repo = NULL;
}
void test_refs_branches_upstream__can_retrieve_the_remote_tracking_reference_of_a_local_branch(void)
{
cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
cl_git_pass(git_branch_upstream(&upstream, branch));
cl_assert_equal_s("refs/remotes/test/master", git_reference_name(upstream));
}
void test_refs_branches_upstream__can_retrieve_the_local_upstream_reference_of_a_local_branch(void)
{
cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/track-local"));
cl_git_pass(git_branch_upstream(&upstream, branch));
cl_assert_equal_s("refs/heads/master", git_reference_name(upstream));
}
void test_refs_branches_upstream__cannot_retrieve_a_remote_upstream_reference_from_a_non_branch(void)
{
cl_git_pass(git_reference_lookup(&branch, repo, "refs/tags/e90810b"));
cl_git_fail(git_branch_upstream(&upstream, branch));
}
void test_refs_branches_upstream__trying_to_retrieve_a_remote_tracking_reference_from_a_plain_local_branch_returns_GIT_ENOTFOUND(void)
{
cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/subtrees"));
cl_assert_equal_i(GIT_ENOTFOUND, git_branch_upstream(&upstream, branch));
}
void test_refs_branches_upstream__trying_to_retrieve_a_remote_tracking_reference_from_a_branch_with_no_fetchspec_returns_GIT_ENOTFOUND(void)
{
cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/cannot-fetch"));
cl_assert_equal_i(GIT_ENOTFOUND, git_branch_upstream(&upstream, branch));
}
void test_refs_branches_upstream__upstream_remote(void)
{
git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_branch_upstream_remote(&buf, repo, "refs/heads/master"));
cl_assert_equal_s("test", buf.ptr);
git_buf_dispose(&buf);
}
void test_refs_branches_upstream__upstream_merge(void)
{
git_reference *branch;
git_repository *repository;
git_buf buf = GIT_BUF_INIT;
repository = cl_git_sandbox_init("testrepo.git");
/* check repository */
cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/test"));
cl_git_pass(git_branch_set_upstream(branch, "test/master"));
assert_config_entry_value(repository, "branch.test.remote", "test");
assert_config_entry_value(repository, "branch.test.merge", "refs/heads/master");
git_reference_free(branch);
/* check merge branch */
cl_git_pass(git_branch_upstream_merge(&buf, repository, "refs/heads/test"));
cl_assert_equal_s("refs/heads/master", buf.ptr);
git_buf_dispose(&buf);
cl_git_sandbox_cleanup();
}
void test_refs_branches_upstream__upstream_remote_empty_value(void)
{
git_repository *repository;
git_config *cfg;
git_buf buf = GIT_BUF_INIT;
repository = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_repository_config(&cfg, repository));
cl_git_pass(git_config_set_string(cfg, "branch.master.remote", ""));
cl_git_fail_with(GIT_ENOTFOUND, git_branch_upstream_remote(&buf, repository, "refs/heads/master"));
cl_git_pass(git_config_delete_entry(cfg, "branch.master.remote"));
cl_git_fail_with(GIT_ENOTFOUND, git_branch_upstream_remote(&buf, repository, "refs/heads/master"));
cl_git_sandbox_cleanup();
}
static void assert_merge_and_or_remote_key_missing(git_repository *repository, const git_commit *target, const char *entry_name)
{
git_reference *branch;
cl_assert_equal_i(GIT_OBJECT_COMMIT, git_object_type((git_object*)target));
cl_git_pass(git_branch_create(&branch, repository, entry_name, (git_commit*)target, 0));
cl_assert_equal_i(GIT_ENOTFOUND, git_branch_upstream(&upstream, branch));
git_reference_free(branch);
}
void test_refs_branches_upstream__retrieve_a_remote_tracking_reference_from_a_branch_with_no_remote_returns_GIT_ENOTFOUND(void)
{
git_reference *head;
git_repository *repository;
git_commit *target;
repository = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_repository_head(&head, repository));
cl_git_pass(git_reference_peel(((git_object **)&target), head, GIT_OBJECT_COMMIT));
git_reference_free(head);
assert_merge_and_or_remote_key_missing(repository, target, "remoteless");
assert_merge_and_or_remote_key_missing(repository, target, "mergeless");
assert_merge_and_or_remote_key_missing(repository, target, "mergeandremoteless");
git_commit_free(target);
cl_git_sandbox_cleanup();
}
void test_refs_branches_upstream__set_unset_upstream(void)
{
git_reference *branch;
git_repository *repository;
repository = cl_git_sandbox_init("testrepo.git");
/* remote */
cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/test"));
cl_git_pass(git_branch_set_upstream(branch, "test/master"));
assert_config_entry_value(repository, "branch.test.remote", "test");
assert_config_entry_value(repository, "branch.test.merge", "refs/heads/master");
git_reference_free(branch);
/* local */
cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/test"));
cl_git_pass(git_branch_set_upstream(branch, "master"));
assert_config_entry_value(repository, "branch.test.remote", ".");
assert_config_entry_value(repository, "branch.test.merge", "refs/heads/master");
/* unset */
cl_git_pass(git_branch_set_upstream(branch, NULL));
assert_config_entry_existence(repository, "branch.test.remote", false);
assert_config_entry_existence(repository, "branch.test.merge", false);
git_reference_free(branch);
cl_git_pass(git_reference_lookup(&branch, repository, "refs/heads/master"));
cl_git_pass(git_branch_set_upstream(branch, NULL));
assert_config_entry_existence(repository, "branch.test.remote", false);
assert_config_entry_existence(repository, "branch.test.merge", false);
git_reference_free(branch);
cl_git_sandbox_cleanup();
}
void test_refs_branches_upstream__no_fetch_refspec(void)
{
git_reference *ref, *branch;
git_repository *repo;
git_remote *remote;
git_config *cfg;
repo = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_remote_create_with_fetchspec(&remote, repo, "matching", ".", NULL));
cl_git_pass(git_remote_add_push(repo, "matching", ":"));
cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/test"));
cl_git_pass(git_reference_create(&ref, repo, "refs/remotes/matching/master", git_reference_target(branch), 1, "fetch"));
cl_git_fail(git_branch_set_upstream(branch, "matching/master"));
cl_assert_equal_s("could not determine remote for 'refs/remotes/matching/master'",
git_error_last()->message);
/* we can't set it automatically, so let's test the user setting it by hand */
cl_git_pass(git_repository_config(&cfg, repo));
cl_git_pass(git_config_set_string(cfg, "branch.test.remote", "matching"));
cl_git_pass(git_config_set_string(cfg, "branch.test.merge", "refs/heads/master"));
/* we still can't find it because there is no rule for that reference */
cl_git_fail_with(GIT_ENOTFOUND, git_branch_upstream(&ref, branch));
git_reference_free(ref);
git_reference_free(branch);
git_remote_free(remote);
cl_git_sandbox_cleanup();
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs/branches/ishead.c
|
#include "clar_libgit2.h"
#include "refs.h"
#include "repo/repo_helpers.h"
static git_repository *repo;
static git_reference *branch;
void test_refs_branches_ishead__initialize(void)
{
repo = cl_git_sandbox_init("testrepo.git");
branch = NULL;
}
void test_refs_branches_ishead__cleanup(void)
{
git_reference_free(branch);
branch = NULL;
cl_git_sandbox_cleanup();
repo = NULL;
}
void test_refs_branches_ishead__can_tell_if_a_branch_is_pointed_at_by_HEAD(void)
{
cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
cl_assert_equal_i(true, git_branch_is_head(branch));
}
void test_refs_branches_ishead__can_properly_handle_unborn_HEAD(void)
{
make_head_unborn(repo, NON_EXISTING_HEAD);
cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
cl_assert_equal_i(false, git_branch_is_head(branch));
}
void test_refs_branches_ishead__can_properly_handle_missing_HEAD(void)
{
delete_head(repo);
cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
cl_assert_equal_i(false, git_branch_is_head(branch));
}
void test_refs_branches_ishead__can_tell_if_a_branch_is_not_pointed_at_by_HEAD(void)
{
cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/br2"));
cl_assert_equal_i(false, git_branch_is_head(branch));
}
void test_refs_branches_ishead__wont_be_fooled_by_a_non_branch(void)
{
cl_git_pass(git_reference_lookup(&branch, repo, "refs/tags/e90810b"));
cl_assert_equal_i(false, git_branch_is_head(branch));
}
/*
* $ git init .
* Initialized empty Git repository in d:/temp/tempee/.git/
*
* $ touch a && git add a
* $ git commit -m" boom"
* [master (root-commit) b47b758] boom
* 0 files changed
* create mode 100644 a
*
* $ echo "ref: refs/heads/master" > .git/refs/heads/linked
* $ echo "ref: refs/heads/linked" > .git/refs/heads/super
* $ echo "ref: refs/heads/super" > .git/HEAD
*
* $ git branch
* linked -> master
* * master
* super -> master
*/
void test_refs_branches_ishead__only_direct_references_are_considered(void)
{
git_reference *linked, *super, *head;
cl_git_pass(git_reference_symbolic_create(&linked, repo, "refs/heads/linked", "refs/heads/master", 0, NULL));
cl_git_pass(git_reference_symbolic_create(&super, repo, "refs/heads/super", "refs/heads/linked", 0, NULL));
cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, "refs/heads/super", 1, NULL));
cl_assert_equal_i(false, git_branch_is_head(linked));
cl_assert_equal_i(false, git_branch_is_head(super));
cl_git_pass(git_repository_head(&branch, repo));
cl_assert_equal_s("refs/heads/master", git_reference_name(branch));
git_reference_free(linked);
git_reference_free(super);
git_reference_free(head);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs/branches/iterator.c
|
#include "clar_libgit2.h"
#include "refs.h"
static git_repository *repo;
static git_reference *fake_remote;
void test_refs_branches_iterator__initialize(void)
{
git_oid id;
cl_fixture_sandbox("testrepo.git");
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
cl_git_pass(git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
cl_git_pass(git_reference_create(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0, NULL));
}
void test_refs_branches_iterator__cleanup(void)
{
git_reference_free(fake_remote);
fake_remote = NULL;
git_repository_free(repo);
repo = NULL;
cl_fixture_cleanup("testrepo.git");
cl_git_sandbox_cleanup();
}
static void assert_retrieval(unsigned int flags, unsigned int expected_count)
{
git_branch_iterator *iter;
git_reference *ref;
int count = 0, error;
git_branch_t type;
cl_git_pass(git_branch_iterator_new(&iter, repo, flags));
while ((error = git_branch_next(&ref, &type, iter)) == 0) {
count++;
git_reference_free(ref);
}
git_branch_iterator_free(iter);
cl_assert_equal_i(error, GIT_ITEROVER);
cl_assert_equal_i(expected_count, count);
}
void test_refs_branches_iterator__retrieve_all_branches(void)
{
assert_retrieval(GIT_BRANCH_ALL, 14);
}
void test_refs_branches_iterator__retrieve_remote_branches(void)
{
assert_retrieval(GIT_BRANCH_REMOTE, 2);
}
void test_refs_branches_iterator__retrieve_local_branches(void)
{
assert_retrieval(GIT_BRANCH_LOCAL, 12);
}
struct expectations {
const char *branch_name;
int encounters;
};
static void assert_branch_has_been_found(struct expectations *findings, const char* expected_branch_name)
{
int pos = 0;
for (pos = 0; findings[pos].branch_name; ++pos) {
if (strcmp(expected_branch_name, findings[pos].branch_name) == 0) {
cl_assert_equal_i(1, findings[pos].encounters);
return;
}
}
cl_fail("expected branch not found in list.");
}
static void contains_branches(struct expectations exp[], git_branch_iterator *iter)
{
git_reference *ref;
git_branch_t type;
int error, pos = 0;
while ((error = git_branch_next(&ref, &type, iter)) == 0) {
for (pos = 0; exp[pos].branch_name; ++pos) {
if (strcmp(git_reference_shorthand(ref), exp[pos].branch_name) == 0)
exp[pos].encounters++;
}
git_reference_free(ref);
}
cl_assert_equal_i(error, GIT_ITEROVER);
}
/*
* $ git branch -r
* nulltoken/HEAD -> nulltoken/master
* nulltoken/master
*/
void test_refs_branches_iterator__retrieve_remote_symbolic_HEAD_when_present(void)
{
git_branch_iterator *iter;
struct expectations exp[] = {
{ "nulltoken/HEAD", 0 },
{ "nulltoken/master", 0 },
{ NULL, 0 }
};
git_reference_free(fake_remote);
cl_git_pass(git_reference_symbolic_create(&fake_remote, repo, "refs/remotes/nulltoken/HEAD", "refs/remotes/nulltoken/master", 0, NULL));
assert_retrieval(GIT_BRANCH_REMOTE, 3);
cl_git_pass(git_branch_iterator_new(&iter, repo, GIT_BRANCH_REMOTE));
contains_branches(exp, iter);
git_branch_iterator_free(iter);
assert_branch_has_been_found(exp, "nulltoken/HEAD");
assert_branch_has_been_found(exp, "nulltoken/master");
}
void test_refs_branches_iterator__mix_of_packed_and_loose(void)
{
git_branch_iterator *iter;
struct expectations exp[] = {
{ "master", 0 },
{ "origin/HEAD", 0 },
{ "origin/master", 0 },
{ "origin/packed", 0 },
{ NULL, 0 }
};
git_repository *r2;
r2 = cl_git_sandbox_init("testrepo2");
cl_git_pass(git_branch_iterator_new(&iter, r2, GIT_BRANCH_ALL));
contains_branches(exp, iter);
git_branch_iterator_free(iter);
assert_branch_has_been_found(exp, "master");
assert_branch_has_been_found(exp, "origin/HEAD");
assert_branch_has_been_found(exp, "origin/master");
assert_branch_has_been_found(exp, "origin/packed");
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs/branches/lookup.c
|
#include "clar_libgit2.h"
#include "refs.h"
static git_repository *repo;
static git_reference *branch;
void test_refs_branches_lookup__initialize(void)
{
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
branch = NULL;
}
void test_refs_branches_lookup__cleanup(void)
{
git_reference_free(branch);
branch = NULL;
git_repository_free(repo);
repo = NULL;
}
void test_refs_branches_lookup__can_retrieve_a_local_branch_local(void)
{
cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL));
}
void test_refs_branches_lookup__can_retrieve_a_local_branch_all(void)
{
cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_ALL));
}
void test_refs_branches_lookup__trying_to_retrieve_a_local_branch_remote(void)
{
cl_git_fail(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_REMOTE));
}
void test_refs_branches_lookup__can_retrieve_a_remote_tracking_branch_remote(void)
{
cl_git_pass(git_branch_lookup(&branch, repo, "test/master", GIT_BRANCH_REMOTE));
}
void test_refs_branches_lookup__can_retrieve_a_remote_tracking_branch_all(void)
{
cl_git_pass(git_branch_lookup(&branch, repo, "test/master", GIT_BRANCH_ALL));
}
void test_refs_branches_lookup__trying_to_retrieve_a_remote_tracking_branch_local(void)
{
cl_git_fail(git_branch_lookup(&branch, repo, "test/master", GIT_BRANCH_LOCAL));
}
void test_refs_branches_lookup__trying_to_retrieve_an_unknown_branch_returns_ENOTFOUND(void)
{
cl_assert_equal_i(GIT_ENOTFOUND, git_branch_lookup(&branch, repo, "where/are/you", GIT_BRANCH_LOCAL));
cl_assert_equal_i(GIT_ENOTFOUND, git_branch_lookup(&branch, repo, "over/here", GIT_BRANCH_REMOTE));
cl_assert_equal_i(GIT_ENOTFOUND, git_branch_lookup(&branch, repo, "maybe/here", GIT_BRANCH_ALL));
}
void test_refs_branches_lookup__trying_to_retrieve_a_branch_with_an_invalid_name_returns_EINVALIDSPEC(void)
{
cl_assert_equal_i(GIT_EINVALIDSPEC,
git_branch_lookup(&branch, repo, "are/you/inv@{id", GIT_BRANCH_LOCAL));
cl_assert_equal_i(GIT_EINVALIDSPEC,
git_branch_lookup(&branch, repo, "yes/i am", GIT_BRANCH_REMOTE));
cl_assert_equal_i(GIT_EINVALIDSPEC,
git_branch_lookup(&branch, repo, "inv al/id", GIT_BRANCH_ALL));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs/tags/name.c
|
#include "clar_libgit2.h"
static int name_is_valid(const char *name)
{
int valid;
cl_git_pass(git_tag_name_is_valid(&valid, name));
return valid;
}
void test_refs_tags_is_name_valid(void)
{
cl_assert_equal_i(true, name_is_valid("sometag"));
cl_assert_equal_i(true, name_is_valid("test/sometag"));
cl_assert_equal_i(false, name_is_valid(""));
cl_assert_equal_i(false, name_is_valid("-dash"));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs/reflog/reflog_helpers.c
|
#include "clar_libgit2.h"
#include "repository.h"
#include "reflog.h"
static int reflog_entry_tostr(git_buf *out, const git_reflog_entry *entry)
{
char old_oid[GIT_OID_HEXSZ], new_oid[GIT_OID_HEXSZ];
assert(out && entry);
git_oid_tostr((char *)&old_oid, GIT_OID_HEXSZ, git_reflog_entry_id_old(entry));
git_oid_tostr((char *)&new_oid, GIT_OID_HEXSZ, git_reflog_entry_id_new(entry));
return git_buf_printf(out, "%s %s %s %s", old_oid, new_oid, "somesig", git_reflog_entry_message(entry));
}
size_t reflog_entrycount(git_repository *repo, const char *name)
{
git_reflog *log;
size_t ret;
cl_git_pass(git_reflog_read(&log, repo, name));
ret = git_reflog_entrycount(log);
git_reflog_free(log);
return ret;
}
void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx,
const char *old_spec, const char *new_spec,
const char *email, const char *message,
const char *file, const char *func, int line)
{
git_reflog *log;
const git_reflog_entry *entry;
git_buf result = GIT_BUF_INIT;
cl_git_pass(git_reflog_read(&log, repo, reflog));
entry = git_reflog_entry_byindex(log, idx);
if (entry == NULL)
clar__fail(file, func, line, "Reflog has no such entry", NULL, 1);
if (old_spec) {
git_object *obj = NULL;
if (git_revparse_single(&obj, repo, old_spec) == GIT_OK) {
if (git_oid_cmp(git_object_id(obj), git_reflog_entry_id_old(entry)) != 0) {
git_oid__writebuf(&result, "\tOld OID: \"", git_object_id(obj));
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_old(entry));
git_buf_puts(&result, "\"\n");
}
git_object_free(obj);
} else {
git_oid *oid = git__calloc(1, sizeof(*oid));
git_oid_fromstr(oid, old_spec);
if (git_oid_cmp(oid, git_reflog_entry_id_old(entry)) != 0) {
git_oid__writebuf(&result, "\tOld OID: \"", oid);
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_old(entry));
git_buf_puts(&result, "\"\n");
}
git__free(oid);
}
}
if (new_spec) {
git_object *obj = NULL;
if (git_revparse_single(&obj, repo, new_spec) == GIT_OK) {
if (git_oid_cmp(git_object_id(obj), git_reflog_entry_id_new(entry)) != 0) {
git_oid__writebuf(&result, "\tNew OID: \"", git_object_id(obj));
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_new(entry));
git_buf_puts(&result, "\"\n");
}
git_object_free(obj);
} else {
git_oid *oid = git__calloc(1, sizeof(*oid));
git_oid_fromstr(oid, new_spec);
if (git_oid_cmp(oid, git_reflog_entry_id_new(entry)) != 0) {
git_oid__writebuf(&result, "\tNew OID: \"", oid);
git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_new(entry));
git_buf_puts(&result, "\"\n");
}
git__free(oid);
}
}
if (email && strcmp(email, git_reflog_entry_committer(entry)->email) != 0)
git_buf_printf(&result, "\tEmail: \"%s\" != \"%s\"\n", email, git_reflog_entry_committer(entry)->email);
if (message) {
const char *entry_msg = git_reflog_entry_message(entry);
if (entry_msg == NULL) entry_msg = "";
if (entry_msg && strcmp(message, entry_msg) != 0)
git_buf_printf(&result, "\tMessage: \"%s\" != \"%s\"\n", message, entry_msg);
}
if (git_buf_len(&result) != 0)
clar__fail(file, func, line, "Reflog entry mismatch", git_buf_cstr(&result), 1);
git_buf_dispose(&result);
git_reflog_free(log);
}
void reflog_print(git_repository *repo, const char *reflog_name)
{
git_reflog *reflog;
size_t idx;
git_buf out = GIT_BUF_INIT;
git_reflog_read(&reflog, repo, reflog_name);
for (idx = 0; idx < git_reflog_entrycount(reflog); idx++) {
const git_reflog_entry *entry = git_reflog_entry_byindex(reflog, idx);
reflog_entry_tostr(&out, entry);
git_buf_putc(&out, '\n');
}
fprintf(stderr, "%s", git_buf_cstr(&out));
git_buf_dispose(&out);
git_reflog_free(reflog);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs/reflog/reflog.c
|
#include "clar_libgit2.h"
#include "futils.h"
#include "git2/reflog.h"
#include "reflog.h"
static const char *new_ref = "refs/heads/test-reflog";
static const char *current_master_tip = "a65fedf39aefe402d3bb6e24df4d4f5fe4547750";
#define commit_msg "commit: bla bla"
static git_repository *g_repo;
/* helpers */
static void assert_signature(const git_signature *expected, const git_signature *actual)
{
cl_assert(actual);
cl_assert_equal_s(expected->name, actual->name);
cl_assert_equal_s(expected->email, actual->email);
cl_assert(expected->when.offset == actual->when.offset);
cl_assert(expected->when.time == actual->when.time);
}
/* Fixture setup and teardown */
void test_refs_reflog_reflog__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo.git");
}
void test_refs_reflog_reflog__cleanup(void)
{
cl_git_sandbox_cleanup();
}
static void assert_appends(const git_signature *committer, const git_oid *oid)
{
git_repository *repo2;
git_reference *lookedup_ref;
git_reflog *reflog;
const git_reflog_entry *entry;
/* Reopen a new instance of the repository */
cl_git_pass(git_repository_open(&repo2, "testrepo.git"));
/* Lookup the previously created branch */
cl_git_pass(git_reference_lookup(&lookedup_ref, repo2, new_ref));
/* Read and parse the reflog for this branch */
cl_git_pass(git_reflog_read(&reflog, repo2, new_ref));
cl_assert_equal_i(3, (int)git_reflog_entrycount(reflog));
/* The first one was the creation of the branch */
entry = git_reflog_entry_byindex(reflog, 2);
cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0);
entry = git_reflog_entry_byindex(reflog, 1);
assert_signature(committer, entry->committer);
cl_assert(git_oid_cmp(oid, &entry->oid_old) == 0);
cl_assert(git_oid_cmp(oid, &entry->oid_cur) == 0);
cl_assert(entry->msg == NULL);
entry = git_reflog_entry_byindex(reflog, 0);
assert_signature(committer, entry->committer);
cl_assert(git_oid_cmp(oid, &entry->oid_cur) == 0);
cl_assert_equal_s(commit_msg, entry->msg);
git_reflog_free(reflog);
git_repository_free(repo2);
git_reference_free(lookedup_ref);
}
void test_refs_reflog_reflog__append_then_read(void)
{
/* write a reflog for a given reference and ensure it can be read back */
git_reference *ref;
git_oid oid;
git_signature *committer;
git_reflog *reflog;
/* Create a new branch pointing at the HEAD */
git_oid_fromstr(&oid, current_master_tip);
cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &oid, 0, NULL));
git_reference_free(ref);
cl_git_pass(git_signature_now(&committer, "foo", "foo@bar"));
cl_git_pass(git_reflog_read(&reflog, g_repo, new_ref));
cl_git_pass(git_reflog_append(reflog, &oid, committer, NULL));
cl_git_pass(git_reflog_append(reflog, &oid, committer, commit_msg "\n"));
cl_git_pass(git_reflog_write(reflog));
assert_appends(committer, &oid);
git_reflog_free(reflog);
git_signature_free(committer);
}
void test_refs_reflog_reflog__renaming_the_reference_moves_the_reflog(void)
{
git_reference *master, *new_master;
git_buf master_log_path = GIT_BUF_INIT, moved_log_path = GIT_BUF_INIT;
git_buf_joinpath(&master_log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
git_buf_puts(&moved_log_path, git_buf_cstr(&master_log_path));
git_buf_joinpath(&master_log_path, git_buf_cstr(&master_log_path), "refs/heads/master");
git_buf_joinpath(&moved_log_path, git_buf_cstr(&moved_log_path), "refs/moved");
cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&master_log_path)));
cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&moved_log_path)));
cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
cl_git_pass(git_reference_rename(&new_master, master, "refs/moved", 0, NULL));
git_reference_free(master);
cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&master_log_path)));
cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&moved_log_path)));
git_reference_free(new_master);
git_buf_dispose(&moved_log_path);
git_buf_dispose(&master_log_path);
}
void test_refs_reflog_reflog__deleting_the_reference_deletes_the_reflog(void)
{
git_reference *master;
git_buf master_log_path = GIT_BUF_INIT;
git_buf_joinpath(&master_log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
git_buf_joinpath(&master_log_path, git_buf_cstr(&master_log_path), "refs/heads/master");
cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&master_log_path)));
cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
cl_git_pass(git_reference_delete(master));
git_reference_free(master);
cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&master_log_path)));
git_buf_dispose(&master_log_path);
}
void test_refs_reflog_reflog__removes_empty_reflog_dir(void)
{
git_reference *ref;
git_buf log_path = GIT_BUF_INIT;
git_oid id;
/* Create a new branch pointing at the HEAD */
git_oid_fromstr(&id, current_master_tip);
cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir/new-head", &id, 0, NULL));
git_buf_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
git_buf_joinpath(&log_path, git_buf_cstr(&log_path), "refs/heads/new-dir/new-head");
cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&log_path)));
cl_git_pass(git_reference_delete(ref));
git_reference_free(ref);
/* new ref creation should succeed since new-dir is empty */
git_oid_fromstr(&id, current_master_tip);
cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir", &id, 0, NULL));
git_reference_free(ref);
git_buf_dispose(&log_path);
}
void test_refs_reflog_reflog__fails_gracefully_on_nonempty_reflog_dir(void)
{
git_reference *ref;
git_buf log_path = GIT_BUF_INIT;
git_oid id;
/* Create a new branch pointing at the HEAD */
git_oid_fromstr(&id, current_master_tip);
cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir/new-head", &id, 0, NULL));
git_reference_free(ref);
git_buf_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR);
git_buf_joinpath(&log_path, git_buf_cstr(&log_path), "refs/heads/new-dir/new-head");
cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&log_path)));
/* delete the ref manually, leave the reflog */
cl_must_pass(p_unlink("testrepo.git/refs/heads/new-dir/new-head"));
/* new ref creation should fail since new-dir contains reflogs still */
git_oid_fromstr(&id, current_master_tip);
cl_git_fail_with(GIT_EDIRECTORY, git_reference_create(&ref, g_repo, "refs/heads/new-dir", &id, 0, NULL));
git_reference_free(ref);
git_buf_dispose(&log_path);
}
static void assert_has_reflog(bool expected_result, const char *name)
{
cl_assert_equal_i(expected_result, git_reference_has_log(g_repo, name));
}
void test_refs_reflog_reflog__reference_has_reflog(void)
{
assert_has_reflog(true, "HEAD");
assert_has_reflog(true, "refs/heads/master");
assert_has_reflog(false, "refs/heads/subtrees");
}
void test_refs_reflog_reflog__reading_the_reflog_from_a_reference_with_no_log_returns_an_empty_one(void)
{
git_reflog *reflog;
const char *refname = "refs/heads/subtrees";
git_buf subtrees_log_path = GIT_BUF_INIT;
git_buf_join_n(&subtrees_log_path, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, refname);
cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&subtrees_log_path)));
cl_git_pass(git_reflog_read(&reflog, g_repo, refname));
cl_assert_equal_i(0, (int)git_reflog_entrycount(reflog));
git_reflog_free(reflog);
git_buf_dispose(&subtrees_log_path);
}
void test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_succeeds(void)
{
git_reflog *reflog;
const char *refname = "refs/heads/newline";
const char *refmessage =
"Reflog*message with a newline and enough content after it to pass the GIT_REFLOG_SIZE_MIN check inside reflog_parse.";
const git_reflog_entry *entry;
git_reference *ref;
git_oid id;
git_buf logpath = GIT_BUF_INIT, logcontents = GIT_BUF_INIT;
char *star;
/* Create a new branch. */
cl_git_pass(git_oid_fromstr(&id, current_master_tip));
cl_git_pass(git_reference_create(&ref, g_repo, refname, &id, 1, refmessage));
/*
* Corrupt the branch reflog by introducing a newline inside the reflog message.
* We do this by replacing '*' with '\n'
*/
cl_git_pass(git_buf_join_n(&logpath, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, refname));
cl_git_pass(git_futils_readbuffer(&logcontents, git_buf_cstr(&logpath)));
cl_assert((star = strchr(git_buf_cstr(&logcontents), '*')) != NULL);
*star = '\n';
cl_git_rewritefile(git_buf_cstr(&logpath), git_buf_cstr(&logcontents));
/*
* Confirm that the file was rewritten successfully
* and now contains a '\n' in the expected location
*/
cl_git_pass(git_futils_readbuffer(&logcontents, git_buf_cstr(&logpath)));
cl_assert(strstr(git_buf_cstr(&logcontents), "Reflog\nmessage") != NULL);
cl_git_pass(git_reflog_read(&reflog, g_repo, refname));
cl_assert(entry = git_reflog_entry_byindex(reflog, 0));
cl_assert_equal_s(git_reflog_entry_message(entry), "Reflog");
git_reference_free(ref);
git_reflog_free(reflog);
git_buf_dispose(&logpath);
git_buf_dispose(&logcontents);
}
void test_refs_reflog_reflog__cannot_write_a_moved_reflog(void)
{
git_reference *master, *new_master;
git_buf master_log_path = GIT_BUF_INIT, moved_log_path = GIT_BUF_INIT;
git_reflog *reflog;
cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
cl_git_pass(git_reflog_read(&reflog, g_repo, "refs/heads/master"));
cl_git_pass(git_reflog_write(reflog));
cl_git_pass(git_reference_rename(&new_master, master, "refs/moved", 0, NULL));
git_reference_free(master);
cl_git_fail(git_reflog_write(reflog));
git_reflog_free(reflog);
git_reference_free(new_master);
git_buf_dispose(&moved_log_path);
git_buf_dispose(&master_log_path);
}
void test_refs_reflog_reflog__renaming_with_an_invalid_name_returns_EINVALIDSPEC(void)
{
cl_assert_equal_i(GIT_EINVALIDSPEC,
git_reflog_rename(g_repo, "refs/heads/master", "refs/heads/Inv@{id"));
}
void test_refs_reflog_reflog__write_only_std_locations(void)
{
git_reference *ref;
git_oid id;
git_oid_fromstr(&id, current_master_tip);
cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/foo", &id, 1, NULL));
git_reference_free(ref);
cl_git_pass(git_reference_create(&ref, g_repo, "refs/tags/foo", &id, 1, NULL));
git_reference_free(ref);
cl_git_pass(git_reference_create(&ref, g_repo, "refs/notes/foo", &id, 1, NULL));
git_reference_free(ref);
assert_has_reflog(true, "refs/heads/foo");
assert_has_reflog(false, "refs/tags/foo");
assert_has_reflog(true, "refs/notes/foo");
}
void test_refs_reflog_reflog__write_when_explicitly_active(void)
{
git_reference *ref;
git_oid id;
git_oid_fromstr(&id, current_master_tip);
git_reference_ensure_log(g_repo, "refs/tags/foo");
cl_git_pass(git_reference_create(&ref, g_repo, "refs/tags/foo", &id, 1, NULL));
git_reference_free(ref);
assert_has_reflog(true, "refs/tags/foo");
}
void test_refs_reflog_reflog__append_to_HEAD_when_changing_current_branch(void)
{
size_t nlogs, nlogs_after;
git_reference *ref;
git_reflog *log;
git_oid id;
cl_git_pass(git_reflog_read(&log, g_repo, "HEAD"));
nlogs = git_reflog_entrycount(log);
git_reflog_free(log);
/* Move it back */
git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/master", &id, 1, NULL));
git_reference_free(ref);
cl_git_pass(git_reflog_read(&log, g_repo, "HEAD"));
nlogs_after = git_reflog_entrycount(log);
git_reflog_free(log);
cl_assert_equal_i(nlogs_after, nlogs + 1);
}
void test_refs_reflog_reflog__do_not_append_when_no_update(void)
{
size_t nlogs, nlogs_after;
git_reference *ref, *ref2;
git_reflog *log;
cl_git_pass(git_reflog_read(&log, g_repo, "HEAD"));
nlogs = git_reflog_entrycount(log);
git_reflog_free(log);
cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/master"));
cl_git_pass(git_reference_create(&ref2, g_repo, "refs/heads/master",
git_reference_target(ref), 1, NULL));
git_reference_free(ref);
git_reference_free(ref2);
cl_git_pass(git_reflog_read(&log, g_repo, "HEAD"));
nlogs_after = git_reflog_entrycount(log);
git_reflog_free(log);
cl_assert_equal_i(nlogs_after, nlogs);
}
static void assert_no_reflog_update(void)
{
size_t nlogs, nlogs_after;
size_t nlogs_master, nlogs_master_after;
git_reference *ref;
git_reflog *log;
git_oid id;
cl_git_pass(git_reflog_read(&log, g_repo, "HEAD"));
nlogs = git_reflog_entrycount(log);
git_reflog_free(log);
cl_git_pass(git_reflog_read(&log, g_repo, "refs/heads/master"));
nlogs_master = git_reflog_entrycount(log);
git_reflog_free(log);
/* Move it back */
git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/master", &id, 1, NULL));
git_reference_free(ref);
cl_git_pass(git_reflog_read(&log, g_repo, "HEAD"));
nlogs_after = git_reflog_entrycount(log);
git_reflog_free(log);
cl_assert_equal_i(nlogs_after, nlogs);
cl_git_pass(git_reflog_read(&log, g_repo, "refs/heads/master"));
nlogs_master_after = git_reflog_entrycount(log);
git_reflog_free(log);
cl_assert_equal_i(nlogs_after, nlogs);
cl_assert_equal_i(nlogs_master_after, nlogs_master);
}
void test_refs_reflog_reflog__logallrefupdates_bare_set_false(void)
{
git_config *config;
cl_git_pass(git_repository_config(&config, g_repo));
cl_git_pass(git_config_set_bool(config, "core.logallrefupdates", false));
git_config_free(config);
assert_no_reflog_update();
}
void test_refs_reflog_reflog__logallrefupdates_bare_set_always(void)
{
git_config *config;
git_reference *ref;
git_reflog *log;
git_oid id;
cl_git_pass(git_repository_config(&config, g_repo));
cl_git_pass(git_config_set_string(config, "core.logallrefupdates", "always"));
git_config_free(config);
git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
cl_git_pass(git_reference_create(&ref, g_repo, "refs/bork", &id, 1, "message"));
cl_git_pass(git_reflog_read(&log, g_repo, "refs/bork"));
cl_assert_equal_i(1, git_reflog_entrycount(log));
cl_assert_equal_s("message", git_reflog_entry_byindex(log, 0)->msg);
git_reflog_free(log);
git_reference_free(ref);
}
void test_refs_reflog_reflog__logallrefupdates_bare_unset(void)
{
git_config *config;
cl_git_pass(git_repository_config(&config, g_repo));
cl_git_pass(git_config_delete_entry(config, "core.logallrefupdates"));
git_config_free(config);
assert_no_reflog_update();
}
void test_refs_reflog_reflog__logallrefupdates_nonbare_set_false(void)
{
git_config *config;
cl_git_sandbox_cleanup();
g_repo = cl_git_sandbox_init("testrepo");
cl_git_pass(git_repository_config(&config, g_repo));
cl_git_pass(git_config_set_bool(config, "core.logallrefupdates", false));
git_config_free(config);
assert_no_reflog_update();
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs/reflog/drop.c
|
#include "clar_libgit2.h"
#include "reflog.h"
static git_repository *g_repo;
static git_reflog *g_reflog;
static size_t entrycount;
void test_refs_reflog_drop__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo.git");
git_reflog_read(&g_reflog, g_repo, "HEAD");
entrycount = git_reflog_entrycount(g_reflog);
}
void test_refs_reflog_drop__cleanup(void)
{
git_reflog_free(g_reflog);
g_reflog = NULL;
cl_git_sandbox_cleanup();
}
void test_refs_reflog_drop__dropping_a_non_exisiting_entry_from_the_log_returns_ENOTFOUND(void)
{
cl_assert_equal_i(GIT_ENOTFOUND, git_reflog_drop(g_reflog, entrycount, 0));
cl_assert_equal_sz(entrycount, git_reflog_entrycount(g_reflog));
}
void test_refs_reflog_drop__can_drop_an_entry(void)
{
cl_assert(entrycount > 4);
cl_git_pass(git_reflog_drop(g_reflog, 2, 0));
cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog));
}
void test_refs_reflog_drop__can_drop_an_entry_and_rewrite_the_log_history(void)
{
const git_reflog_entry *before_current;
const git_reflog_entry *after_current;
git_oid before_current_old_oid, before_current_cur_oid;
cl_assert(entrycount > 4);
before_current = git_reflog_entry_byindex(g_reflog, 1);
git_oid_cpy(&before_current_old_oid, &before_current->oid_old);
git_oid_cpy(&before_current_cur_oid, &before_current->oid_cur);
cl_git_pass(git_reflog_drop(g_reflog, 1, 1));
cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog));
after_current = git_reflog_entry_byindex(g_reflog, 0);
cl_assert_equal_i(0, git_oid_cmp(&before_current_old_oid, &after_current->oid_old));
cl_assert(0 != git_oid_cmp(&before_current_cur_oid, &after_current->oid_cur));
}
void test_refs_reflog_drop__can_drop_the_oldest_entry(void)
{
const git_reflog_entry *entry;
cl_assert(entrycount > 2);
cl_git_pass(git_reflog_drop(g_reflog, entrycount - 1, 0));
cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog));
entry = git_reflog_entry_byindex(g_reflog, entrycount - 2);
cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) != 0);
}
void test_refs_reflog_drop__can_drop_the_oldest_entry_and_rewrite_the_log_history(void)
{
const git_reflog_entry *entry;
cl_assert(entrycount > 2);
cl_git_pass(git_reflog_drop(g_reflog, entrycount - 1, 1));
cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog));
entry = git_reflog_entry_byindex(g_reflog, entrycount - 2);
cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0);
}
void test_refs_reflog_drop__can_drop_all_the_entries(void)
{
cl_assert(--entrycount > 0);
do {
cl_git_pass(git_reflog_drop(g_reflog, 0, 1));
} while (--entrycount > 0);
cl_git_pass(git_reflog_drop(g_reflog, 0, 1));
cl_assert_equal_i(0, (int)git_reflog_entrycount(g_reflog));
}
void test_refs_reflog_drop__can_persist_deletion_on_disk(void)
{
cl_assert(entrycount > 2);
cl_git_pass(git_reflog_drop(g_reflog, 0, 1));
cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog));
cl_git_pass(git_reflog_write(g_reflog));
git_reflog_free(g_reflog);
git_reflog_read(&g_reflog, g_repo, "HEAD");
cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs/reflog/messages.c
|
#include "clar_libgit2.h"
#include "futils.h"
#include "git2/reflog.h"
#include "reflog.h"
#include "refs.h"
#include "reflog_helpers.h"
static const char *g_email = "[email protected]";
static git_repository *g_repo;
/* Fixture setup and teardown */
void test_refs_reflog_messages__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_repository_set_ident(g_repo, "Foo Bar", g_email));
}
void test_refs_reflog_messages__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_refs_reflog_messages__setting_head_updates_reflog(void)
{
git_object *tag;
git_annotated_commit *annotated;
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked")); /* 4 */
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/unborn"));
cl_git_pass(git_revparse_single(&tag, g_repo, "tags/test"));
cl_git_pass(git_repository_set_head_detached(g_repo, git_object_id(tag))); /* 3 */
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked")); /* 2 */
cl_git_pass(git_repository_set_head(g_repo, "refs/tags/test")); /* 1 */
cl_git_pass(git_repository_set_head(g_repo, "refs/remotes/test/master")); /* 0 */
cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 4,
NULL, "refs/heads/haacked",
"[email protected]",
"checkout: moving from master to haacked");
cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 3,
NULL, "tags/test^{commit}",
"[email protected]",
"checkout: moving from unborn to e90810b8df3e80c413d903f631643c716887138d");
cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 2,
"tags/test^{commit}", "refs/heads/haacked",
"[email protected]",
"checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked");
cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 1,
"refs/heads/haacked", "tags/test^{commit}",
"[email protected]",
"checkout: moving from haacked to test");
cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
"tags/test^{commit}", "refs/remotes/test/master",
"[email protected]",
"checkout: moving from e90810b8df3e80c413d903f631643c716887138d to test/master");
cl_git_pass(git_annotated_commit_from_revspec(&annotated, g_repo, "haacked~0"));
cl_git_pass(git_repository_set_head_detached_from_annotated(g_repo, annotated));
cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
NULL, "refs/heads/haacked",
"[email protected]",
"checkout: moving from be3563ae3f795b2b4353bcce3a527ad0a4f7f644 to haacked~0");
git_annotated_commit_free(annotated);
git_object_free(tag);
}
void test_refs_reflog_messages__setting_head_to_same_target_ignores_reflog(void)
{
size_t nentries, nentries_after;
nentries = reflog_entrycount(g_repo, GIT_HEAD_FILE);
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked"));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked"));
nentries_after = reflog_entrycount(g_repo, GIT_HEAD_FILE);
cl_assert_equal_i(nentries + 1, nentries_after);
}
void test_refs_reflog_messages__detaching_writes_reflog(void)
{
git_oid id;
const char *msg;
msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d";
git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d");
cl_git_pass(git_repository_set_head_detached(g_repo, &id));
cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"e90810b8df3e80c413d903f631643c716887138d",
NULL, msg);
msg = "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked";
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked"));
cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
"e90810b8df3e80c413d903f631643c716887138d",
"258f0e2a959a364e40ed6603d5d44fbb24765b10",
NULL, msg);
}
void test_refs_reflog_messages__orphan_branch_does_not_count(void)
{
git_oid id;
const char *msg;
/* Have something known */
msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d";
git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d");
cl_git_pass(git_repository_set_head_detached(g_repo, &id));
cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"e90810b8df3e80c413d903f631643c716887138d",
NULL, msg);
/* Switching to an orphan branch does not write to the reflog */
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/orphan"));
cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"e90810b8df3e80c413d903f631643c716887138d",
NULL, msg);
/* And coming back, we set the source to zero */
msg = "checkout: moving from orphan to haacked";
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked"));
cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
"0000000000000000000000000000000000000000",
"258f0e2a959a364e40ed6603d5d44fbb24765b10",
NULL, msg);
}
void test_refs_reflog_messages__branch_birth(void)
{
git_signature *sig;
git_oid id;
git_tree *tree;
git_reference *ref;
const char *msg;
size_t nentries, nentries_after;
nentries = reflog_entrycount(g_repo, GIT_HEAD_FILE);
cl_git_pass(git_signature_now(&sig, "me", "[email protected]"));
cl_git_pass(git_repository_head(&ref, g_repo));
cl_git_pass(git_reference_peel((git_object **) &tree, ref, GIT_OBJECT_TREE));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/orphan"));
nentries_after = reflog_entrycount(g_repo, GIT_HEAD_FILE);
cl_assert_equal_i(nentries, nentries_after);
msg = "message 2";
cl_git_pass(git_commit_create(&id, g_repo, "HEAD", sig, sig, NULL, msg, tree, 0, NULL));
cl_assert_equal_i(1, reflog_entrycount(g_repo, "refs/heads/orphan"));
nentries_after = reflog_entrycount(g_repo, GIT_HEAD_FILE);
cl_assert_equal_i(nentries + 1, nentries_after);
git_signature_free(sig);
git_tree_free(tree);
git_reference_free(ref);
}
void test_refs_reflog_messages__commit_on_symbolic_ref_updates_head_reflog(void)
{
git_signature *sig;
git_oid id;
git_tree *tree;
git_reference *ref1, *ref2;
const char *msg;
size_t nentries_head, nentries_master;
nentries_head = reflog_entrycount(g_repo, GIT_HEAD_FILE);
cl_git_pass(git_signature_now(&sig, "me", "[email protected]"));
cl_git_pass(git_repository_head(&ref1, g_repo));
cl_git_pass(git_reference_peel((git_object **) &tree, ref1, GIT_OBJECT_TREE));
nentries_master = reflog_entrycount(g_repo, "refs/heads/master");
msg = "message 1";
cl_git_pass(git_reference_symbolic_create(&ref2, g_repo, "refs/heads/master", "refs/heads/foo", 1, msg));
cl_assert_equal_i(0, reflog_entrycount(g_repo, "refs/heads/foo"));
cl_assert_equal_i(nentries_head, reflog_entrycount(g_repo, GIT_HEAD_FILE));
cl_assert_equal_i(nentries_master, reflog_entrycount(g_repo, "refs/heads/master"));
msg = "message 2";
cl_git_pass(git_commit_create(&id, g_repo, "HEAD", sig, sig, NULL, msg, tree, 0, NULL));
cl_assert_equal_i(1, reflog_entrycount(g_repo, "refs/heads/foo"));
cl_assert_equal_i(nentries_head + 1, reflog_entrycount(g_repo, GIT_HEAD_FILE));
cl_assert_equal_i(nentries_master, reflog_entrycount(g_repo, "refs/heads/master"));
git_signature_free(sig);
git_reference_free(ref1);
git_reference_free(ref2);
git_tree_free(tree);
}
void test_refs_reflog_messages__show_merge_for_merge_commits(void)
{
git_oid b1_oid;
git_oid b2_oid;
git_oid merge_commit_oid;
git_commit *b1_commit;
git_commit *b2_commit;
git_signature *s;
git_commit *parent_commits[2];
git_tree *tree;
cl_git_pass(git_signature_now(&s, "alice", "[email protected]"));
cl_git_pass(git_reference_name_to_id(&b1_oid, g_repo, "HEAD"));
cl_git_pass(git_reference_name_to_id(&b2_oid, g_repo, "refs/heads/test"));
cl_git_pass(git_commit_lookup(&b1_commit, g_repo, &b1_oid));
cl_git_pass(git_commit_lookup(&b2_commit, g_repo, &b2_oid));
parent_commits[0] = b1_commit;
parent_commits[1] = b2_commit;
cl_git_pass(git_commit_tree(&tree, b1_commit));
cl_git_pass(git_commit_create(&merge_commit_oid,
g_repo, "HEAD", s, s, NULL,
"Merge commit", tree,
2, (const struct git_commit **) parent_commits));
cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
NULL,
git_oid_tostr_s(&merge_commit_oid),
NULL, "commit (merge): Merge commit");
git_tree_free(tree);
git_commit_free(b1_commit);
git_commit_free(b2_commit);
git_signature_free(s);
}
void test_refs_reflog_messages__creating_a_direct_reference(void)
{
git_reference *reference;
git_oid id;
git_reflog *reflog;
const git_reflog_entry *entry;
const char *name = "refs/heads/new-head";
const char *message = "You've been logged, mate!";
cl_git_pass(git_reference_name_to_id(&id, g_repo, "HEAD"));
cl_git_pass(git_reference_create(&reference, g_repo, name, &id, 0, message));
cl_git_pass(git_reflog_read(&reflog, g_repo, name));
cl_assert_equal_sz(1, git_reflog_entrycount(reflog));
entry = git_reflog_entry_byindex(reflog, 0);
cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0);
cl_assert_equal_oid(&id, &entry->oid_cur);
cl_assert_equal_s(message, entry->msg);
git_reflog_free(reflog);
git_reference_free(reference);
}
void test_refs_reflog_messages__newline_gets_replaced(void)
{
const git_reflog_entry *entry;
git_signature *signature;
git_reflog *reflog;
git_oid oid;
cl_git_pass(git_signature_now(&signature, "me", "[email protected]"));
cl_git_pass(git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"));
cl_git_pass(git_reflog_read(&reflog, g_repo, "HEAD"));
cl_assert_equal_sz(7, git_reflog_entrycount(reflog));
cl_git_pass(git_reflog_append(reflog, &oid, signature, "inner\nnewline"));
cl_assert_equal_sz(8, git_reflog_entrycount(reflog));
cl_assert(entry = git_reflog_entry_byindex(reflog, 0));
cl_assert_equal_s(git_reflog_entry_message(entry), "inner newline");
git_signature_free(signature);
git_reflog_free(reflog);
}
void test_refs_reflog_messages__renaming_ref(void)
{
git_reference *ref, *new_ref;
cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/master"));
cl_git_pass(git_reference_rename(&new_ref, ref, "refs/heads/renamed", false,
"message"));
cl_reflog_check_entry(g_repo, git_reference_name(new_ref), 0,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"[email protected]", "message");
git_reference_free(ref);
git_reference_free(new_ref);
}
void test_refs_reflog_messages__updating_a_direct_reference(void)
{
git_reference *ref, *ref_out, *target_ref;
git_oid target_id;
const char *message = "You've been logged, mate!";
git_reference_name_to_id(&target_id, g_repo, "refs/heads/haacked");
cl_git_pass(git_reference_lookup(&target_ref, g_repo, "refs/heads/haacked"));
cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/master"));
cl_git_pass(git_reference_set_target(&ref_out, ref, &target_id, message));
cl_reflog_check_entry(g_repo, "refs/heads/master", 0,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"258f0e2a959a364e40ed6603d5d44fbb24765b10",
NULL, message);
git_reference_free(target_ref);
git_reference_free(ref);
git_reference_free(ref_out);
}
#define NEW_BRANCH_NAME "new-branch-on-the-block"
void test_refs_reflog_messages__creating_branches_default_messages(void)
{
git_buf buf = GIT_BUF_INIT;
git_annotated_commit *annotated;
git_object *obj;
git_commit *target;
git_reference *branch1, *branch2;
cl_git_pass(git_revparse_single(&obj, g_repo, "e90810b8df3"));
cl_git_pass(git_commit_lookup(&target, g_repo, git_object_id(obj)));
git_object_free(obj);
cl_git_pass(git_branch_create(&branch1, g_repo, NEW_BRANCH_NAME, target, false));
cl_git_pass(git_buf_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target))));
cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0,
GIT_OID_HEX_ZERO,
git_oid_tostr_s(git_commit_id(target)),
g_email, git_buf_cstr(&buf));
cl_git_pass(git_reference_remove(g_repo, "refs/heads/" NEW_BRANCH_NAME));
cl_git_pass(git_annotated_commit_from_revspec(&annotated, g_repo, "e90810b8df3"));
cl_git_pass(git_branch_create_from_annotated(&branch2, g_repo, NEW_BRANCH_NAME, annotated, true));
cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0,
GIT_OID_HEX_ZERO,
git_oid_tostr_s(git_commit_id(target)),
g_email, "branch: Created from e90810b8df3");
git_annotated_commit_free(annotated);
git_buf_dispose(&buf);
git_commit_free(target);
git_reference_free(branch1);
git_reference_free(branch2);
}
void test_refs_reflog_messages__moving_branch_default_message(void)
{
git_reference *branch;
git_reference *new_branch;
git_oid id;
cl_git_pass(git_reference_lookup(&branch, g_repo, "refs/heads/master"));
git_oid_cpy(&id, git_reference_target(branch));
cl_git_pass(git_branch_move(&new_branch, branch, "master2", 0));
cl_reflog_check_entry(g_repo, git_reference_name(new_branch), 0,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
g_email,
"branch: renamed refs/heads/master to refs/heads/master2");
git_reference_free(branch);
git_reference_free(new_branch);
}
void test_refs_reflog_messages__detaching_head_default_message(void)
{
git_reference *ref;
cl_assert_equal_i(false, git_repository_head_detached(g_repo));
cl_git_pass(git_repository_detach_head(g_repo));
cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
NULL, "checkout: moving from master to a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
cl_assert_equal_i(true, git_repository_head_detached(g_repo));
/* take the repo back to its original state */
cl_git_pass(git_reference_symbolic_create(&ref, g_repo, "HEAD", "refs/heads/master",
true, "REATTACH"));
cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
NULL, "REATTACH");
cl_assert_equal_i(false, git_repository_head_detached(g_repo));
git_reference_free(ref);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/refs/reflog/reflog_helpers.h
|
size_t reflog_entrycount(git_repository *repo, const char *name);
#define cl_reflog_check_entry(repo, reflog, idx, old_spec, new_spec, email, message) \
cl_reflog_check_entry_(repo, reflog, idx, old_spec, new_spec, email, message, __FILE__, __LINE__)
void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx,
const char *old_spec, const char *new_spec,
const char *email, const char *message, const char *file, int line);
void reflog_print(git_repository *repo, const char *reflog_name);
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/reset/reset_helpers.c
|
#include "clar_libgit2.h"
#include "reset_helpers.h"
void reflog_check(git_repository *repo, const char *refname,
size_t exp_count, const char *exp_email, const char *exp_msg)
{
git_reflog *log;
const git_reflog_entry *entry;
GIT_UNUSED(exp_email);
cl_git_pass(git_reflog_read(&log, repo, refname));
cl_assert_equal_i(exp_count, git_reflog_entrycount(log));
entry = git_reflog_entry_byindex(log, 0);
if (exp_msg)
cl_assert_equal_s(exp_msg, git_reflog_entry_message(entry));
git_reflog_free(log);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/reset/reset_helpers.h
|
#include "common.h"
#define KNOWN_COMMIT_IN_BARE_REPO "e90810b8df3e80c413d903f631643c716887138d"
#define KNOWN_COMMIT_IN_ATTR_REPO "217878ab49e1314388ea2e32dc6fdb58a1b969e0"
void reflog_check(git_repository *repo, const char *refname,
size_t exp_count, const char *exp_email, const char *exp_msg);
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/reset/soft.c
|
#include "clar_libgit2.h"
#include "posix.h"
#include "reset_helpers.h"
#include "path.h"
#include "repo/repo_helpers.h"
static git_repository *repo;
static git_object *target;
void test_reset_soft__initialize(void)
{
repo = cl_git_sandbox_init("testrepo.git");
}
void test_reset_soft__cleanup(void)
{
git_object_free(target);
target = NULL;
cl_git_sandbox_cleanup();
}
static void assert_reset_soft(bool should_be_detached)
{
git_oid oid;
cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
cl_git_fail(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO));
cl_git_pass(git_revparse_single(&target, repo, KNOWN_COMMIT_IN_BARE_REPO));
cl_assert(git_repository_head_detached(repo) == should_be_detached);
cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL));
cl_assert(git_repository_head_detached(repo) == should_be_detached);
cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
cl_git_pass(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO));
}
void test_reset_soft__can_reset_the_non_detached_Head_to_the_specified_commit(void)
{
assert_reset_soft(false);
}
void test_reset_soft__can_reset_the_detached_Head_to_the_specified_commit(void)
{
git_repository_detach_head(repo);
assert_reset_soft(true);
}
void test_reset_soft__resetting_to_the_commit_pointed_at_by_the_Head_does_not_change_the_target_of_the_Head(void)
{
git_oid oid;
char raw_head_oid[GIT_OID_HEXSZ + 1];
cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
git_oid_fmt(raw_head_oid, &oid);
raw_head_oid[GIT_OID_HEXSZ] = '\0';
cl_git_pass(git_revparse_single(&target, repo, raw_head_oid));
cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL));
cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
cl_git_pass(git_oid_streq(&oid, raw_head_oid));
}
void test_reset_soft__resetting_to_a_tag_sets_the_Head_to_the_peeled_commit(void)
{
git_oid oid;
/* b25fa35 is a tag, pointing to another tag which points to commit e90810b */
cl_git_pass(git_revparse_single(&target, repo, "b25fa35"));
cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL));
cl_assert(git_repository_head_detached(repo) == false);
cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
cl_git_pass(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO));
}
void test_reset_soft__cannot_reset_to_a_tag_not_pointing_at_a_commit(void)
{
/* 53fc32d is the tree of commit e90810b */
cl_git_pass(git_revparse_single(&target, repo, "53fc32d"));
cl_git_fail(git_reset(repo, target, GIT_RESET_SOFT, NULL));
git_object_free(target);
/* 521d87c is an annotated tag pointing to a blob */
cl_git_pass(git_revparse_single(&target, repo, "521d87c"));
cl_git_fail(git_reset(repo, target, GIT_RESET_SOFT, NULL));
}
void test_reset_soft__resetting_against_an_unborn_head_repo_makes_the_head_no_longer_unborn(void)
{
git_reference *head;
cl_git_pass(git_revparse_single(&target, repo, KNOWN_COMMIT_IN_BARE_REPO));
make_head_unborn(repo, NON_EXISTING_HEAD);
cl_assert_equal_i(true, git_repository_head_unborn(repo));
cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL));
cl_assert_equal_i(false, git_repository_head_unborn(repo));
cl_git_pass(git_reference_lookup(&head, repo, NON_EXISTING_HEAD));
cl_assert_equal_i(0, git_oid_streq(git_reference_target(head), KNOWN_COMMIT_IN_BARE_REPO));
git_reference_free(head);
}
void test_reset_soft__fails_when_merging(void)
{
git_buf merge_head_path = GIT_BUF_INIT;
cl_git_pass(git_repository_detach_head(repo));
cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
cl_git_mkfile(git_buf_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
cl_git_pass(git_revparse_single(&target, repo, KNOWN_COMMIT_IN_BARE_REPO));
cl_assert_equal_i(GIT_EUNMERGED, git_reset(repo, target, GIT_RESET_SOFT, NULL));
cl_git_pass(p_unlink(git_buf_cstr(&merge_head_path)));
git_buf_dispose(&merge_head_path);
}
void test_reset_soft__fails_when_index_contains_conflicts_independently_of_MERGE_HEAD_file_existence(void)
{
git_index *index;
git_reference *head;
git_buf merge_head_path = GIT_BUF_INIT;
cl_git_sandbox_cleanup();
repo = cl_git_sandbox_init("mergedrepo");
cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
cl_git_pass(p_unlink(git_buf_cstr(&merge_head_path)));
git_buf_dispose(&merge_head_path);
cl_git_pass(git_repository_index(&index, repo));
cl_assert_equal_i(true, git_index_has_conflicts(index));
git_index_free(index);
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel(&target, head, GIT_OBJECT_COMMIT));
git_reference_free(head);
cl_assert_equal_i(GIT_EUNMERGED, git_reset(repo, target, GIT_RESET_SOFT, NULL));
}
void test_reset_soft__reflog_is_correct(void)
{
git_annotated_commit *annotated;
const char *exp_msg = "checkout: moving from br2 to master";
const char *master_msg = "commit: checking in";
reflog_check(repo, "HEAD", 7, "[email protected]", exp_msg);
reflog_check(repo, "refs/heads/master", 2, "[email protected]", master_msg);
/* Branch not moving, no reflog entry */
cl_git_pass(git_revparse_single(&target, repo, "HEAD^{commit}"));
cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL));
reflog_check(repo, "HEAD", 7, "[email protected]", exp_msg);
reflog_check(repo, "refs/heads/master", 2, "[email protected]", master_msg);
git_object_free(target);
/* Moved branch, expect id in message */
exp_msg = "reset: moving to be3563ae3f795b2b4353bcce3a527ad0a4f7f644";
cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL));
reflog_check(repo, "HEAD", 8, "[email protected]", exp_msg);
reflog_check(repo, "refs/heads/master", 3, NULL, exp_msg);
/* Moved branch, expect message with annotated string */
exp_msg = "reset: moving to HEAD~^{commit}";
cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "HEAD~^{commit}"));
cl_git_pass(git_reset_from_annotated(repo, annotated, GIT_RESET_SOFT, NULL));
reflog_check(repo, "HEAD", 9, "[email protected]", exp_msg);
reflog_check(repo, "refs/heads/master", 4, NULL, exp_msg);
git_annotated_commit_free(annotated);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/reset/mixed.c
|
#include "clar_libgit2.h"
#include "posix.h"
#include "reset_helpers.h"
#include "path.h"
static git_repository *repo;
static git_object *target;
void test_reset_mixed__initialize(void)
{
repo = cl_git_sandbox_init("attr");
target = NULL;
}
void test_reset_mixed__cleanup(void)
{
git_object_free(target);
target = NULL;
cl_git_sandbox_cleanup();
}
void test_reset_mixed__cannot_reset_in_a_bare_repository(void)
{
git_repository *bare;
cl_git_pass(git_repository_open(&bare, cl_fixture("testrepo.git")));
cl_assert(git_repository_is_bare(bare) == true);
cl_git_pass(git_revparse_single(&target, bare, KNOWN_COMMIT_IN_BARE_REPO));
cl_assert_equal_i(GIT_EBAREREPO, git_reset(bare, target, GIT_RESET_MIXED, NULL));
git_repository_free(bare);
}
void test_reset_mixed__resetting_refreshes_the_index_to_the_commit_tree(void)
{
unsigned int status;
cl_git_pass(git_status_file(&status, repo, "macro_bad"));
cl_assert(status == GIT_STATUS_CURRENT);
cl_git_pass(git_revparse_single(&target, repo, "605812a"));
cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
cl_git_pass(git_status_file(&status, repo, "macro_bad"));
cl_assert(status == GIT_STATUS_WT_NEW);
}
void test_reset_mixed__reflog_is_correct(void)
{
git_buf buf = GIT_BUF_INIT;
git_annotated_commit *annotated;
const char *exp_msg = "commit: Updating test data so we can test inter-hunk-context";
reflog_check(repo, "HEAD", 9, "[email protected]", exp_msg);
reflog_check(repo, "refs/heads/master", 9, "[email protected]", exp_msg);
/* Branch not moving, no reflog entry */
cl_git_pass(git_revparse_single(&target, repo, "HEAD^{commit}"));
cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
reflog_check(repo, "HEAD", 9, "[email protected]", exp_msg);
reflog_check(repo, "refs/heads/master", 9, "[email protected]", exp_msg);
git_object_free(target);
target = NULL;
/* Moved branch, expect id in message */
cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
git_buf_clear(&buf);
cl_git_pass(git_buf_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
reflog_check(repo, "HEAD", 10, NULL, git_buf_cstr(&buf));
reflog_check(repo, "refs/heads/master", 10, NULL, git_buf_cstr(&buf));
git_buf_dispose(&buf);
/* Moved branch, expect revspec in message */
exp_msg = "reset: moving to HEAD~^{commit}";
cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "HEAD~^{commit}"));
cl_git_pass(git_reset_from_annotated(repo, annotated, GIT_RESET_MIXED, NULL));
reflog_check(repo, "HEAD", 11, NULL, exp_msg);
reflog_check(repo, "refs/heads/master", 11, NULL, exp_msg);
git_annotated_commit_free(annotated);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/reset/default.c
|
#include "clar_libgit2.h"
#include "posix.h"
#include "reset_helpers.h"
#include "path.h"
static git_repository *_repo;
static git_object *_target;
static git_strarray _pathspecs;
static git_index *_index;
static void initialize(const char *repo_name)
{
_repo = cl_git_sandbox_init(repo_name);
cl_git_pass(git_repository_index(&_index, _repo));
_target = NULL;
_pathspecs.strings = NULL;
_pathspecs.count = 0;
}
void test_reset_default__initialize(void)
{
}
void test_reset_default__cleanup(void)
{
git_object_free(_target);
_target = NULL;
git_index_free(_index);
_index = NULL;
cl_git_sandbox_cleanup();
}
static void assert_content_in_index(
git_strarray *pathspecs,
bool should_exist,
git_strarray *expected_shas)
{
size_t i, pos;
int error;
for (i = 0; i < pathspecs->count; i++) {
error = git_index_find(&pos, _index, pathspecs->strings[i]);
if (should_exist) {
const git_index_entry *entry;
cl_assert(error != GIT_ENOTFOUND);
entry = git_index_get_byindex(_index, pos);
cl_assert(entry != NULL);
if (!expected_shas)
continue;
cl_git_pass(git_oid_streq(&entry->id, expected_shas->strings[i]));
} else
cl_assert_equal_i(should_exist, error != GIT_ENOTFOUND);
}
}
void test_reset_default__resetting_filepaths_against_a_null_target_removes_them_from_the_index(void)
{
char *paths[] = { "staged_changes", "staged_new_file" };
initialize("status");
_pathspecs.strings = paths;
_pathspecs.count = 2;
assert_content_in_index(&_pathspecs, true, NULL);
cl_git_pass(git_reset_default(_repo, NULL, &_pathspecs));
assert_content_in_index(&_pathspecs, false, NULL);
}
/*
* $ git ls-files --cached -s --abbrev=7 -- "staged*"
* 100644 55d316c 0 staged_changes
* 100644 a6be623 0 staged_changes_file_deleted
* ...
*
* $ git reset 0017bd4 -- staged_changes staged_changes_file_deleted
* Unstaged changes after reset:
* ...
*
* $ git ls-files --cached -s --abbrev=7 -- "staged*"
* 100644 32504b7 0 staged_changes
* 100644 061d42a 0 staged_changes_file_deleted
* ...
*/
void test_reset_default__resetting_filepaths_replaces_their_corresponding_index_entries(void)
{
git_strarray before, after;
char *paths[] = { "staged_changes", "staged_changes_file_deleted" };
char *before_shas[] = { "55d316c9ba708999f1918e9677d01dfcae69c6b9",
"a6be623522ce87a1d862128ac42672604f7b468b" };
char *after_shas[] = { "32504b727382542f9f089e24fddac5e78533e96c",
"061d42a44cacde5726057b67558821d95db96f19" };
initialize("status");
_pathspecs.strings = paths;
_pathspecs.count = 2;
before.strings = before_shas;
before.count = 2;
after.strings = after_shas;
after.count = 2;
cl_git_pass(git_revparse_single(&_target, _repo, "0017bd4"));
assert_content_in_index(&_pathspecs, true, &before);
cl_git_pass(git_reset_default(_repo, _target, &_pathspecs));
assert_content_in_index(&_pathspecs, true, &after);
}
/*
* $ git ls-files --cached -s --abbrev=7 -- conflicts-one.txt
* 100644 1f85ca5 1 conflicts-one.txt
* 100644 6aea5f2 2 conflicts-one.txt
* 100644 516bd85 3 conflicts-one.txt
*
* $ git reset 9a05ccb -- conflicts-one.txt
* Unstaged changes after reset:
* ...
*
* $ git ls-files --cached -s --abbrev=7 -- conflicts-one.txt
* 100644 1f85ca5 0 conflicts-one.txt
*
*/
void test_reset_default__resetting_filepaths_clears_previous_conflicts(void)
{
const git_index_entry *conflict_entry[3];
git_strarray after;
char *paths[] = { "conflicts-one.txt" };
char *after_shas[] = { "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81" };
initialize("mergedrepo");
_pathspecs.strings = paths;
_pathspecs.count = 1;
after.strings = after_shas;
after.count = 1;
cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1],
&conflict_entry[2], _index, "conflicts-one.txt"));
cl_git_pass(git_revparse_single(&_target, _repo, "9a05ccb"));
cl_git_pass(git_reset_default(_repo, _target, &_pathspecs));
assert_content_in_index(&_pathspecs, true, &after);
cl_assert_equal_i(GIT_ENOTFOUND, git_index_conflict_get(&conflict_entry[0],
&conflict_entry[1], &conflict_entry[2], _index, "conflicts-one.txt"));
}
/*
$ git reset HEAD -- "I_am_not_there.txt" "me_neither.txt"
Unstaged changes after reset:
...
*/
void test_reset_default__resetting_unknown_filepaths_does_not_fail(void)
{
char *paths[] = { "I_am_not_there.txt", "me_neither.txt" };
initialize("status");
_pathspecs.strings = paths;
_pathspecs.count = 2;
assert_content_in_index(&_pathspecs, false, NULL);
cl_git_pass(git_revparse_single(&_target, _repo, "HEAD"));
cl_git_pass(git_reset_default(_repo, _target, &_pathspecs));
assert_content_in_index(&_pathspecs, false, NULL);
}
void test_reset_default__staged_rename_reset_delete(void)
{
git_index_entry entry;
const git_index_entry *existing;
char *paths[] = { "new.txt" };
initialize("testrepo2");
existing = git_index_get_bypath(_index, "new.txt", 0);
cl_assert(existing);
memcpy(&entry, existing, sizeof(entry));
cl_git_pass(git_index_remove_bypath(_index, "new.txt"));
entry.path = "renamed.txt";
cl_git_pass(git_index_add(_index, &entry));
_pathspecs.strings = paths;
_pathspecs.count = 1;
assert_content_in_index(&_pathspecs, false, NULL);
cl_git_pass(git_revparse_single(&_target, _repo, "HEAD"));
cl_git_pass(git_reset_default(_repo, _target, &_pathspecs));
assert_content_in_index(&_pathspecs, true, NULL);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/reset/hard.c
|
#include "clar_libgit2.h"
#include "posix.h"
#include "reset_helpers.h"
#include "path.h"
#include "futils.h"
static git_repository *repo;
static git_object *target;
void test_reset_hard__initialize(void)
{
repo = cl_git_sandbox_init("status");
target = NULL;
}
void test_reset_hard__cleanup(void)
{
if (target != NULL) {
git_object_free(target);
target = NULL;
}
cl_git_sandbox_cleanup();
}
static int strequal_ignore_eol(const char *exp, const char *str)
{
while (*exp && *str) {
if (*exp != *str) {
while (*exp == '\r' || *exp == '\n') ++exp;
while (*str == '\r' || *str == '\n') ++str;
if (*exp != *str)
return false;
} else {
exp++; str++;
}
}
return (!*exp && !*str);
}
void test_reset_hard__resetting_reverts_modified_files(void)
{
git_buf path = GIT_BUF_INIT, content = GIT_BUF_INIT;
int i;
static const char *files[4] = {
"current_file",
"modified_file",
"staged_new_file",
"staged_changes_modified_file" };
static const char *before[4] = {
"current_file\n",
"modified_file\nmodified_file\n",
"staged_new_file\n",
"staged_changes_modified_file\nstaged_changes_modified_file\nstaged_changes_modified_file\n"
};
static const char *after[4] = {
"current_file\n",
"modified_file\n",
NULL,
"staged_changes_modified_file\n"
};
const char *wd = git_repository_workdir(repo);
cl_assert(wd);
for (i = 0; i < 4; ++i) {
cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
cl_git_pass(git_futils_readbuffer(&content, path.ptr));
cl_assert_equal_s(before[i], content.ptr);
}
cl_git_pass(git_revparse_single(&target, repo, "26a125e"));
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
for (i = 0; i < 4; ++i) {
cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
if (after[i]) {
cl_git_pass(git_futils_readbuffer(&content, path.ptr));
cl_assert(strequal_ignore_eol(after[i], content.ptr));
} else {
cl_assert(!git_path_exists(path.ptr));
}
}
git_buf_dispose(&content);
git_buf_dispose(&path);
}
void test_reset_hard__cannot_reset_in_a_bare_repository(void)
{
git_repository *bare;
cl_git_pass(git_repository_open(&bare, cl_fixture("testrepo.git")));
cl_assert(git_repository_is_bare(bare) == true);
cl_git_pass(git_revparse_single(&target, bare, KNOWN_COMMIT_IN_BARE_REPO));
cl_assert_equal_i(GIT_EBAREREPO, git_reset(bare, target, GIT_RESET_HARD, NULL));
git_repository_free(bare);
}
static void index_entry_init(git_index *index, int side, git_oid *oid)
{
git_index_entry entry;
memset(&entry, 0x0, sizeof(git_index_entry));
entry.path = "conflicting_file";
GIT_INDEX_ENTRY_STAGE_SET(&entry, side);
entry.mode = 0100644;
git_oid_cpy(&entry.id, oid);
cl_git_pass(git_index_add(index, &entry));
}
static void unmerged_index_init(git_index *index, int entries)
{
int write_ancestor = 1;
int write_ours = 2;
int write_theirs = 4;
git_oid ancestor, ours, theirs;
git_oid_fromstr(&ancestor, "452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
git_oid_fromstr(&ours, "32504b727382542f9f089e24fddac5e78533e96c");
git_oid_fromstr(&theirs, "061d42a44cacde5726057b67558821d95db96f19");
cl_git_rewritefile("status/conflicting_file", "conflicting file\n");
if (entries & write_ancestor)
index_entry_init(index, 1, &ancestor);
if (entries & write_ours)
index_entry_init(index, 2, &ours);
if (entries & write_theirs)
index_entry_init(index, 3, &theirs);
}
void test_reset_hard__resetting_reverts_unmerged(void)
{
git_index *index;
int entries;
/* Ensure every permutation of non-zero stage entries results in the
* path being cleaned up. */
for (entries = 1; entries < 8; entries++) {
cl_git_pass(git_repository_index(&index, repo));
unmerged_index_init(index, entries);
cl_git_pass(git_index_write(index));
cl_git_pass(git_revparse_single(&target, repo, "26a125e"));
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
cl_assert(git_path_exists("status/conflicting_file") == 0);
git_object_free(target);
target = NULL;
git_index_free(index);
}
}
void test_reset_hard__cleans_up_merge(void)
{
git_buf merge_head_path = GIT_BUF_INIT,
merge_msg_path = GIT_BUF_INIT,
merge_mode_path = GIT_BUF_INIT,
orig_head_path = GIT_BUF_INIT;
cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
cl_git_mkfile(git_buf_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
cl_git_pass(git_buf_joinpath(&merge_msg_path, git_repository_path(repo), "MERGE_MSG"));
cl_git_mkfile(git_buf_cstr(&merge_msg_path), "Merge commit 0017bd4ab1ec30440b17bae1680cff124ab5f1f6\n");
cl_git_pass(git_buf_joinpath(&merge_mode_path, git_repository_path(repo), "MERGE_MODE"));
cl_git_mkfile(git_buf_cstr(&merge_mode_path), "");
cl_git_pass(git_buf_joinpath(&orig_head_path, git_repository_path(repo), "ORIG_HEAD"));
cl_git_mkfile(git_buf_cstr(&orig_head_path), "0017bd4ab1ec30440b17bae1680cff124ab5f1f6");
cl_git_pass(git_revparse_single(&target, repo, "0017bd4"));
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
cl_assert(!git_path_exists(git_buf_cstr(&merge_head_path)));
cl_assert(!git_path_exists(git_buf_cstr(&merge_msg_path)));
cl_assert(!git_path_exists(git_buf_cstr(&merge_mode_path)));
cl_assert(git_path_exists(git_buf_cstr(&orig_head_path)));
cl_git_pass(p_unlink(git_buf_cstr(&orig_head_path)));
git_buf_dispose(&merge_head_path);
git_buf_dispose(&merge_msg_path);
git_buf_dispose(&merge_mode_path);
git_buf_dispose(&orig_head_path);
}
void test_reset_hard__reflog_is_correct(void)
{
git_buf buf = GIT_BUF_INIT;
git_annotated_commit *annotated;
const char *exp_msg = "commit: Add a file which name should appear before the "
"\"subdir/\" folder while being dealt with by the treewalker";
reflog_check(repo, "HEAD", 3, "[email protected]", exp_msg);
reflog_check(repo, "refs/heads/master", 3, "[email protected]", exp_msg);
/* Branch not moving, no reflog entry */
cl_git_pass(git_revparse_single(&target, repo, "HEAD^{commit}"));
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
reflog_check(repo, "HEAD", 3, "[email protected]", exp_msg);
reflog_check(repo, "refs/heads/master", 3, "[email protected]", exp_msg);
git_object_free(target);
/* Moved branch, expect id in message */
cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
cl_git_pass(git_buf_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
reflog_check(repo, "HEAD", 4, NULL, git_buf_cstr(&buf));
reflog_check(repo, "refs/heads/master", 4, NULL, git_buf_cstr(&buf));
git_buf_dispose(&buf);
/* Moved branch, expect revspec in message */
exp_msg = "reset: moving to HEAD~^{commit}";
cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "HEAD~^{commit}"));
cl_git_pass(git_reset_from_annotated(repo, annotated, GIT_RESET_HARD, NULL));
reflog_check(repo, "HEAD", 5, NULL, exp_msg);
reflog_check(repo, "refs/heads/master", 5, NULL, exp_msg);
git_annotated_commit_free(annotated);
}
void test_reset_hard__switch_file_to_dir(void)
{
git_index_entry entry = {{ 0 }};
git_index *idx;
git_odb *odb;
git_object *commit;
git_tree *tree;
git_signature *sig;
git_oid src_tree_id, tgt_tree_id;
git_oid src_id, tgt_id;
cl_git_pass(git_repository_odb(&odb, repo));
cl_git_pass(git_odb_write(&entry.id, odb, "", 0, GIT_OBJECT_BLOB));
git_odb_free(odb);
entry.mode = GIT_FILEMODE_BLOB;
cl_git_pass(git_index_new(&idx));
cl_git_pass(git_signature_now(&sig, "foo", "bar"));
/* Create the old tree */
entry.path = "README";
cl_git_pass(git_index_add(idx, &entry));
entry.path = "dir";
cl_git_pass(git_index_add(idx, &entry));
cl_git_pass(git_index_write_tree_to(&src_tree_id, idx, repo));
cl_git_pass(git_index_clear(idx));
cl_git_pass(git_tree_lookup(&tree, repo, &src_tree_id));
cl_git_pass(git_commit_create(&src_id, repo, NULL, sig, sig, NULL, "foo", tree, 0, NULL));
git_tree_free(tree);
/* Create the new tree */
entry.path = "README";
cl_git_pass(git_index_add(idx, &entry));
entry.path = "dir/FILE";
cl_git_pass(git_index_add(idx, &entry));
cl_git_pass(git_index_write_tree_to(&tgt_tree_id, idx, repo));
cl_git_pass(git_tree_lookup(&tree, repo, &tgt_tree_id));
cl_git_pass(git_commit_create(&tgt_id, repo, NULL, sig, sig, NULL, "foo", tree, 0, NULL));
git_tree_free(tree);
git_index_free(idx);
git_signature_free(sig);
/* Let's go to a known state of the src commit with the file named 'dir' */
cl_git_pass(git_object_lookup(&commit, repo, &src_id, GIT_OBJECT_COMMIT));
cl_git_pass(git_reset(repo, commit, GIT_RESET_HARD, NULL));
git_object_free(commit);
/* And now we move over to the commit with the directory named 'dir' */
cl_git_pass(git_object_lookup(&commit, repo, &tgt_id, GIT_OBJECT_COMMIT));
cl_git_pass(git_reset(repo, commit, GIT_RESET_HARD, NULL));
git_object_free(commit);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/describe/t6120.c
|
#include "clar_libgit2.h"
#include "describe_helpers.h"
#include "repository.h"
/* Ported from https://github.com/git/git/blob/adfc1857bdb090786fd9d22c1acec39371c76048/t/t6120-describe.sh */
static git_repository *repo;
void test_describe_t6120__initialize(void)
{
repo = cl_git_sandbox_init("describe");
}
void test_describe_t6120__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_describe_t6120__default(void)
{
git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
assert_describe("A-*", "HEAD", repo, &opts, &fmt_opts);
assert_describe("A-*", "HEAD^", repo, &opts, &fmt_opts);
assert_describe("R-*", "HEAD^^", repo, &opts, &fmt_opts);
assert_describe("A-*", "HEAD^^2", repo, &opts, &fmt_opts);
assert_describe("B", "HEAD^^2^", repo, &opts, &fmt_opts);
assert_describe("R-*", "HEAD^^^", repo, &opts, &fmt_opts);
}
void test_describe_t6120__tags(void)
{
git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
opts.describe_strategy = GIT_DESCRIBE_TAGS;
assert_describe("c-*", "HEAD", repo, &opts, &fmt_opts);
assert_describe("c-*", "HEAD^", repo, &opts, &fmt_opts);
assert_describe("e-*", "HEAD^^", repo, &opts, &fmt_opts);
assert_describe("c-*", "HEAD^^2", repo, &opts, &fmt_opts);
assert_describe("B", "HEAD^^2^", repo, &opts, &fmt_opts);
assert_describe("e", "HEAD^^^", repo, &opts, &fmt_opts);
}
void test_describe_t6120__all(void)
{
git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
opts.describe_strategy = GIT_DESCRIBE_ALL;
assert_describe("heads/master", "HEAD", repo, &opts, &fmt_opts);
assert_describe("tags/c-*", "HEAD^", repo, &opts, &fmt_opts);
assert_describe("tags/e", "HEAD^^^", repo, &opts, &fmt_opts);
}
void test_describe_t6120__longformat(void)
{
git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
fmt_opts.always_use_long_format = 1;
assert_describe("B-0-*", "HEAD^^2^", repo, &opts, &fmt_opts);
assert_describe("A-3-*", "HEAD^^2", repo, &opts, &fmt_opts);
}
void test_describe_t6120__firstparent(void)
{
git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
opts.describe_strategy = GIT_DESCRIBE_TAGS;
assert_describe("c-7-*", "HEAD", repo, &opts, &fmt_opts);
opts.only_follow_first_parent = 1;
assert_describe("e-3-*", "HEAD", repo, &opts, &fmt_opts);
}
void test_describe_t6120__workdir(void)
{
git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
assert_describe_workdir("A-*[0-9a-f]", repo, &opts, &fmt_opts);
cl_git_mkfile("describe/file", "something different");
fmt_opts.dirty_suffix = "-dirty";
assert_describe_workdir("A-*[0-9a-f]-dirty", repo, &opts, &fmt_opts);
fmt_opts.dirty_suffix = ".mod";
assert_describe_workdir("A-*[0-9a-f].mod", repo, &opts, &fmt_opts);
}
static void commit_and_tag(
git_time_t *time,
const char *commit_msg,
const char *tag_name)
{
git_index *index;
git_oid commit_id;
git_reference *ref;
cl_git_pass(git_repository_index__weakptr(&index, repo));
cl_git_append2file("describe/file", "\n");
cl_git_pass(git_index_add_bypath(index, "file"));
cl_git_pass(git_index_write(index));
*time += 10;
cl_repo_commit_from_index(&commit_id, repo, NULL, *time, commit_msg);
if (tag_name == NULL)
return;
cl_git_pass(git_reference_create(&ref, repo, tag_name, &commit_id, 0, NULL));
git_reference_free(ref);
}
void test_describe_t6120__pattern(void)
{
git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
git_oid tag_id;
git_object *head;
git_signature *tagger;
git_time_t time;
/* set-up matching pattern tests */
cl_git_pass(git_revparse_single(&head, repo, "HEAD"));
time = 1380553019;
cl_git_pass(git_signature_new(&tagger, "tagger", "[email protected]", time, 0));
cl_git_pass(git_tag_create(&tag_id, repo, "test-annotated", head, tagger, "test-annotated", 0));
git_signature_free(tagger);
git_object_free(head);
commit_and_tag(&time, "one more", "refs/tags/test1-lightweight");
commit_and_tag(&time, "yet another", "refs/tags/test2-lightweight");
commit_and_tag(&time, "even more", NULL);
/* Exercize */
opts.pattern = "test-*";
assert_describe("test-annotated-*", "HEAD", repo, &opts, &fmt_opts);
opts.describe_strategy = GIT_DESCRIBE_TAGS;
opts.pattern = "test1-*";
assert_describe("test1-lightweight-*", "HEAD", repo, &opts, &fmt_opts);
opts.pattern = "test2-*";
assert_describe("test2-lightweight-*", "HEAD", repo, &opts, &fmt_opts);
fmt_opts.always_use_long_format = 1;
assert_describe("test2-lightweight-*", "HEAD^", repo, &opts, &fmt_opts);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/describe/describe.c
|
#include "clar_libgit2.h"
#include "describe_helpers.h"
void test_describe_describe__can_describe_against_a_bare_repo(void)
{
git_repository *repo;
git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT;
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
assert_describe("hard_tag", "HEAD", repo, &opts, &fmt_opts);
opts.show_commit_oid_as_fallback = 1;
assert_describe("be3563a*", "HEAD^", repo, &opts, &fmt_opts);
git_repository_free(repo);
}
static int delete_cb(git_reference *ref, void *payload)
{
GIT_UNUSED(payload);
cl_git_pass(git_reference_delete(ref));
git_reference_free(ref);
return 0;
}
void test_describe_describe__describe_a_repo_with_no_refs(void)
{
git_repository *repo;
git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT;
git_buf buf = GIT_BUF_INIT;
git_object *object;
git_describe_result *result = NULL;
repo = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_revparse_single(&object, repo, "HEAD"));
cl_git_pass(git_reference_foreach(repo, delete_cb, NULL));
/* Impossible to describe without falling back to OIDs */
cl_git_fail(git_describe_commit(&result, object, &opts));
/* Try again with OID fallbacks */
opts.show_commit_oid_as_fallback = 1;
cl_git_pass(git_describe_commit(&result, object, &opts));
git_describe_result_free(result);
git_object_free(object);
git_buf_dispose(&buf);
cl_git_sandbox_cleanup();
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/describe/describe_helpers.c
|
#include "describe_helpers.h"
#include "wildmatch.h"
void assert_describe(
const char *expected_output,
const char *revparse_spec,
git_repository *repo,
git_describe_options *opts,
git_describe_format_options *fmt_opts)
{
git_object *object;
git_buf label = GIT_BUF_INIT;
git_describe_result *result;
cl_git_pass(git_revparse_single(&object, repo, revparse_spec));
cl_git_pass(git_describe_commit(&result, object, opts));
cl_git_pass(git_describe_format(&label, result, fmt_opts));
cl_must_pass(wildmatch(expected_output, git_buf_cstr(&label), 0));
git_describe_result_free(result);
git_object_free(object);
git_buf_dispose(&label);
}
void assert_describe_workdir(
const char *expected_output,
git_repository *repo,
git_describe_options *opts,
git_describe_format_options *fmt_opts)
{
git_buf label = GIT_BUF_INIT;
git_describe_result *result;
cl_git_pass(git_describe_workdir(&result, repo, opts));
cl_git_pass(git_describe_format(&label, result, fmt_opts));
cl_must_pass(wildmatch(expected_output, git_buf_cstr(&label), 0));
git_describe_result_free(result);
git_buf_dispose(&label);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/describe/describe_helpers.h
|
#include "clar_libgit2.h"
#include "buffer.h"
extern void assert_describe(
const char *expected_output,
const char *revparse_spec,
git_repository *repo,
git_describe_options *opts,
git_describe_format_options *fmt_opts);
extern void assert_describe_workdir(
const char *expected_output,
git_repository *repo,
git_describe_options *opts,
git_describe_format_options *fmt_opts);
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/mailmap/blame.c
|
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/blame.h"
#include "mailmap.h"
#include "mailmap_testdata.h"
static git_repository *g_repo;
static git_blame *g_blame;
void test_mailmap_blame__initialize(void)
{
g_repo = NULL;
g_blame = NULL;
}
void test_mailmap_blame__cleanup(void)
{
git_blame_free(g_blame);
cl_git_sandbox_cleanup();
}
void test_mailmap_blame__hunks(void)
{
size_t idx = 0;
const git_blame_hunk *hunk = NULL;
git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
g_repo = cl_git_sandbox_init("mailmap");
opts.flags |= GIT_BLAME_USE_MAILMAP;
cl_git_pass(git_blame_file(&g_blame, g_repo, "file.txt", &opts));
cl_assert(g_blame);
for (idx = 0; idx < ARRAY_SIZE(resolved); ++idx) {
hunk = git_blame_get_hunk_byline(g_blame, idx + 1);
cl_assert(hunk->final_signature != NULL);
cl_assert(hunk->orig_signature != NULL);
cl_assert_equal_s(hunk->final_signature->name, resolved[idx].real_name);
cl_assert_equal_s(hunk->final_signature->email, resolved[idx].real_email);
}
}
void test_mailmap_blame__hunks_no_mailmap(void)
{
size_t idx = 0;
const git_blame_hunk *hunk = NULL;
git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
g_repo = cl_git_sandbox_init("mailmap");
cl_git_pass(git_blame_file(&g_blame, g_repo, "file.txt", &opts));
cl_assert(g_blame);
for (idx = 0; idx < ARRAY_SIZE(resolved); ++idx) {
hunk = git_blame_get_hunk_byline(g_blame, idx + 1);
cl_assert(hunk->final_signature != NULL);
cl_assert(hunk->orig_signature != NULL);
cl_assert_equal_s(hunk->final_signature->name, resolved[idx].replace_name);
cl_assert_equal_s(hunk->final_signature->email, resolved[idx].replace_email);
}
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/mailmap/mailmap_testdata.h
|
#include "mailmap.h"
typedef struct mailmap_entry {
const char *real_name;
const char *real_email;
const char *replace_name;
const char *replace_email;
} mailmap_entry;
static const mailmap_entry resolved[] = {
{ "Brad", "[email protected]", "Brad", "[email protected]" },
{ "Brad L", "[email protected]", "Brad L", "[email protected]" },
{ "Some Dude", "[email protected]", "nick1", "[email protected]" },
{ "Other Author", "[email protected]", "nick2", "[email protected]" },
{ "nick3", "[email protected]", "nick3", "[email protected]" },
{ "Other Author", "[email protected]", "Some Garbage", "[email protected]" },
{ "Phil Hill", "[email protected]", "unknown", "[email protected]" },
{ "Joseph", "[email protected]", "Joseph", "[email protected]" },
{ "Santa Claus", "[email protected]", "Clause", "[email protected]" },
{ "Charles", "[email protected]", "Charles", "[email protected]" }
};
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/mailmap/basic.c
|
#include "clar.h"
#include "clar_libgit2.h"
#include "common.h"
#include "mailmap.h"
static git_mailmap *mailmap = NULL;
const char TEST_MAILMAP[] =
"Foo bar <[email protected]> <[email protected]> \n"
"Blatantly invalid line\n"
"Foo bar <[email protected]> <[email protected]>\n"
"<[email protected]> <[email protected]>\n"
"<[email protected]> Other Name <[email protected]>\n";
struct {
const char *real_name;
const char *real_email;
const char *replace_name;
const char *replace_email;
} expected[] = {
{ "Foo bar", "[email protected]", NULL, "[email protected]" },
{ "Foo bar", "[email protected]", NULL, "[email protected]" },
{ NULL, "[email protected]", NULL, "[email protected]" },
{ NULL, "[email protected]", "Other Name", "[email protected]" }
};
void test_mailmap_basic__initialize(void)
{
cl_git_pass(git_mailmap_from_buffer(
&mailmap, TEST_MAILMAP, strlen(TEST_MAILMAP)));
}
void test_mailmap_basic__cleanup(void)
{
git_mailmap_free(mailmap);
mailmap = NULL;
}
void test_mailmap_basic__entry(void)
{
size_t idx;
const git_mailmap_entry *entry;
/* Check that we have the expected # of entries */
cl_assert_equal_sz(ARRAY_SIZE(expected), git_vector_length(&mailmap->entries));
for (idx = 0; idx < ARRAY_SIZE(expected); ++idx) {
/* Try to look up each entry and make sure they match */
entry = git_mailmap_entry_lookup(
mailmap, expected[idx].replace_name, expected[idx].replace_email);
cl_assert(entry);
cl_assert_equal_s(entry->real_name, expected[idx].real_name);
cl_assert_equal_s(entry->real_email, expected[idx].real_email);
cl_assert_equal_s(entry->replace_name, expected[idx].replace_name);
cl_assert_equal_s(entry->replace_email, expected[idx].replace_email);
}
}
void test_mailmap_basic__lookup_not_found(void)
{
const git_mailmap_entry *entry = git_mailmap_entry_lookup(
mailmap, "Whoever", "[email protected]");
cl_assert(!entry);
}
void test_mailmap_basic__lookup(void)
{
const git_mailmap_entry *entry = git_mailmap_entry_lookup(
mailmap, "Typoed the name once", "[email protected]");
cl_assert(entry);
cl_assert_equal_s(entry->real_name, "Foo bar");
}
void test_mailmap_basic__empty_email_query(void)
{
const char *name;
const char *email;
cl_git_pass(git_mailmap_resolve(
&name, &email, mailmap, "Author name", "[email protected]"));
cl_assert_equal_s(name, "Author name");
cl_assert_equal_s(email, "[email protected]");
}
void test_mailmap_basic__name_matching(void)
{
const char *name;
const char *email;
cl_git_pass(git_mailmap_resolve(
&name, &email, mailmap, "Other Name", "[email protected]"));
cl_assert_equal_s(name, "Other Name");
cl_assert_equal_s(email, "[email protected]");
cl_git_pass(git_mailmap_resolve(
&name, &email, mailmap,
"Other Name That Doesn't Match", "[email protected]"));
cl_assert_equal_s(name, "Other Name That Doesn't Match");
cl_assert_equal_s(email, "[email protected]");
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/mailmap/parsing.c
|
#include "clar_libgit2.h"
#include "repository.h"
#include "git2/sys/repository.h"
#include "mailmap_testdata.h"
static git_repository *g_repo;
static git_mailmap *g_mailmap;
static git_config *g_config;
static const char string_mailmap[] =
"# Simple Comment line\n"
"<[email protected]> <[email protected]>\n"
"Some Dude <[email protected]> nick1 <[email protected]>\n"
"Other Author <[email protected]> nick2 <[email protected]>\n"
"Other Author <[email protected]> <[email protected]>\n"
"Phil Hill <[email protected]> # Comment at end of line\n"
"<[email protected]> Joseph <[email protected]>\n"
"Santa Claus <[email protected]> <[email protected]>\n"
"Untracked <[email protected]>";
static const mailmap_entry entries[] = {
{ NULL, "[email protected]", NULL, "[email protected]" },
{ "Some Dude", "[email protected]", "nick1", "[email protected]" },
{ "Other Author", "[email protected]", "nick2", "[email protected]" },
{ "Other Author", "[email protected]", NULL, "[email protected]" },
{ "Phil Hill", NULL, NULL, "[email protected]" },
{ NULL, "[email protected]", "Joseph", "[email protected]" },
{ "Santa Claus", "[email protected]", NULL, "[email protected]" },
/* This entry isn't in the bare repository */
{ "Untracked", NULL, NULL, "[email protected]" }
};
void test_mailmap_parsing__initialize(void)
{
g_repo = NULL;
g_mailmap = NULL;
g_config = NULL;
}
void test_mailmap_parsing__cleanup(void)
{
git_mailmap_free(g_mailmap);
git_config_free(g_config);
cl_git_sandbox_cleanup();
}
static void check_mailmap_entries(
const git_mailmap *mailmap, const mailmap_entry *entries, size_t entries_size)
{
const git_mailmap_entry *parsed;
size_t idx;
/* Check the correct # of entries were parsed */
cl_assert_equal_sz(entries_size, git_vector_length(&mailmap->entries));
/* Make sure looking up each entry succeeds */
for (idx = 0; idx < entries_size; ++idx) {
parsed = git_mailmap_entry_lookup(
mailmap, entries[idx].replace_name, entries[idx].replace_email);
cl_assert(parsed);
cl_assert_equal_s(parsed->real_name, entries[idx].real_name);
cl_assert_equal_s(parsed->real_email, entries[idx].real_email);
cl_assert_equal_s(parsed->replace_name, entries[idx].replace_name);
cl_assert_equal_s(parsed->replace_email, entries[idx].replace_email);
}
}
static void check_mailmap_resolve(
const git_mailmap *mailmap, const mailmap_entry *resolved, size_t resolved_size)
{
const char *resolved_name = NULL;
const char *resolved_email = NULL;
size_t idx;
/* Check that the resolver behaves correctly */
for (idx = 0; idx < resolved_size; ++idx) {
cl_git_pass(git_mailmap_resolve(
&resolved_name, &resolved_email, mailmap,
resolved[idx].replace_name, resolved[idx].replace_email));
cl_assert_equal_s(resolved_name, resolved[idx].real_name);
cl_assert_equal_s(resolved_email, resolved[idx].real_email);
}
}
static const mailmap_entry resolved_untracked[] = {
{ "Untracked", "[email protected]", "xx", "[email protected]" }
};
void test_mailmap_parsing__string(void)
{
cl_git_pass(git_mailmap_from_buffer(
&g_mailmap, string_mailmap, strlen(string_mailmap)));
/* We should have parsed all of the entries */
check_mailmap_entries(g_mailmap, entries, ARRAY_SIZE(entries));
/* Check that resolving the entries works */
check_mailmap_resolve(g_mailmap, resolved, ARRAY_SIZE(resolved));
check_mailmap_resolve(
g_mailmap, resolved_untracked, ARRAY_SIZE(resolved_untracked));
}
void test_mailmap_parsing__windows_string(void)
{
git_buf unixbuf = GIT_BUF_INIT;
git_buf winbuf = GIT_BUF_INIT;
/* Parse with windows-style line endings */
git_buf_attach_notowned(&unixbuf, string_mailmap, strlen(string_mailmap));
cl_git_pass(git_buf_lf_to_crlf(&winbuf, &unixbuf));
cl_git_pass(git_mailmap_from_buffer(&g_mailmap, winbuf.ptr, winbuf.size));
git_buf_dispose(&winbuf);
/* We should have parsed all of the entries */
check_mailmap_entries(g_mailmap, entries, ARRAY_SIZE(entries));
/* Check that resolving the entries works */
check_mailmap_resolve(g_mailmap, resolved, ARRAY_SIZE(resolved));
check_mailmap_resolve(
g_mailmap, resolved_untracked, ARRAY_SIZE(resolved_untracked));
}
void test_mailmap_parsing__fromrepo(void)
{
g_repo = cl_git_sandbox_init("mailmap");
cl_check(!git_repository_is_bare(g_repo));
cl_git_pass(git_mailmap_from_repository(&g_mailmap, g_repo));
/* We should have parsed all of the entries */
check_mailmap_entries(g_mailmap, entries, ARRAY_SIZE(entries));
/* Check that resolving the entries works */
check_mailmap_resolve(g_mailmap, resolved, ARRAY_SIZE(resolved));
check_mailmap_resolve(
g_mailmap, resolved_untracked, ARRAY_SIZE(resolved_untracked));
}
static const mailmap_entry resolved_bare[] = {
{ "xx", "[email protected]", "xx", "[email protected]" }
};
void test_mailmap_parsing__frombare(void)
{
g_repo = cl_git_sandbox_init("mailmap/.gitted");
cl_git_pass(git_repository_set_bare(g_repo));
cl_check(git_repository_is_bare(g_repo));
cl_git_pass(git_mailmap_from_repository(&g_mailmap, g_repo));
/* We should have parsed all of the entries, except for the untracked one */
check_mailmap_entries(g_mailmap, entries, ARRAY_SIZE(entries) - 1);
/* Check that resolving the entries works */
check_mailmap_resolve(g_mailmap, resolved, ARRAY_SIZE(resolved));
check_mailmap_resolve(
g_mailmap, resolved_bare, ARRAY_SIZE(resolved_bare));
}
static const mailmap_entry resolved_with_file_override[] = {
{ "Brad", "[email protected]", "Brad", "[email protected]" },
{ "Brad L", "[email protected]", "Brad L", "[email protected]" },
{ "Some Dude", "[email protected]", "nick1", "[email protected]" },
{ "Other Author", "[email protected]", "nick2", "[email protected]" },
{ "nick3", "[email protected]", "nick3", "[email protected]" },
{ "Other Author", "[email protected]", "Some Garbage", "[email protected]" },
{ "Joseph", "[email protected]", "Joseph", "[email protected]" },
{ "Santa Claus", "[email protected]", "Clause", "[email protected]" },
{ "Charles", "[email protected]", "Charles", "[email protected]" },
/* This name is overridden by file_override */
{ "File Override", "[email protected]", "unknown", "[email protected]" },
{ "Other Name", "[email protected]", "override", "[email protected]" }
};
void test_mailmap_parsing__file_config(void)
{
g_repo = cl_git_sandbox_init("mailmap");
cl_git_pass(git_repository_config(&g_config, g_repo));
cl_git_pass(git_config_set_string(
g_config, "mailmap.file", cl_fixture("mailmap/file_override")));
cl_git_pass(git_mailmap_from_repository(&g_mailmap, g_repo));
/* Check we don't have duplicate entries */
cl_assert_equal_sz(git_vector_length(&g_mailmap->entries), 9);
/* Check that resolving the entries works */
check_mailmap_resolve(
g_mailmap, resolved_with_file_override,
ARRAY_SIZE(resolved_with_file_override));
}
static const mailmap_entry resolved_with_blob_override[] = {
{ "Brad", "[email protected]", "Brad", "[email protected]" },
{ "Brad L", "[email protected]", "Brad L", "[email protected]" },
{ "Some Dude", "[email protected]", "nick1", "[email protected]" },
{ "Other Author", "[email protected]", "nick2", "[email protected]" },
{ "nick3", "[email protected]", "nick3", "[email protected]" },
{ "Other Author", "[email protected]", "Some Garbage", "[email protected]" },
{ "Joseph", "[email protected]", "Joseph", "[email protected]" },
{ "Santa Claus", "[email protected]", "Clause", "[email protected]" },
{ "Charles", "[email protected]", "Charles", "[email protected]" },
/* This name is overridden by blob_override */
{ "Blob Override", "[email protected]", "unknown", "[email protected]" },
{ "Other Name", "[email protected]", "override", "[email protected]" }
};
void test_mailmap_parsing__blob_config(void)
{
g_repo = cl_git_sandbox_init("mailmap");
cl_git_pass(git_repository_config(&g_config, g_repo));
cl_git_pass(git_config_set_string(
g_config, "mailmap.blob", "HEAD:blob_override"));
cl_git_pass(git_mailmap_from_repository(&g_mailmap, g_repo));
/* Check we don't have duplicate entries */
cl_assert_equal_sz(git_vector_length(&g_mailmap->entries), 9);
/* Check that resolving the entries works */
check_mailmap_resolve(
g_mailmap, resolved_with_blob_override,
ARRAY_SIZE(resolved_with_blob_override));
}
static const mailmap_entry bare_resolved_with_blob_override[] = {
/* As mailmap.blob is set, we won't load HEAD:.mailmap */
{ "Brad", "[email protected]", "Brad", "[email protected]" },
{ "Brad L", "[email protected]", "Brad L", "[email protected]" },
{ "nick1", "[email protected]", "nick1", "[email protected]" },
{ "nick2", "[email protected]", "nick2", "[email protected]" },
{ "nick3", "[email protected]", "nick3", "[email protected]" },
{ "Some Garbage", "[email protected]", "Some Garbage", "[email protected]" },
{ "Joseph", "[email protected]", "Joseph", "[email protected]" },
{ "Clause", "[email protected]", "Clause", "[email protected]" },
{ "Charles", "[email protected]", "Charles", "[email protected]" },
/* This name is overridden by blob_override */
{ "Blob Override", "[email protected]", "unknown", "[email protected]" },
{ "Other Name", "[email protected]", "override", "[email protected]" }
};
void test_mailmap_parsing__bare_blob_config(void)
{
g_repo = cl_git_sandbox_init("mailmap/.gitted");
cl_git_pass(git_repository_set_bare(g_repo));
cl_check(git_repository_is_bare(g_repo));
cl_git_pass(git_repository_config(&g_config, g_repo));
cl_git_pass(git_config_set_string(
g_config, "mailmap.blob", "HEAD:blob_override"));
cl_git_pass(git_mailmap_from_repository(&g_mailmap, g_repo));
/* Check that we only have the 2 entries */
cl_assert_equal_sz(git_vector_length(&g_mailmap->entries), 2);
/* Check that resolving the entries works */
check_mailmap_resolve(
g_mailmap, bare_resolved_with_blob_override,
ARRAY_SIZE(bare_resolved_with_blob_override));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/transport/register.c
|
#include "clar_libgit2.h"
#include "git2/sys/transport.h"
static git_transport _transport = GIT_TRANSPORT_INIT;
static int dummy_transport(git_transport **transport, git_remote *owner, void *param)
{
*transport = &_transport;
GIT_UNUSED(owner);
GIT_UNUSED(param);
return 0;
}
void test_transport_register__custom_transport(void)
{
git_transport *transport;
cl_git_pass(git_transport_register("something", dummy_transport, NULL));
cl_git_pass(git_transport_new(&transport, NULL, "something://somepath"));
cl_assert(transport == &_transport);
cl_git_pass(git_transport_unregister("something"));
}
void test_transport_register__custom_transport_error_doubleregister(void)
{
cl_git_pass(git_transport_register("something", dummy_transport, NULL));
cl_git_fail_with(git_transport_register("something", dummy_transport, NULL), GIT_EEXISTS);
cl_git_pass(git_transport_unregister("something"));
}
void test_transport_register__custom_transport_error_remove_non_existing(void)
{
cl_git_fail_with(git_transport_unregister("something"), GIT_ENOTFOUND);
}
void test_transport_register__custom_transport_ssh(void)
{
const char *urls[] = {
"ssh://somehost:somepath",
"ssh+git://somehost:somepath",
"git+ssh://somehost:somepath",
"git@somehost:somepath",
"ssh://somehost:somepath%20with%20%spaces",
"ssh://somehost:somepath with spaces"
};
git_transport *transport;
unsigned i;
for (i = 0; i < ARRAY_SIZE(urls); i++) {
#ifndef GIT_SSH
cl_git_fail_with(git_transport_new(&transport, NULL, urls[i]), -1);
#else
cl_git_pass(git_transport_new(&transport, NULL, urls[i]));
transport->free(transport);
#endif
}
cl_git_pass(git_transport_register("ssh", dummy_transport, NULL));
cl_git_pass(git_transport_new(&transport, NULL, "git@somehost:somepath"));
cl_assert(transport == &_transport);
cl_git_pass(git_transport_unregister("ssh"));
for (i = 0; i < ARRAY_SIZE(urls); i++) {
#ifndef GIT_SSH
cl_git_fail_with(git_transport_new(&transport, NULL, urls[i]), -1);
#else
cl_git_pass(git_transport_new(&transport, NULL, urls[i]));
transport->free(transport);
#endif
}
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/annotated_commit.c
|
#include "clar_libgit2.h"
static git_repository *g_repo;
void test_merge_annotated_commit__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo");
}
void test_merge_annotated_commit__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_merge_annotated_commit__lookup_annotated_tag(void)
{
git_annotated_commit *commit;
git_reference *ref;
cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/tags/test"));
cl_git_pass(git_annotated_commit_from_ref(&commit, g_repo, ref));
git_annotated_commit_free(commit);
git_reference_free(ref);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/analysis.c
|
/*
NOTE: this is the implementation for both merge/trees/analysis.c and merge/workdir/analysis.c
You probably want to make changes to both files.
*/
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "git2/annotated_commit.h"
#include "git2/sys/index.h"
#include "merge.h"
#include "merge_helpers.h"
#include "refs.h"
#include "posix.h"
#define TEST_REPO_PATH "merge-resolve"
#define UPTODATE_BRANCH "master"
#define PREVIOUS_BRANCH "previous"
#define FASTFORWARD_BRANCH "ff_branch"
#define FASTFORWARD_ID "fd89f8cffb663ac89095a0f9764902e93ceaca6a"
#define NOFASTFORWARD_BRANCH "branch"
#define NOFASTFORWARD_ID "7cb63eed597130ba4abb87b3e544b85021905520"
static git_repository *sandbox;
static git_repository *repo;
void test_merge_analysis__initialize_with_bare_repository(void)
{
sandbox = cl_git_sandbox_init(TEST_REPO_PATH);
cl_git_pass(git_repository_open_ext(&repo, git_repository_path(sandbox),
GIT_REPOSITORY_OPEN_BARE, NULL));
}
void test_merge_analysis__initialize_with_nonbare_repository(void)
{
sandbox = cl_git_sandbox_init(TEST_REPO_PATH);
cl_git_pass(git_repository_open_ext(&repo, git_repository_workdir(sandbox),
0, NULL));
}
void test_merge_analysis__cleanup(void)
{
git_repository_free(repo);
cl_git_sandbox_cleanup();
}
static void analysis_from_branch(
git_merge_analysis_t *merge_analysis,
git_merge_preference_t *merge_pref,
const char *our_branchname,
const char *their_branchname)
{
git_buf our_refname = GIT_BUF_INIT;
git_buf their_refname = GIT_BUF_INIT;
git_reference *our_ref;
git_reference *their_ref;
git_annotated_commit *their_head;
if (our_branchname != NULL) {
cl_git_pass(git_buf_printf(&our_refname, "%s%s", GIT_REFS_HEADS_DIR, our_branchname));
cl_git_pass(git_reference_lookup(&our_ref, repo, git_buf_cstr(&our_refname)));
} else {
cl_git_pass(git_reference_lookup(&our_ref, repo, GIT_HEAD_FILE));
}
cl_git_pass(git_buf_printf(&their_refname, "%s%s", GIT_REFS_HEADS_DIR, their_branchname));
cl_git_pass(git_reference_lookup(&their_ref, repo, git_buf_cstr(&their_refname)));
cl_git_pass(git_annotated_commit_from_ref(&their_head, repo, their_ref));
cl_git_pass(git_merge_analysis_for_ref(merge_analysis, merge_pref, repo, our_ref, (const git_annotated_commit **)&their_head, 1));
git_buf_dispose(&our_refname);
git_buf_dispose(&their_refname);
git_annotated_commit_free(their_head);
git_reference_free(our_ref);
git_reference_free(their_ref);
}
void test_merge_analysis__fastforward(void)
{
git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref;
analysis_from_branch(&merge_analysis, &merge_pref, NULL, FASTFORWARD_BRANCH);
cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL|GIT_MERGE_ANALYSIS_FASTFORWARD, merge_analysis);
}
void test_merge_analysis__no_fastforward(void)
{
git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref;
analysis_from_branch(&merge_analysis, &merge_pref, NULL, NOFASTFORWARD_BRANCH);
cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, merge_analysis);
}
void test_merge_analysis__uptodate(void)
{
git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref;
analysis_from_branch(&merge_analysis, &merge_pref, NULL, UPTODATE_BRANCH);
cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, merge_analysis);
}
void test_merge_analysis__uptodate_merging_prev_commit(void)
{
git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref;
analysis_from_branch(&merge_analysis, &merge_pref, NULL, PREVIOUS_BRANCH);
cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, merge_analysis);
}
void test_merge_analysis__unborn(void)
{
git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref;
git_buf master = GIT_BUF_INIT;
cl_git_pass(git_buf_joinpath(&master, git_repository_path(repo), "refs/heads/master"));
cl_must_pass(p_unlink(git_buf_cstr(&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_buf_dispose(&master);
}
void test_merge_analysis__fastforward_with_config_noff(void)
{
git_config *config;
git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref;
cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_set_string(config, "merge.ff", "false"));
analysis_from_branch(&merge_analysis, &merge_pref, NULL, FASTFORWARD_BRANCH);
cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL|GIT_MERGE_ANALYSIS_FASTFORWARD, merge_analysis);
cl_assert_equal_i(GIT_MERGE_PREFERENCE_NO_FASTFORWARD, (merge_pref & GIT_MERGE_PREFERENCE_NO_FASTFORWARD));
git_config_free(config);
}
void test_merge_analysis__no_fastforward_with_config_ffonly(void)
{
git_config *config;
git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref;
cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_set_string(config, "merge.ff", "only"));
analysis_from_branch(&merge_analysis, &merge_pref, NULL, NOFASTFORWARD_BRANCH);
cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, merge_analysis);
cl_assert_equal_i(GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY, (merge_pref & GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY));
git_config_free(config);
}
void test_merge_analysis__between_uptodate_refs(void)
{
git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref;
analysis_from_branch(&merge_analysis, &merge_pref, NOFASTFORWARD_BRANCH, PREVIOUS_BRANCH);
cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, merge_analysis);
}
void test_merge_analysis__between_noff_refs(void)
{
git_merge_analysis_t merge_analysis;
git_merge_preference_t merge_pref;
analysis_from_branch(&merge_analysis, &merge_pref, "branch", FASTFORWARD_BRANCH);
cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, merge_analysis);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/merge_helpers.h
|
#ifndef INCLUDE_cl_merge_helpers_h__
#define INCLUDE_cl_merge_helpers_h__
#include "merge.h"
#include "git2/merge.h"
struct merge_index_entry {
uint16_t mode;
char oid_str[GIT_OID_HEXSZ+1];
int stage;
char path[128];
};
struct merge_name_entry {
char ancestor_path[128];
char our_path[128];
char their_path[128];
};
struct merge_index_with_status {
struct merge_index_entry entry;
unsigned int status;
};
struct merge_reuc_entry {
char path[128];
unsigned int ancestor_mode;
unsigned int our_mode;
unsigned int their_mode;
char ancestor_oid_str[GIT_OID_HEXSZ+1];
char our_oid_str[GIT_OID_HEXSZ+1];
char their_oid_str[GIT_OID_HEXSZ+1];
};
struct merge_index_conflict_data {
struct merge_index_with_status ancestor;
struct merge_index_with_status ours;
struct merge_index_with_status theirs;
git_merge_diff_t change_type;
};
int merge_trees_from_branches(
git_index **index, git_repository *repo,
const char *ours_name, const char *theirs_name,
git_merge_options *opts);
int merge_commits_from_branches(
git_index **index, git_repository *repo,
const char *ours_name, const char *theirs_name,
git_merge_options *opts);
int merge_branches(git_repository *repo,
const char *ours_branch, const char *theirs_branch,
git_merge_options *merge_opts, git_checkout_options *checkout_opts);
int merge_test_diff_list(git_merge_diff_list *diff_list, const struct merge_index_entry expected[], size_t expected_len);
int merge_test_merge_conflicts(git_vector *conflicts, const struct merge_index_conflict_data expected[], size_t expected_len);
int merge_test_index(git_index *index, const struct merge_index_entry expected[], size_t expected_len);
int merge_test_names(git_index *index, const struct merge_name_entry expected[], size_t expected_len);
int merge_test_reuc(git_index *index, const struct merge_reuc_entry expected[], size_t expected_len);
int merge_test_workdir(git_repository *repo, const struct merge_index_entry expected[], size_t expected_len);
#endif
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/files.c
|
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "buffer.h"
#include "merge.h"
#include "merge_helpers.h"
#include "conflict_data.h"
#include "refs.h"
#include "futils.h"
#include "diff_xdiff.h"
#define TEST_REPO_PATH "merge-resolve"
#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
static git_repository *repo;
static git_index *repo_index;
/* Fixture setup and teardown */
void test_merge_files__initialize(void)
{
git_config *cfg;
repo = cl_git_sandbox_init(TEST_REPO_PATH);
git_repository_index(&repo_index, repo);
/* Ensure that the user's merge.conflictstyle doesn't interfere */
cl_git_pass(git_repository_config(&cfg, repo));
cl_git_pass(git_config_set_string(cfg, "merge.conflictstyle", "merge"));
git_config_free(cfg);
}
void test_merge_files__cleanup(void)
{
git_index_free(repo_index);
cl_git_sandbox_cleanup();
}
void test_merge_files__automerge_from_bufs(void)
{
git_merge_file_input ancestor = GIT_MERGE_FILE_INPUT_INIT,
ours = GIT_MERGE_FILE_INPUT_INIT,
theirs = GIT_MERGE_FILE_INPUT_INIT;
git_merge_file_result result = {0};
const char *expected = "Zero\n1\n2\n3\n4\n5\n6\n7\n8\n9\nTen\n";
ancestor.ptr = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n";
ancestor.size = strlen(ancestor.ptr);
ancestor.path = "testfile.txt";
ancestor.mode = 0100755;
ours.ptr = "Zero\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n";
ours.size = strlen(ours.ptr);
ours.path = "testfile.txt";
ours.mode = 0100755;
theirs.ptr = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\nTen\n";
theirs.size = strlen(theirs.ptr);
theirs.path = "testfile.txt";
theirs.mode = 0100755;
cl_git_pass(git_merge_file(&result, &ancestor, &ours, &theirs, 0));
cl_assert_equal_i(1, result.automergeable);
cl_assert_equal_s("testfile.txt", result.path);
cl_assert_equal_i(0100755, result.mode);
cl_assert_equal_i(strlen(expected), result.len);
cl_assert_equal_strn(expected, result.ptr, result.len);
git_merge_file_result_free(&result);
}
void test_merge_files__automerge_use_best_path_and_mode(void)
{
git_merge_file_input ancestor = GIT_MERGE_FILE_INPUT_INIT,
ours = GIT_MERGE_FILE_INPUT_INIT,
theirs = GIT_MERGE_FILE_INPUT_INIT;
git_merge_file_result result = {0};
const char *expected = "Zero\n1\n2\n3\n4\n5\n6\n7\n8\n9\nTen\n";
ancestor.ptr = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n";
ancestor.size = strlen(ancestor.ptr);
ancestor.path = "testfile.txt";
ancestor.mode = 0100755;
ours.ptr = "Zero\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n";
ours.size = strlen(ours.ptr);
ours.path = "testfile.txt";
ours.mode = 0100644;
theirs.ptr = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\nTen\n";
theirs.size = strlen(theirs.ptr);
theirs.path = "theirs.txt";
theirs.mode = 0100755;
cl_git_pass(git_merge_file(&result, &ancestor, &ours, &theirs, 0));
cl_assert_equal_i(1, result.automergeable);
cl_assert_equal_s("theirs.txt", result.path);
cl_assert_equal_i(0100644, result.mode);
cl_assert_equal_i(strlen(expected), result.len);
cl_assert_equal_strn(expected, result.ptr, result.len);
git_merge_file_result_free(&result);
}
void test_merge_files__conflict_from_bufs(void)
{
git_merge_file_input ancestor = GIT_MERGE_FILE_INPUT_INIT,
ours = GIT_MERGE_FILE_INPUT_INIT,
theirs = GIT_MERGE_FILE_INPUT_INIT;
git_merge_file_result result = {0};
const char *expected = "<<<<<<< testfile.txt\nAloha!\nOurs.\n=======\nHi!\nTheirs.\n>>>>>>> theirs.txt\n";
size_t expected_len = strlen(expected);
ancestor.ptr = "Hello!\nAncestor!\n";
ancestor.size = strlen(ancestor.ptr);
ancestor.path = "testfile.txt";
ancestor.mode = 0100755;
ours.ptr = "Aloha!\nOurs.\n";
ours.size = strlen(ours.ptr);
ours.path = "testfile.txt";
ours.mode = 0100644;
theirs.ptr = "Hi!\nTheirs.\n";
theirs.size = strlen(theirs.ptr);
theirs.path = "theirs.txt";
theirs.mode = 0100755;
cl_git_pass(git_merge_file(&result, &ancestor, &ours, &theirs, NULL));
cl_assert_equal_i(0, result.automergeable);
cl_assert_equal_s("theirs.txt", result.path);
cl_assert_equal_i(0100644, result.mode);
cl_assert_equal_i(expected_len, result.len);
cl_assert_equal_strn(expected, result.ptr, expected_len);
git_merge_file_result_free(&result);
}
void test_merge_files__automerge_from_index(void)
{
git_merge_file_result result = {0};
git_index_entry ancestor, ours, theirs;
git_oid_fromstr(&ancestor.id, "6212c31dab5e482247d7977e4f0dd3601decf13b");
ancestor.path = "automergeable.txt";
ancestor.mode = 0100644;
git_oid_fromstr(&ours.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf");
ours.path = "automergeable.txt";
ours.mode = 0100755;
git_oid_fromstr(&theirs.id, "058541fc37114bfc1dddf6bd6bffc7fae5c2e6fe");
theirs.path = "newname.txt";
theirs.mode = 0100644;
cl_git_pass(git_merge_file_from_index(&result, repo,
&ancestor, &ours, &theirs, 0));
cl_assert_equal_i(1, result.automergeable);
cl_assert_equal_s("newname.txt", result.path);
cl_assert_equal_i(0100755, result.mode);
cl_assert_equal_i(strlen(AUTOMERGEABLE_MERGED_FILE), result.len);
cl_assert_equal_strn(AUTOMERGEABLE_MERGED_FILE, result.ptr, result.len);
git_merge_file_result_free(&result);
}
void test_merge_files__automerge_whitespace_eol(void)
{
git_merge_file_input ancestor = GIT_MERGE_FILE_INPUT_INIT,
ours = GIT_MERGE_FILE_INPUT_INIT,
theirs = GIT_MERGE_FILE_INPUT_INIT;
git_merge_file_options opts = GIT_MERGE_FILE_OPTIONS_INIT;
git_merge_file_result result = {0};
const char *expected = "Zero\n1\n2\n3\n4\n5\n6\n7\n8\n9\nTen\n";
ancestor.ptr = "0 \n1\n2\n3\n4\n5\n6\n7\n8\n9\n10 \n";
ancestor.size = strlen(ancestor.ptr);
ancestor.path = "testfile.txt";
ancestor.mode = 0100755;
ours.ptr = "Zero\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n";
ours.size = strlen(ours.ptr);
ours.path = "testfile.txt";
ours.mode = 0100755;
theirs.ptr = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\nTen\n";
theirs.size = strlen(theirs.ptr);
theirs.path = "testfile.txt";
theirs.mode = 0100755;
opts.flags |= GIT_MERGE_FILE_IGNORE_WHITESPACE_EOL;
cl_git_pass(git_merge_file(&result, &ancestor, &ours, &theirs, &opts));
cl_assert_equal_i(1, result.automergeable);
cl_assert_equal_s("testfile.txt", result.path);
cl_assert_equal_i(0100755, result.mode);
cl_assert_equal_i(strlen(expected), result.len);
cl_assert_equal_strn(expected, result.ptr, result.len);
git_merge_file_result_free(&result);
}
void test_merge_files__automerge_whitespace_change(void)
{
git_merge_file_input ancestor = GIT_MERGE_FILE_INPUT_INIT,
ours = GIT_MERGE_FILE_INPUT_INIT,
theirs = GIT_MERGE_FILE_INPUT_INIT;
git_merge_file_options opts = GIT_MERGE_FILE_OPTIONS_INIT;
git_merge_file_result result = {0};
const char *expected = "Zero\n1\n2\n3\n4\n5 XXX\n6 YYY\n7\n8\n9\nTen\n";
ancestor.ptr = "0\n1\n2\n3\n4\n5 XXX\n6YYY\n7\n8\n9\n10\n";
ancestor.size = strlen(ancestor.ptr);
ancestor.path = "testfile.txt";
ancestor.mode = 0100755;
ours.ptr = "Zero\n1\n2\n3\n4\n5 XXX\n6 YYY\n7\n8\n9\n10\n";
ours.size = strlen(ours.ptr);
ours.path = "testfile.txt";
ours.mode = 0100755;
theirs.ptr = "0\n1\n2\n3\n4\n5 XXX\n6 YYY\n7\n8\n9\nTen\n";
theirs.size = strlen(theirs.ptr);
theirs.path = "testfile.txt";
theirs.mode = 0100755;
opts.flags |= GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE;
cl_git_pass(git_merge_file(&result, &ancestor, &ours, &theirs, &opts));
cl_assert_equal_i(1, result.automergeable);
cl_assert_equal_s("testfile.txt", result.path);
cl_assert_equal_i(0100755, result.mode);
cl_assert_equal_i(strlen(expected), result.len);
cl_assert_equal_strn(expected, result.ptr, result.len);
git_merge_file_result_free(&result);
}
void test_merge_files__doesnt_add_newline(void)
{
git_merge_file_input ancestor = GIT_MERGE_FILE_INPUT_INIT,
ours = GIT_MERGE_FILE_INPUT_INIT,
theirs = GIT_MERGE_FILE_INPUT_INIT;
git_merge_file_options opts = GIT_MERGE_FILE_OPTIONS_INIT;
git_merge_file_result result = {0};
const char *expected = "Zero\n1\n2\n3\n4\n5 XXX\n6 YYY\n7\n8\n9\nTen";
ancestor.ptr = "0\n1\n2\n3\n4\n5 XXX\n6YYY\n7\n8\n9\n10";
ancestor.size = strlen(ancestor.ptr);
ancestor.path = "testfile.txt";
ancestor.mode = 0100755;
ours.ptr = "Zero\n1\n2\n3\n4\n5 XXX\n6 YYY\n7\n8\n9\n10";
ours.size = strlen(ours.ptr);
ours.path = "testfile.txt";
ours.mode = 0100755;
theirs.ptr = "0\n1\n2\n3\n4\n5 XXX\n6 YYY\n7\n8\n9\nTen";
theirs.size = strlen(theirs.ptr);
theirs.path = "testfile.txt";
theirs.mode = 0100755;
opts.flags |= GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE;
cl_git_pass(git_merge_file(&result, &ancestor, &ours, &theirs, &opts));
cl_assert_equal_i(1, result.automergeable);
cl_assert_equal_s("testfile.txt", result.path);
cl_assert_equal_i(0100755, result.mode);
cl_assert_equal_i(strlen(expected), result.len);
cl_assert_equal_strn(expected, result.ptr, result.len);
git_merge_file_result_free(&result);
}
void test_merge_files__skips_large_files(void)
{
git_merge_file_input ours = GIT_MERGE_FILE_INPUT_INIT,
theirs = GIT_MERGE_FILE_INPUT_INIT;
git_merge_file_options opts = GIT_MERGE_FILE_OPTIONS_INIT;
git_merge_file_result result = {0};
ours.size = GIT_XDIFF_MAX_SIZE + 1;
ours.path = "testfile.txt";
ours.mode = 0100755;
theirs.size = GIT_XDIFF_MAX_SIZE + 1;
theirs.path = "testfile.txt";
theirs.mode = 0100755;
cl_git_pass(git_merge_file(&result, NULL, &ours, &theirs, &opts));
cl_assert_equal_i(0, result.automergeable);
git_merge_file_result_free(&result);
}
void test_merge_files__skips_binaries(void)
{
git_merge_file_input ancestor = GIT_MERGE_FILE_INPUT_INIT,
ours = GIT_MERGE_FILE_INPUT_INIT,
theirs = GIT_MERGE_FILE_INPUT_INIT;
git_merge_file_result result = {0};
ancestor.ptr = "ance\0stor\0";
ancestor.size = 10;
ancestor.path = "ancestor.txt";
ancestor.mode = 0100755;
ours.ptr = "foo\0bar\0";
ours.size = 8;
ours.path = "ours.txt";
ours.mode = 0100755;
theirs.ptr = "bar\0foo\0";
theirs.size = 8;
theirs.path = "theirs.txt";
theirs.mode = 0100644;
cl_git_pass(git_merge_file(&result, &ancestor, &ours, &theirs, NULL));
cl_assert_equal_i(0, result.automergeable);
git_merge_file_result_free(&result);
}
void test_merge_files__handles_binaries_when_favored(void)
{
git_merge_file_input ancestor = GIT_MERGE_FILE_INPUT_INIT,
ours = GIT_MERGE_FILE_INPUT_INIT,
theirs = GIT_MERGE_FILE_INPUT_INIT;
git_merge_file_options opts = GIT_MERGE_FILE_OPTIONS_INIT;
git_merge_file_result result = {0};
ancestor.ptr = "ance\0stor\0";
ancestor.size = 10;
ancestor.path = "ancestor.txt";
ancestor.mode = 0100755;
ours.ptr = "foo\0bar\0";
ours.size = 8;
ours.path = "ours.txt";
ours.mode = 0100755;
theirs.ptr = "bar\0foo\0";
theirs.size = 8;
theirs.path = "theirs.txt";
theirs.mode = 0100644;
opts.favor = GIT_MERGE_FILE_FAVOR_OURS;
cl_git_pass(git_merge_file(&result, &ancestor, &ours, &theirs, &opts));
cl_assert_equal_i(1, result.automergeable);
cl_assert_equal_s("ours.txt", result.path);
cl_assert_equal_i(0100755, result.mode);
cl_assert_equal_i(ours.size, result.len);
cl_assert(memcmp(result.ptr, ours.ptr, ours.size) == 0);
git_merge_file_result_free(&result);
}
void test_merge_files__crlf_conflict_markers_for_crlf_files(void)
{
git_merge_file_input ancestor = GIT_MERGE_FILE_INPUT_INIT,
ours = GIT_MERGE_FILE_INPUT_INIT,
theirs = GIT_MERGE_FILE_INPUT_INIT;
git_merge_file_options opts = GIT_MERGE_FILE_OPTIONS_INIT;
git_merge_file_result result = {0};
const char *expected =
"<<<<<<< file.txt\r\nThis file\r\ndoes, too.\r\n"
"=======\r\nAnd so does\r\nthis one.\r\n>>>>>>> file.txt\r\n";
size_t expected_len = strlen(expected);
const char *expected_diff3 =
"<<<<<<< file.txt\r\nThis file\r\ndoes, too.\r\n"
"||||||| file.txt\r\nThis file has\r\nCRLF line endings.\r\n"
"=======\r\nAnd so does\r\nthis one.\r\n>>>>>>> file.txt\r\n";
size_t expected_diff3_len = strlen(expected_diff3);
ancestor.ptr = "This file has\r\nCRLF line endings.\r\n";
ancestor.size = 35;
ancestor.path = "file.txt";
ancestor.mode = 0100644;
ours.ptr = "This file\r\ndoes, too.\r\n";
ours.size = 23;
ours.path = "file.txt";
ours.mode = 0100644;
theirs.ptr = "And so does\r\nthis one.\r\n";
theirs.size = 24;
theirs.path = "file.txt";
theirs.mode = 0100644;
cl_git_pass(git_merge_file(&result, &ancestor, &ours, &theirs, &opts));
cl_assert_equal_i(0, result.automergeable);
cl_assert_equal_i(expected_len, result.len);
cl_assert(memcmp(expected, result.ptr, expected_len) == 0);
git_merge_file_result_free(&result);
opts.flags |= GIT_MERGE_FILE_STYLE_DIFF3;
cl_git_pass(git_merge_file(&result, &ancestor, &ours, &theirs, &opts));
cl_assert_equal_i(0, result.automergeable);
cl_assert_equal_i(expected_diff3_len, result.len);
cl_assert(memcmp(expected_diff3, result.ptr, expected_len) == 0);
git_merge_file_result_free(&result);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/merge_helpers.c
|
#include "clar_libgit2.h"
#include "futils.h"
#include "refs.h"
#include "tree.h"
#include "merge_helpers.h"
#include "merge.h"
#include "index.h"
#include "git2/merge.h"
#include "git2/sys/index.h"
#include "git2/annotated_commit.h"
int merge_trees_from_branches(
git_index **index, git_repository *repo,
const char *ours_name, const char *theirs_name,
git_merge_options *opts)
{
git_commit *our_commit, *their_commit, *ancestor_commit = NULL;
git_tree *our_tree, *their_tree, *ancestor_tree = NULL;
git_oid our_oid, their_oid, ancestor_oid;
git_buf branch_buf = GIT_BUF_INIT;
int error;
git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours_name);
cl_git_pass(git_reference_name_to_id(&our_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid));
git_buf_clear(&branch_buf);
git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs_name);
cl_git_pass(git_reference_name_to_id(&their_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&their_commit, repo, &their_oid));
error = git_merge_base(&ancestor_oid, repo, git_commit_id(our_commit), git_commit_id(their_commit));
if (error != GIT_ENOTFOUND) {
cl_git_pass(error);
cl_git_pass(git_commit_lookup(&ancestor_commit, repo, &ancestor_oid));
cl_git_pass(git_commit_tree(&ancestor_tree, ancestor_commit));
}
cl_git_pass(git_commit_tree(&our_tree, our_commit));
cl_git_pass(git_commit_tree(&their_tree, their_commit));
error = git_merge_trees(index, repo, ancestor_tree, our_tree, their_tree, opts);
git_buf_dispose(&branch_buf);
git_tree_free(our_tree);
git_tree_free(their_tree);
git_tree_free(ancestor_tree);
git_commit_free(our_commit);
git_commit_free(their_commit);
git_commit_free(ancestor_commit);
return error;
}
int merge_commits_from_branches(
git_index **index, git_repository *repo,
const char *ours_name, const char *theirs_name,
git_merge_options *opts)
{
git_commit *our_commit, *their_commit;
git_oid our_oid, their_oid;
git_buf branch_buf = GIT_BUF_INIT;
int error;
git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours_name);
cl_git_pass(git_reference_name_to_id(&our_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid));
git_buf_clear(&branch_buf);
git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs_name);
cl_git_pass(git_reference_name_to_id(&their_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&their_commit, repo, &their_oid));
error = git_merge_commits(index, repo, our_commit, their_commit, opts);
git_buf_dispose(&branch_buf);
git_commit_free(our_commit);
git_commit_free(their_commit);
return error;
}
int merge_branches(git_repository *repo,
const char *ours_branch, const char *theirs_branch,
git_merge_options *merge_opts, git_checkout_options *checkout_opts)
{
git_reference *head_ref, *theirs_ref;
git_annotated_commit *theirs_head;
git_checkout_options head_checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
head_checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_git_pass(git_reference_symbolic_create(&head_ref, repo, "HEAD", ours_branch, 1, NULL));
cl_git_pass(git_checkout_head(repo, &head_checkout_opts));
cl_git_pass(git_reference_lookup(&theirs_ref, repo, theirs_branch));
cl_git_pass(git_annotated_commit_from_ref(&theirs_head, repo, theirs_ref));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)&theirs_head, 1, merge_opts, checkout_opts));
git_reference_free(head_ref);
git_reference_free(theirs_ref);
git_annotated_commit_free(theirs_head);
return 0;
}
void merge__dump_index_entries(git_vector *index_entries)
{
size_t i;
const git_index_entry *index_entry;
printf ("\nINDEX [%"PRIuZ"]:\n", index_entries->length);
for (i = 0; i < index_entries->length; i++) {
index_entry = index_entries->contents[i];
printf("%o ", index_entry->mode);
printf("%s ", git_oid_allocfmt(&index_entry->id));
printf("%d ", git_index_entry_stage(index_entry));
printf("%s ", index_entry->path);
printf("\n");
}
printf("\n");
}
void merge__dump_names(git_index *index)
{
size_t i;
const git_index_name_entry *conflict_name;
for (i = 0; i < git_index_name_entrycount(index); i++) {
conflict_name = git_index_name_get_byindex(index, i);
printf("%s %s %s\n", conflict_name->ancestor, conflict_name->ours, conflict_name->theirs);
}
printf("\n");
}
void merge__dump_reuc(git_index *index)
{
size_t i;
const git_index_reuc_entry *reuc;
printf ("\nREUC:\n");
for (i = 0; i < git_index_reuc_entrycount(index); i++) {
reuc = git_index_reuc_get_byindex(index, i);
printf("%s ", reuc->path);
printf("%o ", reuc->mode[0]);
printf("%s\n", git_oid_allocfmt(&reuc->oid[0]));
printf(" %o ", reuc->mode[1]);
printf(" %s\n", git_oid_allocfmt(&reuc->oid[1]));
printf(" %o ", reuc->mode[2]);
printf(" %s ", git_oid_allocfmt(&reuc->oid[2]));
printf("\n");
}
printf("\n");
}
static int index_entry_eq_merge_index_entry(const struct merge_index_entry *expected, const git_index_entry *actual)
{
git_oid expected_oid;
bool test_oid;
if (strlen(expected->oid_str) != 0) {
cl_git_pass(git_oid_fromstr(&expected_oid, expected->oid_str));
test_oid = 1;
} else
test_oid = 0;
if (actual->mode != expected->mode ||
(test_oid && git_oid_cmp(&actual->id, &expected_oid) != 0) ||
git_index_entry_stage(actual) != expected->stage)
return 0;
if (actual->mode == 0 && (actual->path != NULL || strlen(expected->path) > 0))
return 0;
if (actual->mode != 0 && (strcmp(actual->path, expected->path) != 0))
return 0;
return 1;
}
static int name_entry_eq(const char *expected, const char *actual)
{
if (strlen(expected) == 0)
return (actual == NULL) ? 1 : 0;
return (strcmp(expected, actual) == 0) ? 1 : 0;
}
static int name_entry_eq_merge_name_entry(const struct merge_name_entry *expected, const git_index_name_entry *actual)
{
if (name_entry_eq(expected->ancestor_path, actual->ancestor) == 0 ||
name_entry_eq(expected->our_path, actual->ours) == 0 ||
name_entry_eq(expected->their_path, actual->theirs) == 0)
return 0;
return 1;
}
static int index_conflict_data_eq_merge_diff(const struct merge_index_conflict_data *expected, git_merge_diff *actual)
{
if (!index_entry_eq_merge_index_entry(&expected->ancestor.entry, &actual->ancestor_entry) ||
!index_entry_eq_merge_index_entry(&expected->ours.entry, &actual->our_entry) ||
!index_entry_eq_merge_index_entry(&expected->theirs.entry, &actual->their_entry))
return 0;
if (expected->ours.status != actual->our_status ||
expected->theirs.status != actual->their_status)
return 0;
return 1;
}
int merge_test_merge_conflicts(git_vector *conflicts, const struct merge_index_conflict_data expected[], size_t expected_len)
{
git_merge_diff *actual;
size_t i;
if (conflicts->length != expected_len)
return 0;
for (i = 0; i < expected_len; i++) {
actual = conflicts->contents[i];
if (!index_conflict_data_eq_merge_diff(&expected[i], actual))
return 0;
}
return 1;
}
int merge_test_index(git_index *index, const struct merge_index_entry expected[], size_t expected_len)
{
size_t i;
const git_index_entry *index_entry;
/*
merge__dump_index_entries(&index->entries);
*/
if (git_index_entrycount(index) != expected_len)
return 0;
for (i = 0; i < expected_len; i++) {
if ((index_entry = git_index_get_byindex(index, i)) == NULL)
return 0;
if (!index_entry_eq_merge_index_entry(&expected[i], index_entry))
return 0;
}
return 1;
}
int merge_test_names(git_index *index, const struct merge_name_entry expected[], size_t expected_len)
{
size_t i;
const git_index_name_entry *name_entry;
/*
dump_names(index);
*/
if (git_index_name_entrycount(index) != expected_len)
return 0;
for (i = 0; i < expected_len; i++) {
if ((name_entry = git_index_name_get_byindex(index, i)) == NULL)
return 0;
if (! name_entry_eq_merge_name_entry(&expected[i], name_entry))
return 0;
}
return 1;
}
int merge_test_reuc(git_index *index, const struct merge_reuc_entry expected[], size_t expected_len)
{
size_t i;
const git_index_reuc_entry *reuc_entry;
git_oid expected_oid;
/*
dump_reuc(index);
*/
if (git_index_reuc_entrycount(index) != expected_len)
return 0;
for (i = 0; i < expected_len; i++) {
if ((reuc_entry = git_index_reuc_get_byindex(index, i)) == NULL)
return 0;
if (strcmp(reuc_entry->path, expected[i].path) != 0 ||
reuc_entry->mode[0] != expected[i].ancestor_mode ||
reuc_entry->mode[1] != expected[i].our_mode ||
reuc_entry->mode[2] != expected[i].their_mode)
return 0;
if (expected[i].ancestor_mode > 0) {
cl_git_pass(git_oid_fromstr(&expected_oid, expected[i].ancestor_oid_str));
if (git_oid_cmp(&reuc_entry->oid[0], &expected_oid) != 0)
return 0;
}
if (expected[i].our_mode > 0) {
cl_git_pass(git_oid_fromstr(&expected_oid, expected[i].our_oid_str));
if (git_oid_cmp(&reuc_entry->oid[1], &expected_oid) != 0)
return 0;
}
if (expected[i].their_mode > 0) {
cl_git_pass(git_oid_fromstr(&expected_oid, expected[i].their_oid_str));
if (git_oid_cmp(&reuc_entry->oid[2], &expected_oid) != 0)
return 0;
}
}
return 1;
}
int dircount(void *payload, git_buf *pathbuf)
{
size_t *entries = payload;
size_t len = git_buf_len(pathbuf);
if (len < 5 || strcmp(pathbuf->ptr + (git_buf_len(pathbuf) - 5), "/.git") != 0)
(*entries)++;
return 0;
}
int merge_test_workdir(git_repository *repo, const struct merge_index_entry expected[], size_t expected_len)
{
size_t actual_len = 0, i;
git_oid actual_oid, expected_oid;
git_buf wd = GIT_BUF_INIT;
git_buf_puts(&wd, repo->workdir);
git_path_direach(&wd, 0, dircount, &actual_len);
if (actual_len != expected_len)
return 0;
for (i = 0; i < expected_len; i++) {
git_blob_create_from_workdir(&actual_oid, repo, expected[i].path);
git_oid_fromstr(&expected_oid, expected[i].oid_str);
if (git_oid_cmp(&actual_oid, &expected_oid) != 0)
return 0;
}
git_buf_dispose(&wd);
return 1;
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/conflict_data.h
|
#define AUTOMERGEABLE_MERGED_FILE \
"this file is changed in master\n" \
"this file is automergeable\n" \
"this file is automergeable\n" \
"this file is automergeable\n" \
"this file is automergeable\n" \
"this file is automergeable\n" \
"this file is automergeable\n" \
"this file is automergeable\n" \
"this file is changed in branch\n"
#define AUTOMERGEABLE_MERGED_FILE_CRLF \
"this file is changed in master\r\n" \
"this file is automergeable\r\n" \
"this file is automergeable\r\n" \
"this file is automergeable\r\n" \
"this file is automergeable\r\n" \
"this file is automergeable\r\n" \
"this file is automergeable\r\n" \
"this file is automergeable\r\n" \
"this file is changed in branch\r\n"
#define CONFLICTING_MERGE_FILE \
"<<<<<<< HEAD\n" \
"this file is changed in master and branch\n" \
"=======\n" \
"this file is changed in branch and master\n" \
">>>>>>> 7cb63eed597130ba4abb87b3e544b85021905520\n"
#define CONFLICTING_DIFF3_FILE \
"<<<<<<< HEAD\n" \
"this file is changed in master and branch\n" \
"||||||| initial\n" \
"this file is a conflict\n" \
"=======\n" \
"this file is changed in branch and master\n" \
">>>>>>> 7cb63eed597130ba4abb87b3e544b85021905520\n"
#define CONFLICTING_UNION_FILE \
"this file is changed in master and branch\n" \
"this file is changed in branch and master\n"
#define CONFLICTING_RECURSIVE_F1_TO_F2 \
"VEAL SOUP.\n" \
"\n" \
"<<<<<<< HEAD\n" \
"PUT INTO A POT THREE QUARTS OF WATER, three onions cut small, ONE\n" \
"=======\n" \
"PUT INTO A POT THREE QUARTS OF WATER, three onions cut not too small, one\n" \
">>>>>>> branchF-2\n" \
"spoonful of black pepper pounded, and two of salt, with two or three\n" \
"slices of lean ham; let it boil steadily two hours; skim it\n" \
"occasionally, then put into it a shin of veal, let it boil two hours\n" \
"longer; take out the slices of ham, and skim off the grease if any\n" \
"should rise, take a gill of good cream, mix with it two table-spoonsful\n" \
"of flour very nicely, and the yelks of two eggs beaten well, strain this\n" \
"mixture, and add some chopped parsley; pour some soup on by degrees,\n" \
"stir it well, and pour it into the pot, continuing to stir until it has\n" \
"boiled two or three minutes to take off the raw taste of the eggs. If\n" \
"the cream be not perfectly sweet, and the eggs quite new, the thickening\n" \
"will curdle in the soup. For a change you may put a dozen ripe tomatos\n" \
"in, first taking off their skins, by letting them stand a few minutes in\n" \
"hot water, when they may be easily peeled. When made in this way you\n" \
"must thicken it with the flour only. Any part of the veal may be used,\n" \
"but the shin or knuckle is the nicest.\n" \
"\n" \
"<<<<<<< HEAD\n" \
"This certainly is a mighty fine recipe.\n" \
"=======\n" \
"This is a mighty fine recipe!\n" \
">>>>>>> branchF-2\n"
#define CONFLICTING_RECURSIVE_H2_TO_H1_WITH_DIFF3 \
"VEAL SOUP.\n" \
"\n" \
"<<<<<<< HEAD\n" \
"Put Into A Pot Three Quarts of Water, Three Onions Cut Small, One\n" \
"||||||| merged common ancestors\n" \
"<<<<<<<<< Temporary merge branch 1\n" \
"PUT INTO A POT three quarts of water, three onions cut small, one\n" \
"||||||||| merged common ancestors\n" \
"Put into a pot three quarts of water, three onions cut small, one\n" \
"=========\n" \
"Put into a pot three quarts of water, THREE ONIONS CUT SMALL, one\n" \
">>>>>>>>> Temporary merge branch 2\n" \
"=======\n" \
"put into a pot three quarts of water, three onions cut small, one\n" \
">>>>>>> branchH-1\n" \
"spoonful of black pepper pounded, and two of salt, with two or three\n" \
"slices of lean ham; let it boil steadily two hours; skim it\n" \
"occasionally, then put into it a shin of veal, let it boil two hours\n" \
"longer; take out the slices of ham, and skim off the grease if any\n" \
"should rise, take a gill of good cream, mix with it two table-spoonsful\n" \
"of flour very nicely, and the yelks of two eggs beaten well, strain this\n" \
"mixture, and add some chopped parsley; pour some soup on by degrees,\n" \
"stir it well, and pour it into the pot, continuing to stir until it has\n" \
"boiled two or three minutes to take off the raw taste of the eggs. If\n" \
"the cream be not perfectly sweet, and the eggs quite new, the thickening\n" \
"will curdle in the soup. For a change you may put a dozen ripe tomatos\n" \
"in, first taking off their skins, by letting them stand a few minutes in\n" \
"hot water, when they may be easily peeled. When made in this way you\n" \
"must thicken it with the flour only. Any part of the veal may be used,\n" \
"but the shin or knuckle is the nicest.\n"
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/driver.c
|
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "buffer.h"
#include "merge.h"
#define TEST_REPO_PATH "merge-resolve"
#define BRANCH_ID "7cb63eed597130ba4abb87b3e544b85021905520"
#define AUTOMERGEABLE_IDSTR "f2e1550a0c9e53d5811175864a29536642ae3821"
static git_repository *repo;
static git_index *repo_index;
static git_oid automergeable_id;
static void test_drivers_register(void);
static void test_drivers_unregister(void);
void test_merge_driver__initialize(void)
{
git_config *cfg;
repo = cl_git_sandbox_init(TEST_REPO_PATH);
git_repository_index(&repo_index, repo);
git_oid_fromstr(&automergeable_id, AUTOMERGEABLE_IDSTR);
/* Ensure that the user's merge.conflictstyle doesn't interfere */
cl_git_pass(git_repository_config(&cfg, repo));
cl_git_pass(git_config_set_string(cfg, "merge.conflictstyle", "merge"));
cl_git_pass(git_config_set_bool(cfg, "core.autocrlf", false));
test_drivers_register();
git_config_free(cfg);
}
void test_merge_driver__cleanup(void)
{
test_drivers_unregister();
git_index_free(repo_index);
cl_git_sandbox_cleanup();
}
struct test_merge_driver {
git_merge_driver base;
int initialized;
int shutdown;
};
static int test_driver_init(git_merge_driver *s)
{
struct test_merge_driver *self = (struct test_merge_driver *)s;
self->initialized = 1;
return 0;
}
static void test_driver_shutdown(git_merge_driver *s)
{
struct test_merge_driver *self = (struct test_merge_driver *)s;
self->shutdown = 1;
}
static int test_driver_apply(
git_merge_driver *s,
const char **path_out,
uint32_t *mode_out,
git_buf *merged_out,
const char *filter_name,
const git_merge_driver_source *src)
{
GIT_UNUSED(s);
GIT_UNUSED(src);
*path_out = "applied.txt";
*mode_out = GIT_FILEMODE_BLOB;
return git_buf_printf(merged_out, "This is the `%s` driver.\n",
filter_name);
}
static struct test_merge_driver test_driver_custom = {
{
GIT_MERGE_DRIVER_VERSION,
test_driver_init,
test_driver_shutdown,
test_driver_apply,
},
0,
0,
};
static struct test_merge_driver test_driver_wildcard = {
{
GIT_MERGE_DRIVER_VERSION,
test_driver_init,
test_driver_shutdown,
test_driver_apply,
},
0,
0,
};
static void test_drivers_register(void)
{
cl_git_pass(git_merge_driver_register("custom", &test_driver_custom.base));
cl_git_pass(git_merge_driver_register("*", &test_driver_wildcard.base));
}
static void test_drivers_unregister(void)
{
cl_git_pass(git_merge_driver_unregister("custom"));
cl_git_pass(git_merge_driver_unregister("*"));
}
static void set_gitattributes_to(const char *driver)
{
git_buf line = GIT_BUF_INIT;
if (driver && strcmp(driver, ""))
git_buf_printf(&line, "automergeable.txt merge=%s\n", driver);
else if (driver)
git_buf_printf(&line, "automergeable.txt merge\n");
else
git_buf_printf(&line, "automergeable.txt -merge\n");
cl_assert(!git_buf_oom(&line));
cl_git_mkfile(TEST_REPO_PATH "/.gitattributes", line.ptr);
git_buf_dispose(&line);
}
static void merge_branch(void)
{
git_oid their_id;
git_annotated_commit *their_head;
cl_git_pass(git_oid_fromstr(&their_id, BRANCH_ID));
cl_git_pass(git_annotated_commit_lookup(&their_head, repo, &their_id));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)&their_head,
1, NULL, NULL));
git_annotated_commit_free(their_head);
}
void test_merge_driver__custom(void)
{
const char *expected = "This is the `custom` driver.\n";
set_gitattributes_to("custom");
merge_branch();
cl_assert_equal_file(expected, strlen(expected),
TEST_REPO_PATH "/applied.txt");
}
void test_merge_driver__wildcard(void)
{
const char *expected = "This is the `foobar` driver.\n";
set_gitattributes_to("foobar");
merge_branch();
cl_assert_equal_file(expected, strlen(expected),
TEST_REPO_PATH "/applied.txt");
}
void test_merge_driver__shutdown_is_called(void)
{
test_driver_custom.initialized = 0;
test_driver_custom.shutdown = 0;
test_driver_wildcard.initialized = 0;
test_driver_wildcard.shutdown = 0;
/* run the merge with the custom driver */
set_gitattributes_to("custom");
merge_branch();
/* unregister the drivers, ensure their shutdown function is called */
test_drivers_unregister();
/* since the `custom` driver was used, it should have been initialized and
* shutdown, but the wildcard driver was not used at all and should not
* have been initialized or shutdown.
*/
cl_assert(test_driver_custom.initialized);
cl_assert(test_driver_custom.shutdown);
cl_assert(!test_driver_wildcard.initialized);
cl_assert(!test_driver_wildcard.shutdown);
test_drivers_register();
}
static int defer_driver_apply(
git_merge_driver *s,
const char **path_out,
uint32_t *mode_out,
git_buf *merged_out,
const char *filter_name,
const git_merge_driver_source *src)
{
GIT_UNUSED(s);
GIT_UNUSED(path_out);
GIT_UNUSED(mode_out);
GIT_UNUSED(merged_out);
GIT_UNUSED(filter_name);
GIT_UNUSED(src);
return GIT_PASSTHROUGH;
}
static struct test_merge_driver test_driver_defer_apply = {
{
GIT_MERGE_DRIVER_VERSION,
test_driver_init,
test_driver_shutdown,
defer_driver_apply,
},
0,
0,
};
void test_merge_driver__apply_can_defer(void)
{
const git_index_entry *idx;
cl_git_pass(git_merge_driver_register("defer",
&test_driver_defer_apply.base));
set_gitattributes_to("defer");
merge_branch();
cl_assert((idx = git_index_get_bypath(repo_index, "automergeable.txt", 0)));
cl_assert_equal_oid(&automergeable_id, &idx->id);
git_merge_driver_unregister("defer");
}
static int conflict_driver_apply(
git_merge_driver *s,
const char **path_out,
uint32_t *mode_out,
git_buf *merged_out,
const char *filter_name,
const git_merge_driver_source *src)
{
GIT_UNUSED(s);
GIT_UNUSED(path_out);
GIT_UNUSED(mode_out);
GIT_UNUSED(merged_out);
GIT_UNUSED(filter_name);
GIT_UNUSED(src);
return GIT_EMERGECONFLICT;
}
static struct test_merge_driver test_driver_conflict_apply = {
{
GIT_MERGE_DRIVER_VERSION,
test_driver_init,
test_driver_shutdown,
conflict_driver_apply,
},
0,
0,
};
void test_merge_driver__apply_can_conflict(void)
{
const git_index_entry *ancestor, *ours, *theirs;
cl_git_pass(git_merge_driver_register("conflict",
&test_driver_conflict_apply.base));
set_gitattributes_to("conflict");
merge_branch();
cl_git_pass(git_index_conflict_get(&ancestor, &ours, &theirs,
repo_index, "automergeable.txt"));
git_merge_driver_unregister("conflict");
}
void test_merge_driver__default_can_be_specified(void)
{
git_oid their_id;
git_annotated_commit *their_head;
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
const char *expected = "This is the `custom` driver.\n";
merge_opts.default_driver = "custom";
cl_git_pass(git_oid_fromstr(&their_id, BRANCH_ID));
cl_git_pass(git_annotated_commit_lookup(&their_head, repo, &their_id));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)&their_head,
1, &merge_opts, NULL));
git_annotated_commit_free(their_head);
cl_assert_equal_file(expected, strlen(expected),
TEST_REPO_PATH "/applied.txt");
}
void test_merge_driver__honors_builtin_mergedefault(void)
{
const git_index_entry *ancestor, *ours, *theirs;
cl_repo_set_string(repo, "merge.default", "binary");
merge_branch();
cl_git_pass(git_index_conflict_get(&ancestor, &ours, &theirs,
repo_index, "automergeable.txt"));
}
void test_merge_driver__honors_custom_mergedefault(void)
{
const char *expected = "This is the `custom` driver.\n";
cl_repo_set_string(repo, "merge.default", "custom");
merge_branch();
cl_assert_equal_file(expected, strlen(expected),
TEST_REPO_PATH "/applied.txt");
}
void test_merge_driver__mergedefault_deferring_falls_back_to_text(void)
{
const git_index_entry *idx;
cl_git_pass(git_merge_driver_register("defer",
&test_driver_defer_apply.base));
cl_repo_set_string(repo, "merge.default", "defer");
merge_branch();
cl_assert((idx = git_index_get_bypath(repo_index, "automergeable.txt", 0)));
cl_assert_equal_oid(&automergeable_id, &idx->id);
git_merge_driver_unregister("defer");
}
void test_merge_driver__set_forces_text(void)
{
const git_index_entry *idx;
/* `merge` without specifying a driver indicates `text` */
set_gitattributes_to("");
cl_repo_set_string(repo, "merge.default", "custom");
merge_branch();
cl_assert((idx = git_index_get_bypath(repo_index, "automergeable.txt", 0)));
cl_assert_equal_oid(&automergeable_id, &idx->id);
}
void test_merge_driver__unset_forces_binary(void)
{
const git_index_entry *ancestor, *ours, *theirs;
/* `-merge` without specifying a driver indicates `binary` */
set_gitattributes_to(NULL);
cl_repo_set_string(repo, "merge.default", "custom");
merge_branch();
cl_git_pass(git_index_conflict_get(&ancestor, &ours, &theirs,
repo_index, "automergeable.txt"));
}
void test_merge_driver__not_configured_driver_falls_back(void)
{
const git_index_entry *idx;
test_drivers_unregister();
/* `merge` without specifying a driver indicates `text` */
set_gitattributes_to("notfound");
merge_branch();
cl_assert((idx = git_index_get_bypath(repo_index, "automergeable.txt", 0)));
cl_assert_equal_oid(&automergeable_id, &idx->id);
test_drivers_register();
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/workdir/simple.c
|
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "../conflict_data.h"
#include "refs.h"
#include "futils.h"
static git_repository *repo;
static git_index *repo_index;
#define TEST_REPO_PATH "merge-resolve"
#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
#define THEIRS_SIMPLE_BRANCH "branch"
#define THEIRS_SIMPLE_OID "7cb63eed597130ba4abb87b3e544b85021905520"
#define THEIRS_UNRELATED_BRANCH "unrelated"
#define THEIRS_UNRELATED_OID "55b4e4687e7a0d9ca367016ed930f385d4022e6f"
#define THEIRS_UNRELATED_PARENT "d6cf6c7741b3316826af1314042550c97ded1d50"
#define OURS_DIRECTORY_FILE "df_side1"
#define THEIRS_DIRECTORY_FILE "fc90237dc4891fa6c69827fc465632225e391618"
/* Non-conflicting files, index entries are common to every merge operation */
#define ADDED_IN_MASTER_INDEX_ENTRY \
{ 0100644, "233c0919c998ed110a4b6ff36f353aec8b713487", 0, \
"added-in-master.txt" }
#define AUTOMERGEABLE_INDEX_ENTRY \
{ 0100644, "f2e1550a0c9e53d5811175864a29536642ae3821", 0, \
"automergeable.txt" }
#define CHANGED_IN_BRANCH_INDEX_ENTRY \
{ 0100644, "4eb04c9e79e88f6640d01ff5b25ca2a60764f216", 0, \
"changed-in-branch.txt" }
#define CHANGED_IN_MASTER_INDEX_ENTRY \
{ 0100644, "11deab00b2d3a6f5a3073988ac050c2d7b6655e2", 0, \
"changed-in-master.txt" }
#define UNCHANGED_INDEX_ENTRY \
{ 0100644, "c8f06f2e3bb2964174677e91f0abead0e43c9e5d", 0, \
"unchanged.txt" }
/* Unrelated files */
#define UNRELATED_NEW1 \
{ 0100644, "ef58fdd8086c243bdc81f99e379acacfd21d32d6", 0, \
"new-in-unrelated1.txt" }
#define UNRELATED_NEW2 \
{ 0100644, "948ba6e701c1edab0c2d394fb7c5538334129793", 0, \
"new-in-unrelated2.txt" }
/* Expected REUC entries */
#define AUTOMERGEABLE_REUC_ENTRY \
{ "automergeable.txt", 0100644, 0100644, 0100644, \
"6212c31dab5e482247d7977e4f0dd3601decf13b", \
"ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", \
"058541fc37114bfc1dddf6bd6bffc7fae5c2e6fe" }
#define CONFLICTING_REUC_ENTRY \
{ "conflicting.txt", 0100644, 0100644, 0100644, \
"d427e0b2e138501a3d15cc376077a3631e15bd46", \
"4e886e602529caa9ab11d71f86634bd1b6e0de10", \
"2bd0a343aeef7a2cf0d158478966a6e587ff3863" }
#define REMOVED_IN_BRANCH_REUC_ENTRY \
{ "removed-in-branch.txt", 0100644, 0100644, 0, \
"dfe3f22baa1f6fce5447901c3086bae368de6bdd", \
"dfe3f22baa1f6fce5447901c3086bae368de6bdd", \
"" }
#define REMOVED_IN_MASTER_REUC_ENTRY \
{ "removed-in-master.txt", 0100644, 0, 0100644, \
"5c3b68a71fc4fa5d362fd3875e53137c6a5ab7a5", \
"", \
"5c3b68a71fc4fa5d362fd3875e53137c6a5ab7a5" }
/* Fixture setup and teardown */
void test_merge_workdir_simple__initialize(void)
{
git_config *cfg;
repo = cl_git_sandbox_init(TEST_REPO_PATH);
git_repository_index(&repo_index, repo);
/* Ensure that the user's merge.conflictstyle doesn't interfere */
cl_git_pass(git_repository_config(&cfg, repo));
cl_git_pass(git_config_set_string(cfg, "merge.conflictstyle", "merge"));
git_config_free(cfg);
}
void test_merge_workdir_simple__cleanup(void)
{
git_index_free(repo_index);
cl_git_sandbox_cleanup();
}
static void merge_simple_branch(int merge_file_favor, int addl_checkout_strategy)
{
git_oid their_oids[1];
git_annotated_commit *their_heads[1];
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_SIMPLE_OID));
cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &their_oids[0]));
merge_opts.file_favor = merge_file_favor;
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_ALLOW_CONFLICTS |
addl_checkout_strategy;
cl_git_pass(git_merge(repo, (const git_annotated_commit **)their_heads, 1, &merge_opts, &checkout_opts));
git_annotated_commit_free(their_heads[0]);
}
static void set_core_autocrlf_to(git_repository *repo, bool value)
{
git_config *cfg;
cl_git_pass(git_repository_config(&cfg, repo));
cl_git_pass(git_config_set_bool(cfg, "core.autocrlf", value));
git_config_free(cfg);
}
void test_merge_workdir_simple__automerge(void)
{
git_index *index;
const git_index_entry *entry;
git_buf automergeable_buf = GIT_BUF_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
AUTOMERGEABLE_INDEX_ENTRY,
CHANGED_IN_BRANCH_INDEX_ENTRY,
CHANGED_IN_MASTER_INDEX_ENTRY,
{ 0100644, "d427e0b2e138501a3d15cc376077a3631e15bd46", 1, "conflicting.txt" },
{ 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 2, "conflicting.txt" },
{ 0100644, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", 3, "conflicting.txt" },
UNCHANGED_INDEX_ENTRY,
};
struct merge_reuc_entry merge_reuc_entries[] = {
AUTOMERGEABLE_REUC_ENTRY,
REMOVED_IN_BRANCH_REUC_ENTRY,
REMOVED_IN_MASTER_REUC_ENTRY
};
set_core_autocrlf_to(repo, false);
merge_simple_branch(0, 0);
cl_git_pass(git_futils_readbuffer(&automergeable_buf,
TEST_REPO_PATH "/automergeable.txt"));
cl_assert(strcmp(automergeable_buf.ptr, AUTOMERGEABLE_MERGED_FILE) == 0);
git_buf_dispose(&automergeable_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
git_repository_index(&index, repo);
cl_assert((entry = git_index_get_bypath(index, "automergeable.txt", 0)) != NULL);
cl_assert(entry->file_size == strlen(AUTOMERGEABLE_MERGED_FILE));
git_index_free(index);
}
void test_merge_workdir_simple__index_reload(void)
{
git_repository *tmp_repo;
git_annotated_commit *their_heads[1];
git_oid their_oid;
git_index_entry entry = {{0}};
git_index *tmp_index;
cl_git_pass(git_repository_open(&tmp_repo, git_repository_workdir(repo)));
cl_git_pass(git_repository_index(&tmp_index, tmp_repo));
cl_git_pass(git_index_read(repo_index, 0));
entry.mode = GIT_FILEMODE_BLOB;
cl_git_pass(git_oid_fromstr(&entry.id, "11deab00b2d3a6f5a3073988ac050c2d7b6655e2"));
entry.path = "automergeable.txt";
cl_git_pass(git_index_add(repo_index, &entry));
cl_git_pass(git_index_add_bypath(tmp_index, "automergeable.txt"));
cl_git_pass(git_index_write(tmp_index));
cl_git_pass(git_oid_fromstr(&their_oid, THEIRS_SIMPLE_OID));
cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &their_oid));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)their_heads, 1, NULL, NULL));
git_index_free(tmp_index);
git_repository_free(tmp_repo);
git_annotated_commit_free(their_heads[0]);
}
void test_merge_workdir_simple__automerge_crlf(void)
{
#ifdef GIT_WIN32
git_index *index;
const git_index_entry *entry;
git_buf automergeable_buf = GIT_BUF_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
AUTOMERGEABLE_INDEX_ENTRY,
CHANGED_IN_BRANCH_INDEX_ENTRY,
CHANGED_IN_MASTER_INDEX_ENTRY,
{ 0100644, "d427e0b2e138501a3d15cc376077a3631e15bd46", 1, "conflicting.txt" },
{ 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 2, "conflicting.txt" },
{ 0100644, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", 3, "conflicting.txt" },
UNCHANGED_INDEX_ENTRY,
};
struct merge_reuc_entry merge_reuc_entries[] = {
AUTOMERGEABLE_REUC_ENTRY,
REMOVED_IN_BRANCH_REUC_ENTRY,
REMOVED_IN_MASTER_REUC_ENTRY
};
set_core_autocrlf_to(repo, true);
merge_simple_branch(0, 0);
cl_git_pass(git_futils_readbuffer(&automergeable_buf,
TEST_REPO_PATH "/automergeable.txt"));
cl_assert(strcmp(automergeable_buf.ptr, AUTOMERGEABLE_MERGED_FILE_CRLF) == 0);
git_buf_dispose(&automergeable_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
git_repository_index(&index, repo);
cl_assert((entry = git_index_get_bypath(index, "automergeable.txt", 0)) != NULL);
cl_assert(entry->file_size == strlen(AUTOMERGEABLE_MERGED_FILE_CRLF));
git_index_free(index);
#endif /* GIT_WIN32 */
}
void test_merge_workdir_simple__mergefile(void)
{
git_buf conflicting_buf = GIT_BUF_INIT, mergemsg_buf = GIT_BUF_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
AUTOMERGEABLE_INDEX_ENTRY,
CHANGED_IN_BRANCH_INDEX_ENTRY,
CHANGED_IN_MASTER_INDEX_ENTRY,
{ 0100644, "d427e0b2e138501a3d15cc376077a3631e15bd46", 1, "conflicting.txt" },
{ 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 2, "conflicting.txt" },
{ 0100644, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", 3, "conflicting.txt" },
UNCHANGED_INDEX_ENTRY,
};
struct merge_reuc_entry merge_reuc_entries[] = {
AUTOMERGEABLE_REUC_ENTRY,
REMOVED_IN_BRANCH_REUC_ENTRY,
REMOVED_IN_MASTER_REUC_ENTRY
};
set_core_autocrlf_to(repo, false);
merge_simple_branch(0, 0);
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_MERGE_FILE) == 0);
cl_git_pass(git_futils_readbuffer(&mergemsg_buf,
TEST_REPO_PATH "/.git/MERGE_MSG"));
cl_assert(strcmp(git_buf_cstr(&mergemsg_buf),
"Merge commit '7cb63eed597130ba4abb87b3e544b85021905520'\n" \
"\n" \
"Conflicts:\n" \
"\tconflicting.txt\n") == 0);
git_buf_dispose(&conflicting_buf);
git_buf_dispose(&mergemsg_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
}
void test_merge_workdir_simple__diff3(void)
{
git_buf conflicting_buf = GIT_BUF_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
AUTOMERGEABLE_INDEX_ENTRY,
CHANGED_IN_BRANCH_INDEX_ENTRY,
CHANGED_IN_MASTER_INDEX_ENTRY,
{ 0100644, "d427e0b2e138501a3d15cc376077a3631e15bd46", 1, "conflicting.txt" },
{ 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 2, "conflicting.txt" },
{ 0100644, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", 3, "conflicting.txt" },
UNCHANGED_INDEX_ENTRY,
};
struct merge_reuc_entry merge_reuc_entries[] = {
AUTOMERGEABLE_REUC_ENTRY,
REMOVED_IN_BRANCH_REUC_ENTRY,
REMOVED_IN_MASTER_REUC_ENTRY
};
set_core_autocrlf_to(repo, false);
merge_simple_branch(0, GIT_CHECKOUT_CONFLICT_STYLE_DIFF3);
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_DIFF3_FILE) == 0);
git_buf_dispose(&conflicting_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
}
void test_merge_workdir_simple__union(void)
{
git_buf conflicting_buf = GIT_BUF_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
AUTOMERGEABLE_INDEX_ENTRY,
CHANGED_IN_BRANCH_INDEX_ENTRY,
CHANGED_IN_MASTER_INDEX_ENTRY,
{ 0100644, "72cdb057b340205164478565e91eb71647e66891", 0, "conflicting.txt" },
UNCHANGED_INDEX_ENTRY,
};
struct merge_reuc_entry merge_reuc_entries[] = {
AUTOMERGEABLE_REUC_ENTRY,
CONFLICTING_REUC_ENTRY,
REMOVED_IN_BRANCH_REUC_ENTRY,
REMOVED_IN_MASTER_REUC_ENTRY
};
set_core_autocrlf_to(repo, false);
merge_simple_branch(GIT_MERGE_FILE_FAVOR_UNION, 0);
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_UNION_FILE) == 0);
git_buf_dispose(&conflicting_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 6));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 4));
}
void test_merge_workdir_simple__gitattributes_union(void)
{
git_buf conflicting_buf = GIT_BUF_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
AUTOMERGEABLE_INDEX_ENTRY,
CHANGED_IN_BRANCH_INDEX_ENTRY,
CHANGED_IN_MASTER_INDEX_ENTRY,
{ 0100644, "72cdb057b340205164478565e91eb71647e66891", 0, "conflicting.txt" },
UNCHANGED_INDEX_ENTRY,
};
struct merge_reuc_entry merge_reuc_entries[] = {
AUTOMERGEABLE_REUC_ENTRY,
CONFLICTING_REUC_ENTRY,
REMOVED_IN_BRANCH_REUC_ENTRY,
REMOVED_IN_MASTER_REUC_ENTRY
};
set_core_autocrlf_to(repo, false);
cl_git_mkfile(TEST_REPO_PATH "/.gitattributes", "conflicting.txt merge=union\n");
merge_simple_branch(GIT_MERGE_FILE_FAVOR_NORMAL, 0);
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_UNION_FILE) == 0);
git_buf_dispose(&conflicting_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 6));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 4));
}
void test_merge_workdir_simple__diff3_from_config(void)
{
git_config *config;
git_buf conflicting_buf = GIT_BUF_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
AUTOMERGEABLE_INDEX_ENTRY,
CHANGED_IN_BRANCH_INDEX_ENTRY,
CHANGED_IN_MASTER_INDEX_ENTRY,
{ 0100644, "d427e0b2e138501a3d15cc376077a3631e15bd46", 1, "conflicting.txt" },
{ 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 2, "conflicting.txt" },
{ 0100644, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", 3, "conflicting.txt" },
UNCHANGED_INDEX_ENTRY,
};
struct merge_reuc_entry merge_reuc_entries[] = {
AUTOMERGEABLE_REUC_ENTRY,
REMOVED_IN_BRANCH_REUC_ENTRY,
REMOVED_IN_MASTER_REUC_ENTRY
};
cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_set_string(config, "merge.conflictstyle", "diff3"));
set_core_autocrlf_to(repo, false);
merge_simple_branch(0, 0);
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_DIFF3_FILE) == 0);
git_buf_dispose(&conflicting_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
git_config_free(config);
}
void test_merge_workdir_simple__merge_overrides_config(void)
{
git_config *config;
git_buf conflicting_buf = GIT_BUF_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
AUTOMERGEABLE_INDEX_ENTRY,
CHANGED_IN_BRANCH_INDEX_ENTRY,
CHANGED_IN_MASTER_INDEX_ENTRY,
{ 0100644, "d427e0b2e138501a3d15cc376077a3631e15bd46", 1, "conflicting.txt" },
{ 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 2, "conflicting.txt" },
{ 0100644, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", 3, "conflicting.txt" },
UNCHANGED_INDEX_ENTRY,
};
struct merge_reuc_entry merge_reuc_entries[] = {
AUTOMERGEABLE_REUC_ENTRY,
REMOVED_IN_BRANCH_REUC_ENTRY,
REMOVED_IN_MASTER_REUC_ENTRY
};
cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_set_string(config, "merge.conflictstyle", "diff3"));
set_core_autocrlf_to(repo, false);
merge_simple_branch(0, GIT_CHECKOUT_CONFLICT_STYLE_MERGE);
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
TEST_REPO_PATH "/conflicting.txt"));
cl_assert(strcmp(conflicting_buf.ptr, CONFLICTING_MERGE_FILE) == 0);
git_buf_dispose(&conflicting_buf);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
git_config_free(config);
}
void test_merge_workdir_simple__checkout_ours(void)
{
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
AUTOMERGEABLE_INDEX_ENTRY,
CHANGED_IN_BRANCH_INDEX_ENTRY,
CHANGED_IN_MASTER_INDEX_ENTRY,
{ 0100644, "d427e0b2e138501a3d15cc376077a3631e15bd46", 1, "conflicting.txt" },
{ 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 2, "conflicting.txt" },
{ 0100644, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", 3, "conflicting.txt" },
UNCHANGED_INDEX_ENTRY,
};
struct merge_reuc_entry merge_reuc_entries[] = {
AUTOMERGEABLE_REUC_ENTRY,
REMOVED_IN_BRANCH_REUC_ENTRY,
REMOVED_IN_MASTER_REUC_ENTRY
};
merge_simple_branch(0, GIT_CHECKOUT_SAFE | GIT_CHECKOUT_USE_OURS);
cl_assert(merge_test_index(repo_index, merge_index_entries, 8));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3));
cl_assert(git_path_exists(TEST_REPO_PATH "/conflicting.txt"));
}
void test_merge_workdir_simple__favor_ours(void)
{
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
AUTOMERGEABLE_INDEX_ENTRY,
CHANGED_IN_BRANCH_INDEX_ENTRY,
CHANGED_IN_MASTER_INDEX_ENTRY,
{ 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 0, "conflicting.txt" },
UNCHANGED_INDEX_ENTRY,
};
struct merge_reuc_entry merge_reuc_entries[] = {
AUTOMERGEABLE_REUC_ENTRY,
CONFLICTING_REUC_ENTRY,
REMOVED_IN_BRANCH_REUC_ENTRY,
REMOVED_IN_MASTER_REUC_ENTRY,
};
merge_simple_branch(GIT_MERGE_FILE_FAVOR_OURS, 0);
cl_assert(merge_test_index(repo_index, merge_index_entries, 6));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 4));
}
void test_merge_workdir_simple__favor_theirs(void)
{
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
AUTOMERGEABLE_INDEX_ENTRY,
CHANGED_IN_BRANCH_INDEX_ENTRY,
CHANGED_IN_MASTER_INDEX_ENTRY,
{ 0100644, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", 0, "conflicting.txt" },
UNCHANGED_INDEX_ENTRY,
};
struct merge_reuc_entry merge_reuc_entries[] = {
AUTOMERGEABLE_REUC_ENTRY,
CONFLICTING_REUC_ENTRY,
REMOVED_IN_BRANCH_REUC_ENTRY,
REMOVED_IN_MASTER_REUC_ENTRY,
};
merge_simple_branch(GIT_MERGE_FILE_FAVOR_THEIRS, 0);
cl_assert(merge_test_index(repo_index, merge_index_entries, 6));
cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 4));
}
void test_merge_workdir_simple__directory_file(void)
{
git_reference *head;
git_oid their_oids[1], head_commit_id;
git_annotated_commit *their_heads[1];
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
git_commit *head_commit;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "49130a28ef567af9a6a6104c38773fedfa5f9742", 2, "dir-10" },
{ 0100644, "6c06dcd163587c2cc18be44857e0b71116382aeb", 3, "dir-10" },
{ 0100644, "43aafd43bea779ec74317dc361f45ae3f532a505", 0, "dir-6" },
{ 0100644, "a031a28ae70e33a641ce4b8a8f6317f1ab79dee4", 3, "dir-7" },
{ 0100644, "5012fd565b1393bdfda1805d4ec38ce6619e1fd1", 1, "dir-7/file.txt" },
{ 0100644, "a5563304ddf6caba25cb50323a2ea6f7dbfcadca", 2, "dir-7/file.txt" },
{ 0100644, "e9ad6ec3e38364a3d07feda7c4197d4d845c53b5", 0, "dir-8" },
{ 0100644, "3ef4d30382ca33fdeba9fda895a99e0891ba37aa", 2, "dir-9" },
{ 0100644, "fc4c636d6515e9e261f9260dbcf3cc6eca97ea08", 1, "dir-9/file.txt" },
{ 0100644, "76ab0e2868197ec158ddd6c78d8a0d2fd73d38f9", 3, "dir-9/file.txt" },
{ 0100644, "5c2411f8075f48a6b2fdb85ebc0d371747c4df15", 0, "file-1/new" },
{ 0100644, "a39a620dae5bc8b4e771cd4d251b7d080401a21e", 1, "file-2" },
{ 0100644, "d963979c237d08b6ba39062ee7bf64c7d34a27f8", 2, "file-2" },
{ 0100644, "5c341ead2ba6f2af98ce5ec3fe84f6b6d2899c0d", 0, "file-2/new" },
{ 0100644, "9efe7723802d4305142eee177e018fee1572c4f4", 0, "file-3/new" },
{ 0100644, "bacac9b3493509aa15e1730e1545fc0919d1dae0", 1, "file-4" },
{ 0100644, "7663fce0130db092936b137cabd693ec234eb060", 3, "file-4" },
{ 0100644, "e49f917b448d1340b31d76e54ba388268fd4c922", 0, "file-4/new" },
{ 0100644, "cab2cf23998b40f1af2d9d9a756dc9e285a8df4b", 2, "file-5/new" },
{ 0100644, "f5504f36e6f4eb797a56fc5bac6c6c7f32969bf2", 3, "file-5/new" },
};
cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, GIT_REFS_HEADS_DIR OURS_DIRECTORY_FILE, 1, NULL));
cl_git_pass(git_reference_name_to_id(&head_commit_id, repo, GIT_HEAD_FILE));
cl_git_pass(git_commit_lookup(&head_commit, repo, &head_commit_id));
cl_git_pass(git_reset(repo, (git_object *)head_commit, GIT_RESET_HARD, NULL));
cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_DIRECTORY_FILE));
cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &their_oids[0]));
merge_opts.file_favor = 0;
cl_git_pass(git_merge(repo, (const git_annotated_commit **)their_heads, 1, &merge_opts, NULL));
cl_assert(merge_test_index(repo_index, merge_index_entries, 20));
git_reference_free(head);
git_commit_free(head_commit);
git_annotated_commit_free(their_heads[0]);
}
void test_merge_workdir_simple__unrelated(void)
{
git_oid their_oids[1];
git_annotated_commit *their_heads[1];
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "233c0919c998ed110a4b6ff36f353aec8b713487", 0, "added-in-master.txt" },
{ 0100644, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", 0, "automergeable.txt" },
{ 0100644, "ab6c44a2e84492ad4b41bb6bac87353e9d02ac8b", 0, "changed-in-branch.txt" },
{ 0100644, "11deab00b2d3a6f5a3073988ac050c2d7b6655e2", 0, "changed-in-master.txt" },
{ 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 0, "conflicting.txt" },
{ 0100644, "ef58fdd8086c243bdc81f99e379acacfd21d32d6", 0, "new-in-unrelated1.txt" },
{ 0100644, "948ba6e701c1edab0c2d394fb7c5538334129793", 0, "new-in-unrelated2.txt" },
{ 0100644, "dfe3f22baa1f6fce5447901c3086bae368de6bdd", 0, "removed-in-branch.txt" },
{ 0100644, "c8f06f2e3bb2964174677e91f0abead0e43c9e5d", 0, "unchanged.txt" },
};
cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_UNRELATED_PARENT));
cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &their_oids[0]));
merge_opts.file_favor = 0;
cl_git_pass(git_merge(repo, (const git_annotated_commit **)their_heads, 1, &merge_opts, NULL));
cl_assert(merge_test_index(repo_index, merge_index_entries, 9));
git_annotated_commit_free(their_heads[0]);
}
void test_merge_workdir_simple__unrelated_with_conflicts(void)
{
git_oid their_oids[1];
git_annotated_commit *their_heads[1];
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "233c0919c998ed110a4b6ff36f353aec8b713487", 0, "added-in-master.txt" },
{ 0100644, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", 2, "automergeable.txt" },
{ 0100644, "d07ec190c306ec690bac349e87d01c4358e49bb2", 3, "automergeable.txt" },
{ 0100644, "ab6c44a2e84492ad4b41bb6bac87353e9d02ac8b", 0, "changed-in-branch.txt" },
{ 0100644, "11deab00b2d3a6f5a3073988ac050c2d7b6655e2", 0, "changed-in-master.txt" },
{ 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 2, "conflicting.txt" },
{ 0100644, "4b253da36a0ae8bfce63aeabd8c5b58429925594", 3, "conflicting.txt" },
{ 0100644, "ef58fdd8086c243bdc81f99e379acacfd21d32d6", 0, "new-in-unrelated1.txt" },
{ 0100644, "948ba6e701c1edab0c2d394fb7c5538334129793", 0, "new-in-unrelated2.txt" },
{ 0100644, "dfe3f22baa1f6fce5447901c3086bae368de6bdd", 0, "removed-in-branch.txt" },
{ 0100644, "c8f06f2e3bb2964174677e91f0abead0e43c9e5d", 0, "unchanged.txt" },
};
cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_UNRELATED_OID));
cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &their_oids[0]));
merge_opts.file_favor = 0;
cl_git_pass(git_merge(repo, (const git_annotated_commit **)their_heads, 1, &merge_opts, NULL));
cl_assert(merge_test_index(repo_index, merge_index_entries, 11));
git_annotated_commit_free(their_heads[0]);
}
void test_merge_workdir_simple__binary(void)
{
git_oid our_oid, their_oid, our_file_oid;
git_commit *our_commit;
git_annotated_commit *their_head;
const git_index_entry *binary_entry;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "1c51d885170f57a0c4e8c69ff6363d91a5b51f85", 1, "binary" },
{ 0100644, "23ed141a6ae1e798b2f721afedbe947c119111ba", 2, "binary" },
{ 0100644, "836b8b82b26cab22eaaed8820877c76d6c8bca19", 3, "binary" },
};
cl_git_pass(git_oid_fromstr(&our_oid, "cc338e4710c9b257106b8d16d82f86458d5beaf1"));
cl_git_pass(git_oid_fromstr(&their_oid, "ad01aebfdf2ac13145efafe3f9fcf798882f1730"));
cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid));
cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD, NULL));
cl_git_pass(git_annotated_commit_lookup(&their_head, repo, &their_oid));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)&their_head, 1, NULL, NULL));
cl_assert(merge_test_index(repo_index, merge_index_entries, 3));
cl_git_pass(git_index_add_bypath(repo_index, "binary"));
cl_assert((binary_entry = git_index_get_bypath(repo_index, "binary", 0)) != NULL);
cl_git_pass(git_oid_fromstr(&our_file_oid, "23ed141a6ae1e798b2f721afedbe947c119111ba"));
cl_assert(git_oid_cmp(&binary_entry->id, &our_file_oid) == 0);
git_annotated_commit_free(their_head);
git_commit_free(our_commit);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/workdir/submodules.c
|
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
static git_repository *repo;
#define TEST_REPO_PATH "merge-resolve"
#define SUBMODULE_MAIN_BRANCH "submodules"
#define SUBMODULE_OTHER_BRANCH "submodules-branch"
#define SUBMODULE_OTHER2_BRANCH "submodules-branch2"
#define SUBMODULE_DELETE_BRANCH "delete-submodule"
#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
/* Fixture setup and teardown */
void test_merge_workdir_submodules__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
}
void test_merge_workdir_submodules__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_merge_workdir_submodules__automerge(void)
{
git_reference *our_ref, *their_ref;
git_commit *our_commit;
git_annotated_commit *their_head;
git_index *index;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "caff6b7d44973f53e3e0cf31d0d695188b19aec6", 0, ".gitmodules" },
{ 0100644, "950a663a6a7b2609eed1ed1ba9f41eb1a3192a9f", 0, "file1.txt" },
{ 0100644, "343e660b9cb4bee5f407c2e33fcb9df24d9407a4", 0, "file2.txt" },
{ 0160000, "d3d806a4bef96889117fd7ebac0e3cb5ec152932", 1, "submodule" },
{ 0160000, "297aa6cd028b3336c7802c7a6f49143da4e1602d", 2, "submodule" },
{ 0160000, "ae39c77c70cb6bad18bb471912460c4e1ba0f586", 3, "submodule" },
};
cl_git_pass(git_reference_lookup(&our_ref, repo, "refs/heads/" SUBMODULE_MAIN_BRANCH));
cl_git_pass(git_commit_lookup(&our_commit, repo, git_reference_target(our_ref)));
cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD, NULL));
cl_git_pass(git_reference_lookup(&their_ref, repo, "refs/heads/" SUBMODULE_OTHER_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_head, repo, their_ref));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)&their_head, 1, NULL, NULL));
cl_git_pass(git_repository_index(&index, repo));
cl_assert(merge_test_index(index, merge_index_entries, 6));
git_index_free(index);
git_annotated_commit_free(their_head);
git_commit_free(our_commit);
git_reference_free(their_ref);
git_reference_free(our_ref);
}
void test_merge_workdir_submodules__take_changed(void)
{
git_reference *our_ref, *their_ref;
git_commit *our_commit;
git_annotated_commit *their_head;
git_index *index;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "caff6b7d44973f53e3e0cf31d0d695188b19aec6", 0, ".gitmodules" },
{ 0100644, "b438ff23300b2e0f80b84a6f30140dfa91e71423", 0, "file1.txt" },
{ 0100644, "f27fbafdfa6693f8f7a5128506fe3e338dbfcad2", 0, "file2.txt" },
{ 0160000, "297aa6cd028b3336c7802c7a6f49143da4e1602d", 0, "submodule" },
};
cl_git_pass(git_reference_lookup(&our_ref, repo, "refs/heads/" SUBMODULE_MAIN_BRANCH));
cl_git_pass(git_commit_lookup(&our_commit, repo, git_reference_target(our_ref)));
cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD, NULL));
cl_git_pass(git_reference_lookup(&their_ref, repo, "refs/heads/" SUBMODULE_OTHER2_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_head, repo, their_ref));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)&their_head, 1, NULL, NULL));
cl_git_pass(git_repository_index(&index, repo));
cl_assert(merge_test_index(index, merge_index_entries, 4));
git_index_free(index);
git_annotated_commit_free(their_head);
git_commit_free(our_commit);
git_reference_free(their_ref);
git_reference_free(our_ref);
}
void test_merge_workdir_submodules__update_delete_conflict(void)
{
git_reference *our_ref, *their_ref;
git_commit *our_commit;
git_annotated_commit *their_head;
git_index *index;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", 0, ".gitmodules" },
{ 0100644, "5887a5e516c53bd58efb0f02ec6aa031b6fe9ad7", 0, "file1.txt" },
{ 0100644, "4218670ab81cc219a9f94befb5c5dad90ec52648", 0, "file2.txt" },
{ 0160000, "d3d806a4bef96889117fd7ebac0e3cb5ec152932", 1, "submodule"},
{ 0160000, "297aa6cd028b3336c7802c7a6f49143da4e1602d", 3, "submodule" },
};
cl_git_pass(git_reference_lookup(&our_ref, repo, "refs/heads/" SUBMODULE_DELETE_BRANCH));
cl_git_pass(git_commit_lookup(&our_commit, repo, git_reference_target(our_ref)));
cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD, NULL));
cl_git_pass(git_reference_lookup(&their_ref, repo, "refs/heads/" SUBMODULE_MAIN_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_head, repo, their_ref));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)&their_head, 1, NULL, NULL));
cl_git_pass(git_repository_index(&index, repo));
cl_assert(merge_test_index(index, merge_index_entries, 5));
git_index_free(index);
git_annotated_commit_free(their_head);
git_commit_free(our_commit);
git_reference_free(their_ref);
git_reference_free(our_ref);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/workdir/recursive.c
|
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "../conflict_data.h"
static git_repository *repo;
#define TEST_REPO_PATH "merge-recursive"
void test_merge_workdir_recursive__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
}
void test_merge_workdir_recursive__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_merge_workdir_recursive__writes_conflict_with_virtual_base(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
git_buf conflicting_buf = GIT_BUF_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "fa567f568ed72157c0c617438d077695b99d9aac", 1, "veal.txt" },
{ 0100644, "21950d5e4e4d1a871b4dfcf72ecb6b9c162c434e", 2, "veal.txt" },
{ 0100644, "3855170cef875708da06ab9ad7fc6a73b531cda1", 3, "veal.txt" },
};
cl_git_pass(merge_branches(repo, GIT_REFS_HEADS_DIR "branchF-1", GIT_REFS_HEADS_DIR "branchF-2", &opts, NULL));
cl_git_pass(git_repository_index(&index, repo));
cl_assert(merge_test_index(index, merge_index_entries, 8));
cl_git_pass(git_futils_readbuffer(&conflicting_buf, "merge-recursive/veal.txt"));
cl_assert_equal_s(CONFLICTING_RECURSIVE_F1_TO_F2, conflicting_buf.ptr);
git_index_free(index);
git_buf_dispose(&conflicting_buf);
}
void test_merge_workdir_recursive__conflicting_merge_base_with_diff3(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
git_buf conflicting_buf = GIT_BUF_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "0b01d2f70a1c6b9ab60c382f3f9cdc8173da6736", 1, "veal.txt" },
{ 0100644, "37a5054a9f9b4628e3924c5cb8f2147c6e2a3efc", 2, "veal.txt" },
{ 0100644, "d604c75019c282144bdbbf3fd3462ba74b240efc", 3, "veal.txt" },
};
opts.file_flags |= GIT_MERGE_FILE_STYLE_DIFF3;
checkout_opts.checkout_strategy |= GIT_CHECKOUT_CONFLICT_STYLE_DIFF3;
cl_git_pass(merge_branches(repo, GIT_REFS_HEADS_DIR "branchH-2", GIT_REFS_HEADS_DIR "branchH-1", &opts, &checkout_opts));
cl_git_pass(git_repository_index(&index, repo));
cl_assert(merge_test_index(index, merge_index_entries, 8));
cl_git_pass(git_futils_readbuffer(&conflicting_buf, "merge-recursive/veal.txt"));
cl_assert_equal_s(CONFLICTING_RECURSIVE_H2_TO_H1_WITH_DIFF3, conflicting_buf.ptr);
git_index_free(index);
git_buf_dispose(&conflicting_buf);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/workdir/renames.c
|
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "futils.h"
#include "refs.h"
static git_repository *repo;
#define TEST_REPO_PATH "merge-resolve"
#define BRANCH_RENAME_OURS "rename_conflict_ours"
#define BRANCH_RENAME_THEIRS "rename_conflict_theirs"
/* Fixture setup and teardown */
void test_merge_workdir_renames__initialize(void)
{
git_config *cfg;
repo = cl_git_sandbox_init(TEST_REPO_PATH);
/* Ensure that the user's merge.conflictstyle doesn't interfere */
cl_git_pass(git_repository_config(&cfg, repo));
cl_git_pass(git_config_set_string(cfg, "merge.conflictstyle", "merge"));
git_config_free(cfg);
}
void test_merge_workdir_renames__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_merge_workdir_renames__renames(void)
{
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e", 0, "0a-no-change.txt" },
{ 0100644, "f0ce2b8e4986084d9b308fb72709e414c23eb5e6", 0, "0b-duplicated-in-ours.txt" },
{ 0100644, "8aac75de2a34b4d340bf62a6e58197269cb55797", 0, "0b-rewritten-in-ours.txt" },
{ 0100644, "2f56120107d680129a5d9791b521cb1e73a2ed31", 0, "0c-duplicated-in-theirs.txt" },
{ 0100644, "7edc726325da726751a4195e434e4377b0f67f9a", 0, "0c-rewritten-in-theirs.txt" },
{ 0100644, "0d872f8e871a30208305978ecbf9e66d864f1638", 0, "1a-newname-in-ours-edited-in-theirs.txt" },
{ 0100644, "d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb", 0, "1a-newname-in-ours.txt" },
{ 0100644, "ed9523e62e453e50dd9be1606af19399b96e397a", 0, "1b-newname-in-theirs-edited-in-ours.txt" },
{ 0100644, "2b5f1f181ee3b58ea751f5dd5d8f9b445520a136", 0, "1b-newname-in-theirs.txt" },
{ 0100644, "178940b450f238a56c0d75b7955cb57b38191982", 0, "2-newname-in-both.txt" },
{ 0100644, "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9", 0, "3a-newname-in-ours-deleted-in-theirs.txt" },
{ 0100644, "36219b49367146cb2e6a1555b5a9ebd4d0328495", 0, "3b-newname-in-theirs-deleted-in-ours.txt" },
{ 0100644, "227792b52aaa0b238bea00ec7e509b02623f168c", 0, "4a-newname-in-ours-added-in-theirs.txt~HEAD" },
{ 0100644, "8b5b53cb2aa9ceb1139f5312fcfa3cc3c5a47c9a", 0, "4a-newname-in-ours-added-in-theirs.txt~rename_conflict_theirs" },
{ 0100644, "de872ee3618b894992e9d1e18ba2ebe256a112f9", 0, "4b-newname-in-theirs-added-in-ours.txt~HEAD" },
{ 0100644, "98d52d07c0b0bbf2b46548f6aa521295c2cb55db", 0, "4b-newname-in-theirs-added-in-ours.txt~rename_conflict_theirs" },
{ 0100644, "d3719a5ae8e4d92276b5313ce976f6ee5af2b436", 0, "5a-newname-in-ours-added-in-theirs.txt~HEAD" },
{ 0100644, "98ba4205fcf31f5dd93c916d35fe3f3b3d0e6714", 0, "5a-newname-in-ours-added-in-theirs.txt~rename_conflict_theirs" },
{ 0100644, "385c8a0f26ddf79e9041e15e17dc352ed2c4cced", 0, "5b-newname-in-theirs-added-in-ours.txt~HEAD" },
{ 0100644, "63247125386de9ec90a27ad36169307bf8a11a38", 0, "5b-newname-in-theirs-added-in-ours.txt~rename_conflict_theirs" },
{ 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 0, "6-both-renamed-1-to-2-ours.txt" },
{ 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 0, "6-both-renamed-1-to-2-theirs.txt" },
{ 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 0, "7-both-renamed.txt~HEAD" },
{ 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 0, "7-both-renamed.txt~rename_conflict_theirs" },
};
merge_opts.flags |= GIT_MERGE_FIND_RENAMES;
merge_opts.rename_threshold = 50;
cl_git_pass(merge_branches(repo, GIT_REFS_HEADS_DIR BRANCH_RENAME_OURS, GIT_REFS_HEADS_DIR BRANCH_RENAME_THEIRS, &merge_opts, NULL));
cl_assert(merge_test_workdir(repo, merge_index_entries, 24));
}
void test_merge_workdir_renames__ours(void)
{
git_index *index;
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e", 0, "0a-no-change.txt" },
{ 0100644, "f0ce2b8e4986084d9b308fb72709e414c23eb5e6", 0, "0b-duplicated-in-ours.txt" },
{ 0100644, "e376fbdd06ebf021c92724da9f26f44212734e3e", 0, "0b-rewritten-in-ours.txt" },
{ 0100644, "2f56120107d680129a5d9791b521cb1e73a2ed31", 0, "0c-duplicated-in-theirs.txt" },
{ 0100644, "efc9121fdedaf08ba180b53ebfbcf71bd488ed09", 0, "0c-rewritten-in-theirs.txt" },
{ 0100644, "0d872f8e871a30208305978ecbf9e66d864f1638", 0, "1a-newname-in-ours-edited-in-theirs.txt" },
{ 0100644, "d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb", 0, "1a-newname-in-ours.txt" },
{ 0100644, "ed9523e62e453e50dd9be1606af19399b96e397a", 0, "1b-newname-in-theirs-edited-in-ours.txt" },
{ 0100644, "2b5f1f181ee3b58ea751f5dd5d8f9b445520a136", 0, "1b-newname-in-theirs.txt" },
{ 0100644, "178940b450f238a56c0d75b7955cb57b38191982", 0, "2-newname-in-both.txt" },
{ 0100644, "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9", 0, "3a-newname-in-ours-deleted-in-theirs.txt" },
{ 0100644, "36219b49367146cb2e6a1555b5a9ebd4d0328495", 0, "3b-newname-in-theirs-deleted-in-ours.txt" },
{ 0100644, "227792b52aaa0b238bea00ec7e509b02623f168c", 0, "4a-newname-in-ours-added-in-theirs.txt" },
{ 0100644, "de872ee3618b894992e9d1e18ba2ebe256a112f9", 0, "4b-newname-in-theirs-added-in-ours.txt" },
{ 0100644, "d3719a5ae8e4d92276b5313ce976f6ee5af2b436", 0, "5a-newname-in-ours-added-in-theirs.txt" },
{ 0100644, "385c8a0f26ddf79e9041e15e17dc352ed2c4cced", 0, "5b-newname-in-theirs-added-in-ours.txt" },
{ 0100644, "63247125386de9ec90a27ad36169307bf8a11a38", 0, "5b-renamed-in-theirs-added-in-ours.txt" },
{ 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 0, "6-both-renamed-1-to-2-ours.txt" },
{ 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 0, "7-both-renamed-side-2.txt" },
{ 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 0, "7-both-renamed.txt" },
};
merge_opts.flags |= GIT_MERGE_FIND_RENAMES;
merge_opts.rename_threshold = 50;
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_USE_OURS;
cl_git_pass(merge_branches(repo, GIT_REFS_HEADS_DIR BRANCH_RENAME_OURS, GIT_REFS_HEADS_DIR BRANCH_RENAME_THEIRS, &merge_opts, &checkout_opts));
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_write(index));
cl_assert(merge_test_workdir(repo, merge_index_entries, 20));
git_index_free(index);
}
void test_merge_workdir_renames__similar(void)
{
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
/*
* Note: this differs slightly from the core git merge result - there, 4a is
* tracked as a rename/delete instead of a rename/add and the theirs side
* is not placed in workdir in any form.
*/
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e", 0, "0a-no-change.txt" },
{ 0100644, "f0ce2b8e4986084d9b308fb72709e414c23eb5e6", 0, "0b-duplicated-in-ours.txt" },
{ 0100644, "8aac75de2a34b4d340bf62a6e58197269cb55797", 0, "0b-rewritten-in-ours.txt" },
{ 0100644, "2f56120107d680129a5d9791b521cb1e73a2ed31", 0, "0c-duplicated-in-theirs.txt" },
{ 0100644, "7edc726325da726751a4195e434e4377b0f67f9a", 0, "0c-rewritten-in-theirs.txt" },
{ 0100644, "0d872f8e871a30208305978ecbf9e66d864f1638", 0, "1a-newname-in-ours-edited-in-theirs.txt" },
{ 0100644, "d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb", 0, "1a-newname-in-ours.txt" },
{ 0100644, "ed9523e62e453e50dd9be1606af19399b96e397a", 0, "1b-newname-in-theirs-edited-in-ours.txt" },
{ 0100644, "2b5f1f181ee3b58ea751f5dd5d8f9b445520a136", 0, "1b-newname-in-theirs.txt" },
{ 0100644, "178940b450f238a56c0d75b7955cb57b38191982", 0, "2-newname-in-both.txt" },
{ 0100644, "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9", 0, "3a-newname-in-ours-deleted-in-theirs.txt" },
{ 0100644, "36219b49367146cb2e6a1555b5a9ebd4d0328495", 0, "3b-newname-in-theirs-deleted-in-ours.txt" },
{ 0100644, "227792b52aaa0b238bea00ec7e509b02623f168c", 0, "4a-newname-in-ours-added-in-theirs.txt~HEAD" },
{ 0100644, "8b5b53cb2aa9ceb1139f5312fcfa3cc3c5a47c9a", 0, "4a-newname-in-ours-added-in-theirs.txt~rename_conflict_theirs" },
{ 0100644, "de872ee3618b894992e9d1e18ba2ebe256a112f9", 0, "4b-newname-in-theirs-added-in-ours.txt~HEAD" },
{ 0100644, "98d52d07c0b0bbf2b46548f6aa521295c2cb55db", 0, "4b-newname-in-theirs-added-in-ours.txt~rename_conflict_theirs" },
{ 0100644, "d3719a5ae8e4d92276b5313ce976f6ee5af2b436", 0, "5a-newname-in-ours-added-in-theirs.txt~HEAD" },
{ 0100644, "98ba4205fcf31f5dd93c916d35fe3f3b3d0e6714", 0, "5a-newname-in-ours-added-in-theirs.txt~rename_conflict_theirs" },
{ 0100644, "385c8a0f26ddf79e9041e15e17dc352ed2c4cced", 0, "5b-newname-in-theirs-added-in-ours.txt~HEAD" },
{ 0100644, "63247125386de9ec90a27ad36169307bf8a11a38", 0, "5b-newname-in-theirs-added-in-ours.txt~rename_conflict_theirs" },
{ 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 0, "6-both-renamed-1-to-2-ours.txt" },
{ 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 0, "6-both-renamed-1-to-2-theirs.txt" },
{ 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 0, "7-both-renamed.txt~HEAD" },
{ 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 0, "7-both-renamed.txt~rename_conflict_theirs" },
};
merge_opts.flags |= GIT_MERGE_FIND_RENAMES;
merge_opts.rename_threshold = 50;
cl_git_pass(merge_branches(repo, GIT_REFS_HEADS_DIR BRANCH_RENAME_OURS, GIT_REFS_HEADS_DIR BRANCH_RENAME_THEIRS, &merge_opts, NULL));
cl_assert(merge_test_workdir(repo, merge_index_entries, 24));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/workdir/dirty.c
|
#include "clar_libgit2.h"
#include "git2/merge.h"
#include "buffer.h"
#include "merge.h"
#include "index.h"
#include "../merge_helpers.h"
#include "posix.h"
#define TEST_REPO_PATH "merge-resolve"
#define MERGE_BRANCH_OID "7cb63eed597130ba4abb87b3e544b85021905520"
#define AUTOMERGEABLE_MERGED_FILE \
"this file is changed in master\n" \
"this file is automergeable\n" \
"this file is automergeable\n" \
"this file is automergeable\n" \
"this file is automergeable\n" \
"this file is automergeable\n" \
"this file is automergeable\n" \
"this file is automergeable\n" \
"this file is changed in branch\n"
#define CHANGED_IN_BRANCH_FILE \
"changed in branch\n"
static git_repository *repo;
static git_index *repo_index;
static char *unaffected[][4] = {
{ "added-in-master.txt", NULL },
{ "changed-in-master.txt", NULL },
{ "unchanged.txt", NULL },
{ "added-in-master.txt", "changed-in-master.txt", NULL },
{ "added-in-master.txt", "unchanged.txt", NULL },
{ "changed-in-master.txt", "unchanged.txt", NULL },
{ "added-in-master.txt", "changed-in-master.txt", "unchanged.txt", NULL },
{ "new_file.txt", NULL },
{ "new_file.txt", "unchanged.txt", NULL },
{ NULL },
};
static char *affected[][5] = {
{ "automergeable.txt", NULL },
{ "changed-in-branch.txt", NULL },
{ "conflicting.txt", NULL },
{ "removed-in-branch.txt", NULL },
{ "automergeable.txt", "changed-in-branch.txt", NULL },
{ "automergeable.txt", "conflicting.txt", NULL },
{ "automergeable.txt", "removed-in-branch.txt", NULL },
{ "changed-in-branch.txt", "conflicting.txt", NULL },
{ "changed-in-branch.txt", "removed-in-branch.txt", NULL },
{ "conflicting.txt", "removed-in-branch.txt", NULL },
{ "automergeable.txt", "changed-in-branch.txt", "conflicting.txt", NULL },
{ "automergeable.txt", "changed-in-branch.txt", "removed-in-branch.txt", NULL },
{ "automergeable.txt", "conflicting.txt", "removed-in-branch.txt", NULL },
{ "changed-in-branch.txt", "conflicting.txt", "removed-in-branch.txt", NULL },
{ "automergeable.txt", "changed-in-branch.txt", "conflicting.txt", "removed-in-branch.txt", NULL },
{ NULL },
};
static char *result_contents[4][6] = {
{ "automergeable.txt", AUTOMERGEABLE_MERGED_FILE, NULL, NULL },
{ "changed-in-branch.txt", CHANGED_IN_BRANCH_FILE, NULL, NULL },
{ "automergeable.txt", AUTOMERGEABLE_MERGED_FILE, "changed-in-branch.txt", CHANGED_IN_BRANCH_FILE, NULL, NULL },
{ NULL }
};
void test_merge_workdir_dirty__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
git_repository_index(&repo_index, repo);
}
void test_merge_workdir_dirty__cleanup(void)
{
git_index_free(repo_index);
cl_git_sandbox_cleanup();
}
static void set_core_autocrlf_to(git_repository *repo, bool value)
{
git_config *cfg;
cl_git_pass(git_repository_config(&cfg, repo));
cl_git_pass(git_config_set_bool(cfg, "core.autocrlf", value));
git_config_free(cfg);
}
static int merge_branch(void)
{
git_oid their_oids[1];
git_annotated_commit *their_head;
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
int error;
cl_git_pass(git_oid_fromstr(&their_oids[0], MERGE_BRANCH_OID));
cl_git_pass(git_annotated_commit_lookup(&their_head, repo, &their_oids[0]));
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
error = git_merge(repo, (const git_annotated_commit **)&their_head, 1, &merge_opts, &checkout_opts);
git_annotated_commit_free(their_head);
return error;
}
static void write_files(char *files[])
{
char *filename;
git_buf path = GIT_BUF_INIT, content = GIT_BUF_INIT;
size_t i;
for (i = 0, filename = files[i]; filename; filename = files[++i]) {
git_buf_clear(&path);
git_buf_clear(&content);
git_buf_printf(&path, "%s/%s", TEST_REPO_PATH, filename);
git_buf_printf(&content, "This is a dirty file in the working directory!\n\n"
"It will not be staged! Its filename is %s.\n", filename);
cl_git_mkfile(path.ptr, content.ptr);
}
git_buf_dispose(&path);
git_buf_dispose(&content);
}
static void hack_index(char *files[])
{
char *filename;
struct stat statbuf;
git_buf path = GIT_BUF_INIT;
git_index_entry *entry;
struct p_timeval times[2];
time_t now;
size_t i;
/* Update the index to suggest that checkout placed these files on
* disk, keeping the object id but updating the cache, which will
* emulate a Git implementation's different filter.
*
* We set the file's timestamp to before now to pretend that
* it was an old checkout so we don't trigger the racy
* protections would would check the content.
*/
now = time(NULL);
times[0].tv_sec = now - 5;
times[0].tv_usec = 0;
times[1].tv_sec = now - 5;
times[1].tv_usec = 0;
for (i = 0, filename = files[i]; filename; filename = files[++i]) {
git_buf_clear(&path);
cl_assert(entry = (git_index_entry *)
git_index_get_bypath(repo_index, filename, 0));
cl_git_pass(git_buf_printf(&path, "%s/%s", TEST_REPO_PATH, filename));
cl_git_pass(p_utimes(path.ptr, times));
cl_git_pass(p_stat(path.ptr, &statbuf));
entry->ctime.seconds = (int32_t)statbuf.st_ctime;
entry->mtime.seconds = (int32_t)statbuf.st_mtime;
#if defined(GIT_USE_NSEC)
entry->ctime.nanoseconds = statbuf.st_ctime_nsec;
entry->mtime.nanoseconds = statbuf.st_mtime_nsec;
#else
entry->ctime.nanoseconds = 0;
entry->mtime.nanoseconds = 0;
#endif
entry->dev = statbuf.st_dev;
entry->ino = statbuf.st_ino;
entry->uid = statbuf.st_uid;
entry->gid = statbuf.st_gid;
entry->file_size = (uint32_t)statbuf.st_size;
}
git_buf_dispose(&path);
}
static void stage_random_files(char *files[])
{
char *filename;
size_t i;
write_files(files);
for (i = 0, filename = files[i]; filename; filename = files[++i])
cl_git_pass(git_index_add_bypath(repo_index, filename));
}
static void stage_content(char *content[])
{
git_reference *head;
git_object *head_object;
git_buf path = GIT_BUF_INIT;
char *filename, *text;
size_t i;
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel(&head_object, head, GIT_OBJECT_COMMIT));
cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL));
for (i = 0, filename = content[i], text = content[++i];
filename && text;
filename = content[++i], text = content[++i]) {
git_buf_clear(&path);
cl_git_pass(git_buf_printf(&path, "%s/%s", TEST_REPO_PATH, filename));
cl_git_mkfile(path.ptr, text);
cl_git_pass(git_index_add_bypath(repo_index, filename));
}
git_object_free(head_object);
git_reference_free(head);
git_buf_dispose(&path);
}
static int merge_dirty_files(char *dirty_files[])
{
git_reference *head;
git_object *head_object;
int error;
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel(&head_object, head, GIT_OBJECT_COMMIT));
cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL));
write_files(dirty_files);
error = merge_branch();
git_object_free(head_object);
git_reference_free(head);
return error;
}
static int merge_differently_filtered_files(char *files[])
{
git_reference *head;
git_object *head_object;
int error;
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel(&head_object, head, GIT_OBJECT_COMMIT));
cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL));
/* Emulate checkout with a broken or misconfigured filter: modify some
* files on-disk and then update the index with the updated file size
* and time, as if some filter applied them. These files should not be
* treated as dirty since we created them.
*
* (Make sure to update the index stamp to defeat racy-git protections
* trying to sanity check the files in the index; those would rehash the
* files, showing them as dirty, the exact mechanism we're trying to avoid.)
*/
write_files(files);
hack_index(files);
cl_git_pass(git_index_write(repo_index));
error = merge_branch();
git_object_free(head_object);
git_reference_free(head);
return error;
}
static int merge_staged_files(char *staged_files[])
{
stage_random_files(staged_files);
return merge_branch();
}
void test_merge_workdir_dirty__unaffected_dirty_files_allowed(void)
{
char **files;
size_t i;
for (i = 0, files = unaffected[i]; files[0]; files = unaffected[++i])
cl_git_pass(merge_dirty_files(files));
}
void test_merge_workdir_dirty__unstaged_deletes_maintained(void)
{
git_reference *head;
git_object *head_object;
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel(&head_object, head, GIT_OBJECT_COMMIT));
cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL));
cl_git_pass(p_unlink("merge-resolve/unchanged.txt"));
cl_git_pass(merge_branch());
git_object_free(head_object);
git_reference_free(head);
}
void test_merge_workdir_dirty__affected_dirty_files_disallowed(void)
{
char **files;
size_t i;
for (i = 0, files = affected[i]; files[0]; files = affected[++i])
cl_git_fail(merge_dirty_files(files));
}
void test_merge_workdir_dirty__staged_files_in_index_disallowed(void)
{
char **files;
size_t i;
for (i = 0, files = unaffected[i]; files[0]; files = unaffected[++i])
cl_git_fail(merge_staged_files(files));
for (i = 0, files = affected[i]; files[0]; files = affected[++i])
cl_git_fail(merge_staged_files(files));
}
void test_merge_workdir_dirty__identical_staged_files_allowed(void)
{
char **content;
size_t i;
set_core_autocrlf_to(repo, false);
for (i = 0, content = result_contents[i]; content[0]; content = result_contents[++i]) {
stage_content(content);
cl_git_pass(git_index_write(repo_index));
cl_git_pass(merge_branch());
}
}
void test_merge_workdir_dirty__honors_cache(void)
{
char **files;
size_t i;
for (i = 0, files = affected[i]; files[0]; files = affected[++i])
cl_git_pass(merge_differently_filtered_files(files));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/workdir/setup.c
|
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "merge.h"
#include "refs.h"
#include "futils.h"
static git_repository *repo;
static git_index *repo_index;
#define TEST_REPO_PATH "merge-resolve"
#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
#define ORIG_HEAD "bd593285fc7fe4ca18ccdbabf027f5d689101452"
#define THEIRS_SIMPLE_BRANCH "branch"
#define THEIRS_SIMPLE_OID "7cb63eed597130ba4abb87b3e544b85021905520"
#define OCTO1_BRANCH "octo1"
#define OCTO1_OID "16f825815cfd20a07a75c71554e82d8eede0b061"
#define OCTO2_BRANCH "octo2"
#define OCTO2_OID "158dc7bedb202f5b26502bf3574faa7f4238d56c"
#define OCTO3_BRANCH "octo3"
#define OCTO3_OID "50ce7d7d01217679e26c55939eef119e0c93e272"
#define OCTO4_BRANCH "octo4"
#define OCTO4_OID "54269b3f6ec3d7d4ede24dd350dd5d605495c3ae"
#define OCTO5_BRANCH "octo5"
#define OCTO5_OID "e4f618a2c3ed0669308735727df5ebf2447f022f"
/* Fixture setup and teardown */
void test_merge_workdir_setup__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
git_repository_index(&repo_index, repo);
}
void test_merge_workdir_setup__cleanup(void)
{
git_index_free(repo_index);
cl_git_sandbox_cleanup();
}
static bool test_file_contents(const char *filename, const char *expected)
{
git_buf file_path_buf = GIT_BUF_INIT, file_buf = GIT_BUF_INIT;
bool equals;
git_buf_joinpath(&file_path_buf, git_repository_path(repo), filename);
cl_git_pass(git_futils_readbuffer(&file_buf, file_path_buf.ptr));
equals = (strcmp(file_buf.ptr, expected) == 0);
git_buf_dispose(&file_path_buf);
git_buf_dispose(&file_buf);
return equals;
}
static void write_file_contents(const char *filename, const char *output)
{
git_buf file_path_buf = GIT_BUF_INIT;
git_buf_joinpath(&file_path_buf, git_repository_path(repo),
filename);
cl_git_rewritefile(file_path_buf.ptr, output);
git_buf_dispose(&file_path_buf);
}
/* git merge --no-ff octo1 */
void test_merge_workdir_setup__one_branch(void)
{
git_oid our_oid;
git_reference *octo1_ref;
git_annotated_commit *our_head, *their_heads[1];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 1));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "'\n"));
git_reference_free(octo1_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
}
/* git merge --no-ff 16f825815cfd20a07a75c71554e82d8eede0b061 */
void test_merge_workdir_setup__one_oid(void)
{
git_oid our_oid;
git_oid octo1_oid;
git_annotated_commit *our_head, *their_heads[1];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID));
cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_oid));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 1));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'\n"));
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
}
/* git merge octo1 octo2 */
void test_merge_workdir_setup__two_branches(void)
{
git_oid our_oid;
git_reference *octo1_ref;
git_reference *octo2_ref;
git_annotated_commit *our_head, *their_heads[2];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 2));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO2_BRANCH "'\n"));
git_reference_free(octo1_ref);
git_reference_free(octo2_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
}
/* git merge octo1 octo2 octo3 */
void test_merge_workdir_setup__three_branches(void)
{
git_oid our_oid;
git_reference *octo1_ref;
git_reference *octo2_ref;
git_reference *octo3_ref;
git_annotated_commit *our_head, *their_heads[3];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref));
cl_git_pass(git_reference_lookup(&octo3_ref, repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[2], repo, octo3_ref));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 3));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "', '" OCTO2_BRANCH "' and '" OCTO3_BRANCH "'\n"));
git_reference_free(octo1_ref);
git_reference_free(octo2_ref);
git_reference_free(octo3_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
git_annotated_commit_free(their_heads[2]);
}
/* git merge 16f825815cfd20a07a75c71554e82d8eede0b061 158dc7bedb202f5b26502bf3574faa7f4238d56c 50ce7d7d01217679e26c55939eef119e0c93e272 */
void test_merge_workdir_setup__three_oids(void)
{
git_oid our_oid;
git_oid octo1_oid;
git_oid octo2_oid;
git_oid octo3_oid;
git_annotated_commit *our_head, *their_heads[3];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID));
cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_oid));
cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID));
cl_git_pass(git_annotated_commit_lookup(&their_heads[1], repo, &octo2_oid));
cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID));
cl_git_pass(git_annotated_commit_lookup(&their_heads[2], repo, &octo3_oid));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 3));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; commit '" OCTO2_OID "'; commit '" OCTO3_OID "'\n"));
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
git_annotated_commit_free(their_heads[2]);
}
/* git merge octo1 158dc7bedb202f5b26502bf3574faa7f4238d56c */
void test_merge_workdir_setup__branches_and_oids_1(void)
{
git_oid our_oid;
git_reference *octo1_ref;
git_oid octo2_oid;
git_annotated_commit *our_head, *their_heads[2];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID));
cl_git_pass(git_annotated_commit_lookup(&their_heads[1], repo, &octo2_oid));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 2));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "'; commit '" OCTO2_OID "'\n"));
git_reference_free(octo1_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
}
/* git merge octo1 158dc7bedb202f5b26502bf3574faa7f4238d56c octo3 54269b3f6ec3d7d4ede24dd350dd5d605495c3ae */
void test_merge_workdir_setup__branches_and_oids_2(void)
{
git_oid our_oid;
git_reference *octo1_ref;
git_oid octo2_oid;
git_reference *octo3_ref;
git_oid octo4_oid;
git_annotated_commit *our_head, *their_heads[4];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID));
cl_git_pass(git_annotated_commit_lookup(&their_heads[1], repo, &octo2_oid));
cl_git_pass(git_reference_lookup(&octo3_ref, repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[2], repo, octo3_ref));
cl_git_pass(git_oid_fromstr(&octo4_oid, OCTO4_OID));
cl_git_pass(git_annotated_commit_lookup(&their_heads[3], repo, &octo4_oid));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 4));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO3_BRANCH "'; commit '" OCTO2_OID "'; commit '" OCTO4_OID "'\n"));
git_reference_free(octo1_ref);
git_reference_free(octo3_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
git_annotated_commit_free(their_heads[2]);
git_annotated_commit_free(their_heads[3]);
}
/* git merge 16f825815cfd20a07a75c71554e82d8eede0b061 octo2 50ce7d7d01217679e26c55939eef119e0c93e272 octo4 */
void test_merge_workdir_setup__branches_and_oids_3(void)
{
git_oid our_oid;
git_oid octo1_oid;
git_reference *octo2_ref;
git_oid octo3_oid;
git_reference *octo4_ref;
git_annotated_commit *our_head, *their_heads[4];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID));
cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_oid));
cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref));
cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID));
cl_git_pass(git_annotated_commit_lookup(&their_heads[2], repo, &octo3_oid));
cl_git_pass(git_reference_lookup(&octo4_ref, repo, GIT_REFS_HEADS_DIR OCTO4_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[3], repo, octo4_ref));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 4));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; branches '" OCTO2_BRANCH "' and '" OCTO4_BRANCH "'; commit '" OCTO3_OID "'\n"));
git_reference_free(octo2_ref);
git_reference_free(octo4_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
git_annotated_commit_free(their_heads[2]);
git_annotated_commit_free(their_heads[3]);
}
/* git merge 16f825815cfd20a07a75c71554e82d8eede0b061 octo2 50ce7d7d01217679e26c55939eef119e0c93e272 octo4 octo5 */
void test_merge_workdir_setup__branches_and_oids_4(void)
{
git_oid our_oid;
git_oid octo1_oid;
git_reference *octo2_ref;
git_oid octo3_oid;
git_reference *octo4_ref;
git_reference *octo5_ref;
git_annotated_commit *our_head, *their_heads[5];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID));
cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_oid));
cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref));
cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID));
cl_git_pass(git_annotated_commit_lookup(&their_heads[2], repo, &octo3_oid));
cl_git_pass(git_reference_lookup(&octo4_ref, repo, GIT_REFS_HEADS_DIR OCTO4_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[3], repo, octo4_ref));
cl_git_pass(git_reference_lookup(&octo5_ref, repo, GIT_REFS_HEADS_DIR OCTO5_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[4], repo, octo5_ref));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 5));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n" OCTO5_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; branches '" OCTO2_BRANCH "', '" OCTO4_BRANCH "' and '" OCTO5_BRANCH "'; commit '" OCTO3_OID "'\n"));
git_reference_free(octo2_ref);
git_reference_free(octo4_ref);
git_reference_free(octo5_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
git_annotated_commit_free(their_heads[2]);
git_annotated_commit_free(their_heads[3]);
git_annotated_commit_free(their_heads[4]);
}
/* git merge octo1 octo1 octo1 */
void test_merge_workdir_setup__three_same_branches(void)
{
git_oid our_oid;
git_reference *octo1_1_ref;
git_reference *octo1_2_ref;
git_reference *octo1_3_ref;
git_annotated_commit *our_head, *their_heads[3];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_reference_lookup(&octo1_1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_1_ref));
cl_git_pass(git_reference_lookup(&octo1_2_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo1_2_ref));
cl_git_pass(git_reference_lookup(&octo1_3_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[2], repo, octo1_3_ref));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 3));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO1_OID "\n" OCTO1_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "', '" OCTO1_BRANCH "' and '" OCTO1_BRANCH "'\n"));
git_reference_free(octo1_1_ref);
git_reference_free(octo1_2_ref);
git_reference_free(octo1_3_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
git_annotated_commit_free(their_heads[2]);
}
/* git merge 16f825815cfd20a07a75c71554e82d8eede0b061 16f825815cfd20a07a75c71554e82d8eede0b061 16f825815cfd20a07a75c71554e82d8eede0b061 */
void test_merge_workdir_setup__three_same_oids(void)
{
git_oid our_oid;
git_oid octo1_1_oid;
git_oid octo1_2_oid;
git_oid octo1_3_oid;
git_annotated_commit *our_head, *their_heads[3];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_oid_fromstr(&octo1_1_oid, OCTO1_OID));
cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_1_oid));
cl_git_pass(git_oid_fromstr(&octo1_2_oid, OCTO1_OID));
cl_git_pass(git_annotated_commit_lookup(&their_heads[1], repo, &octo1_2_oid));
cl_git_pass(git_oid_fromstr(&octo1_3_oid, OCTO1_OID));
cl_git_pass(git_annotated_commit_lookup(&their_heads[2], repo, &octo1_3_oid));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 3));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO1_OID "\n" OCTO1_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; commit '" OCTO1_OID "'; commit '" OCTO1_OID "'\n"));
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
git_annotated_commit_free(their_heads[2]);
}
static int create_remote_tracking_branch(const char *branch_name, const char *oid_str)
{
int error = 0;
git_buf remotes_path = GIT_BUF_INIT,
origin_path = GIT_BUF_INIT,
filename = GIT_BUF_INIT,
data = GIT_BUF_INIT;
if ((error = git_buf_puts(&remotes_path, git_repository_path(repo))) < 0 ||
(error = git_buf_puts(&remotes_path, GIT_REFS_REMOTES_DIR)) < 0)
goto done;
if (!git_path_exists(git_buf_cstr(&remotes_path)) &&
(error = p_mkdir(git_buf_cstr(&remotes_path), 0777)) < 0)
goto done;
if ((error = git_buf_puts(&origin_path, git_buf_cstr(&remotes_path))) < 0 ||
(error = git_buf_puts(&origin_path, "origin")) < 0)
goto done;
if (!git_path_exists(git_buf_cstr(&origin_path)) &&
(error = p_mkdir(git_buf_cstr(&origin_path), 0777)) < 0)
goto done;
if ((error = git_buf_puts(&filename, git_buf_cstr(&origin_path))) < 0 ||
(error = git_buf_puts(&filename, "/")) < 0 ||
(error = git_buf_puts(&filename, branch_name)) < 0 ||
(error = git_buf_puts(&data, oid_str)) < 0 ||
(error = git_buf_puts(&data, "\n")) < 0)
goto done;
cl_git_rewritefile(git_buf_cstr(&filename), git_buf_cstr(&data));
done:
git_buf_dispose(&remotes_path);
git_buf_dispose(&origin_path);
git_buf_dispose(&filename);
git_buf_dispose(&data);
return error;
}
/* git merge refs/remotes/origin/octo1 */
void test_merge_workdir_setup__remote_tracking_one_branch(void)
{
git_oid our_oid;
git_reference *octo1_ref;
git_annotated_commit *our_head, *their_heads[1];
cl_git_pass(create_remote_tracking_branch(OCTO1_BRANCH, OCTO1_OID));
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 1));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge remote-tracking branch 'refs/remotes/origin/" OCTO1_BRANCH "'\n"));
git_reference_free(octo1_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
}
/* git merge refs/remotes/origin/octo1 refs/remotes/origin/octo2 */
void test_merge_workdir_setup__remote_tracking_two_branches(void)
{
git_oid our_oid;
git_reference *octo1_ref;
git_reference *octo2_ref;
git_annotated_commit *our_head, *their_heads[2];
cl_git_pass(create_remote_tracking_branch(OCTO1_BRANCH, OCTO1_OID));
cl_git_pass(create_remote_tracking_branch(OCTO2_BRANCH, OCTO2_OID));
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO2_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 2));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge remote-tracking branches 'refs/remotes/origin/" OCTO1_BRANCH "' and 'refs/remotes/origin/" OCTO2_BRANCH "'\n"));
git_reference_free(octo1_ref);
git_reference_free(octo2_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
}
/* git merge refs/remotes/origin/octo1 refs/remotes/origin/octo2 refs/remotes/origin/octo3 */
void test_merge_workdir_setup__remote_tracking_three_branches(void)
{
git_oid our_oid;
git_reference *octo1_ref;
git_reference *octo2_ref;
git_reference *octo3_ref;
git_annotated_commit *our_head, *their_heads[3];
cl_git_pass(create_remote_tracking_branch(OCTO1_BRANCH, OCTO1_OID));
cl_git_pass(create_remote_tracking_branch(OCTO2_BRANCH, OCTO2_OID));
cl_git_pass(create_remote_tracking_branch(OCTO3_BRANCH, OCTO3_OID));
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO2_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref));
cl_git_pass(git_reference_lookup(&octo3_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO3_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[2], repo, octo3_ref));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 3));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge remote-tracking branches 'refs/remotes/origin/" OCTO1_BRANCH "', 'refs/remotes/origin/" OCTO2_BRANCH "' and 'refs/remotes/origin/" OCTO3_BRANCH "'\n"));
git_reference_free(octo1_ref);
git_reference_free(octo2_ref);
git_reference_free(octo3_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
git_annotated_commit_free(their_heads[2]);
}
/* git merge octo1 refs/remotes/origin/octo2 */
void test_merge_workdir_setup__normal_branch_and_remote_tracking_branch(void)
{
git_oid our_oid;
git_reference *octo1_ref;
git_reference *octo2_ref;
git_annotated_commit *our_head, *their_heads[2];
cl_git_pass(create_remote_tracking_branch(OCTO2_BRANCH, OCTO2_OID));
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO2_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 2));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "', remote-tracking branch 'refs/remotes/origin/" OCTO2_BRANCH "'\n"));
git_reference_free(octo1_ref);
git_reference_free(octo2_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
}
/* git merge refs/remotes/origin/octo1 octo2 */
void test_merge_workdir_setup__remote_tracking_branch_and_normal_branch(void)
{
git_oid our_oid;
git_reference *octo1_ref;
git_reference *octo2_ref;
git_annotated_commit *our_head, *their_heads[2];
cl_git_pass(create_remote_tracking_branch(OCTO1_BRANCH, OCTO1_OID));
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 2));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO2_BRANCH "', remote-tracking branch 'refs/remotes/origin/" OCTO1_BRANCH "'\n"));
git_reference_free(octo1_ref);
git_reference_free(octo2_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
}
/* git merge octo1 refs/remotes/origin/octo2 octo3 refs/remotes/origin/octo4 */
void test_merge_workdir_setup__two_remote_tracking_branch_and_two_normal_branches(void)
{
git_oid our_oid;
git_reference *octo1_ref;
git_reference *octo2_ref;
git_reference *octo3_ref;
git_reference *octo4_ref;
git_annotated_commit *our_head, *their_heads[4];
cl_git_pass(create_remote_tracking_branch(OCTO2_BRANCH, OCTO2_OID));
cl_git_pass(create_remote_tracking_branch(OCTO4_BRANCH, OCTO4_OID));
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO2_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref));
cl_git_pass(git_reference_lookup(&octo3_ref, repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[2], repo, octo3_ref));
cl_git_pass(git_reference_lookup(&octo4_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO4_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[3], repo, octo4_ref));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 4));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO3_BRANCH "', remote-tracking branches 'refs/remotes/origin/" OCTO2_BRANCH "' and 'refs/remotes/origin/" OCTO4_BRANCH "'\n"));
git_reference_free(octo1_ref);
git_reference_free(octo2_ref);
git_reference_free(octo3_ref);
git_reference_free(octo4_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
git_annotated_commit_free(their_heads[2]);
git_annotated_commit_free(their_heads[3]);
}
/* git pull origin branch octo1 */
void test_merge_workdir_setup__pull_one(void)
{
git_oid our_oid;
git_oid octo1_1_oid;
git_annotated_commit *our_head, *their_heads[1];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_oid_fromstr(&octo1_1_oid, OCTO1_OID));
cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[0], repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH, "http://remote.url/repo.git", &octo1_1_oid));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 1));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch 'octo1' of http://remote.url/repo.git\n"));
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
}
/* git pull origin octo1 octo2 */
void test_merge_workdir_setup__pull_two(void)
{
git_oid our_oid;
git_oid octo1_oid;
git_oid octo2_oid;
git_annotated_commit *our_head, *their_heads[2];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID));
cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[0], repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH, "http://remote.url/repo.git", &octo1_oid));
cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID));
cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[1], repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH, "http://remote.url/repo.git", &octo2_oid));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 2));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO2_BRANCH "' of http://remote.url/repo.git\n"));
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
}
/* git pull origin octo1 octo2 octo3 */
void test_merge_workdir_setup__pull_three(void)
{
git_oid our_oid;
git_oid octo1_oid;
git_oid octo2_oid;
git_oid octo3_oid;
git_annotated_commit *our_head, *their_heads[3];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID));
cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[0], repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH, "http://remote.url/repo.git", &octo1_oid));
cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID));
cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[1], repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH, "http://remote.url/repo.git", &octo2_oid));
cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID));
cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[2], repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH, "http://remote.url/repo.git", &octo3_oid));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 3));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "', '" OCTO2_BRANCH "' and '" OCTO3_BRANCH "' of http://remote.url/repo.git\n"));
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
git_annotated_commit_free(their_heads[2]);
}
void test_merge_workdir_setup__three_remotes(void)
{
git_oid our_oid;
git_oid octo1_oid;
git_oid octo2_oid;
git_oid octo3_oid;
git_annotated_commit *our_head, *their_heads[3];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID));
cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[0], repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH, "http://remote.first/repo.git", &octo1_oid));
cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID));
cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[1], repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH, "http://remote.second/repo.git", &octo2_oid));
cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID));
cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[2], repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH, "http://remote.third/repo.git", &octo3_oid));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 3));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "' of http://remote.first/repo.git, branch '" OCTO2_BRANCH "' of http://remote.second/repo.git, branch '" OCTO3_BRANCH "' of http://remote.third/repo.git\n"));
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
git_annotated_commit_free(their_heads[2]);
}
void test_merge_workdir_setup__two_remotes(void)
{
git_oid our_oid;
git_oid octo1_oid;
git_oid octo2_oid;
git_oid octo3_oid;
git_oid octo4_oid;
git_annotated_commit *our_head, *their_heads[4];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID));
cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[0], repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH, "http://remote.first/repo.git", &octo1_oid));
cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID));
cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[1], repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH, "http://remote.second/repo.git", &octo2_oid));
cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID));
cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[2], repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH, "http://remote.first/repo.git", &octo3_oid));
cl_git_pass(git_oid_fromstr(&octo4_oid, OCTO4_OID));
cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[3], repo, GIT_REFS_HEADS_DIR OCTO4_BRANCH, "http://remote.second/repo.git", &octo4_oid));
cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 4));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO3_BRANCH "' of http://remote.first/repo.git, branches '" OCTO2_BRANCH "' and '" OCTO4_BRANCH "' of http://remote.second/repo.git\n"));
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
git_annotated_commit_free(their_heads[1]);
git_annotated_commit_free(their_heads[2]);
git_annotated_commit_free(their_heads[3]);
}
void test_merge_workdir_setup__id_from_head(void)
{
git_oid expected_id;
const git_oid *id;
git_reference *ref;
git_annotated_commit *heads[3];
cl_git_pass(git_oid_fromstr(&expected_id, OCTO1_OID));
cl_git_pass(git_annotated_commit_from_fetchhead(&heads[0], repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH, "http://remote.url/repo.git", &expected_id));
id = git_annotated_commit_id(heads[0]);
cl_assert_equal_i(1, git_oid_equal(id, &expected_id));
cl_git_pass(git_annotated_commit_lookup(&heads[1], repo, &expected_id));
id = git_annotated_commit_id(heads[1]);
cl_assert_equal_i(1, git_oid_equal(id, &expected_id));
cl_git_pass(git_reference_lookup(&ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&heads[2], repo, ref));
id = git_annotated_commit_id(heads[2]);
cl_assert_equal_i(1, git_oid_equal(id, &expected_id));
git_reference_free(ref);
git_annotated_commit_free(heads[0]);
git_annotated_commit_free(heads[1]);
git_annotated_commit_free(heads[2]);
}
struct annotated_commit_cb_data {
const char **oid_str;
unsigned int len;
unsigned int i;
};
static int annotated_commit_foreach_cb(const git_oid *oid, void *payload)
{
git_oid expected_oid;
struct annotated_commit_cb_data *cb_data = payload;
git_oid_fromstr(&expected_oid, cb_data->oid_str[cb_data->i]);
cl_assert(git_oid_cmp(&expected_oid, oid) == 0);
cb_data->i++;
return 0;
}
void test_merge_workdir_setup__head_notfound(void)
{
int error;
cl_git_fail((error = git_repository_mergehead_foreach(repo,
annotated_commit_foreach_cb, NULL)));
cl_assert(error == GIT_ENOTFOUND);
}
void test_merge_workdir_setup__head_invalid_oid(void)
{
int error;
write_file_contents(GIT_MERGE_HEAD_FILE, "invalid-oid\n");
cl_git_fail((error = git_repository_mergehead_foreach(repo,
annotated_commit_foreach_cb, NULL)));
cl_assert(error == -1);
}
void test_merge_workdir_setup__head_foreach_nonewline(void)
{
int error;
write_file_contents(GIT_MERGE_HEAD_FILE, THEIRS_SIMPLE_OID);
cl_git_fail((error = git_repository_mergehead_foreach(repo,
annotated_commit_foreach_cb, NULL)));
cl_assert(error == -1);
}
void test_merge_workdir_setup__head_foreach_one(void)
{
const char *expected = THEIRS_SIMPLE_OID;
struct annotated_commit_cb_data cb_data = { &expected, 1 };
write_file_contents(GIT_MERGE_HEAD_FILE, THEIRS_SIMPLE_OID "\n");
cl_git_pass(git_repository_mergehead_foreach(repo,
annotated_commit_foreach_cb, &cb_data));
cl_assert(cb_data.i == cb_data.len);
}
void test_merge_workdir_setup__head_foreach_octopus(void)
{
const char *expected[] = { THEIRS_SIMPLE_OID,
OCTO1_OID, OCTO2_OID, OCTO3_OID, OCTO4_OID, OCTO5_OID };
struct annotated_commit_cb_data cb_data = { expected, 6 };
write_file_contents(GIT_MERGE_HEAD_FILE,
THEIRS_SIMPLE_OID "\n"
OCTO1_OID "\n"
OCTO2_OID "\n"
OCTO3_OID "\n"
OCTO4_OID "\n"
OCTO5_OID "\n");
cl_git_pass(git_repository_mergehead_foreach(repo,
annotated_commit_foreach_cb, &cb_data));
cl_assert(cb_data.i == cb_data.len);
}
void test_merge_workdir_setup__retained_after_success(void)
{
git_oid our_oid;
git_reference *octo1_ref;
git_annotated_commit *our_head, *their_heads[1];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)&their_heads[0], 1, NULL, NULL));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff"));
cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "'\n"));
git_reference_free(octo1_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
}
void test_merge_workdir_setup__removed_after_failure(void)
{
git_oid our_oid;
git_reference *octo1_ref;
git_annotated_commit *our_head, *their_heads[1];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
cl_git_write2file("merge-resolve/.git/index.lock", "foo\n", 4, O_RDWR|O_CREAT, 0666);
cl_git_fail(git_merge(
repo, (const git_annotated_commit **)&their_heads[0], 1, NULL, NULL));
cl_assert(!git_path_exists("merge-resolve/.git/" GIT_MERGE_HEAD_FILE));
cl_assert(!git_path_exists("merge-resolve/.git/" GIT_MERGE_MODE_FILE));
cl_assert(!git_path_exists("merge-resolve/.git/" GIT_MERGE_MSG_FILE));
git_reference_free(octo1_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
}
void test_merge_workdir_setup__unlocked_after_success(void)
{
git_oid our_oid;
git_reference *octo1_ref;
git_annotated_commit *our_head, *their_heads[1];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
cl_git_pass(git_merge(
repo, (const git_annotated_commit **)&their_heads[0], 1, NULL, NULL));
cl_assert(!git_path_exists("merge-resolve/.git/index.lock"));
git_reference_free(octo1_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
}
void test_merge_workdir_setup__unlocked_after_conflict(void)
{
git_oid our_oid;
git_reference *octo1_ref;
git_annotated_commit *our_head, *their_heads[1];
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid));
cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref));
cl_git_rewritefile("merge-resolve/new-in-octo1.txt",
"Conflicting file!\n\nMerge will fail!\n");
cl_git_fail(git_merge(
repo, (const git_annotated_commit **)&their_heads[0], 1, NULL, NULL));
cl_assert(!git_path_exists("merge-resolve/.git/index.lock"));
git_reference_free(octo1_ref);
git_annotated_commit_free(our_head);
git_annotated_commit_free(their_heads[0]);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/workdir/trivial.c
|
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "git2/sys/index.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "refs.h"
#include "futils.h"
static git_repository *repo;
static git_index *repo_index;
#define TEST_REPO_PATH "merge-resolve"
#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
/* Fixture setup and teardown */
void test_merge_workdir_trivial__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
git_repository_index(&repo_index, repo);
}
void test_merge_workdir_trivial__cleanup(void)
{
git_index_free(repo_index);
cl_git_sandbox_cleanup();
}
static int merge_trivial(const char *ours, const char *theirs)
{
git_buf branch_buf = GIT_BUF_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
git_reference *our_ref, *their_ref;
git_annotated_commit *their_heads[1];
checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours);
cl_git_pass(git_reference_symbolic_create(&our_ref, repo, "HEAD", branch_buf.ptr, 1, NULL));
cl_git_pass(git_checkout_head(repo, &checkout_opts));
git_buf_clear(&branch_buf);
git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs);
cl_git_pass(git_reference_lookup(&their_ref, repo, branch_buf.ptr));
cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, their_ref));
cl_git_pass(git_merge(repo, (const git_annotated_commit **)their_heads, 1, NULL, NULL));
git_buf_dispose(&branch_buf);
git_reference_free(our_ref);
git_reference_free(their_ref);
git_annotated_commit_free(their_heads[0]);
return 0;
}
static size_t merge_trivial_conflict_entrycount(void)
{
const git_index_entry *entry;
size_t count = 0;
size_t i;
for (i = 0; i < git_index_entrycount(repo_index); i++) {
cl_assert(entry = git_index_get_byindex(repo_index, i));
if (git_index_entry_is_conflict(entry))
count++;
}
return count;
}
/* 2ALT: ancest:(empty)+, head:*empty*, remote:remote = result:remote */
void test_merge_workdir_trivial__2alt(void)
{
const git_index_entry *entry;
cl_git_pass(merge_trivial("trivial-2alt", "trivial-2alt-branch"));
cl_assert(entry = git_index_get_bypath(repo_index, "new-in-branch.txt", 0));
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
cl_assert(merge_trivial_conflict_entrycount() == 0);
}
/* 3ALT: ancest:(empty)+, head:head, remote:*empty* = result:head */
void test_merge_workdir_trivial__3alt(void)
{
const git_index_entry *entry;
cl_git_pass(merge_trivial("trivial-3alt", "trivial-3alt-branch"));
cl_assert(entry = git_index_get_bypath(repo_index, "new-in-3alt.txt", 0));
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
cl_assert(merge_trivial_conflict_entrycount() == 0);
}
/* 4: ancest:(empty)^, head:head, remote:remote = result:no merge */
void test_merge_workdir_trivial__4(void)
{
const git_index_entry *entry;
cl_git_pass(merge_trivial("trivial-4", "trivial-4-branch"));
cl_assert((entry = git_index_get_bypath(repo_index, "new-and-different.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
cl_assert(merge_trivial_conflict_entrycount() == 2);
cl_assert(entry = git_index_get_bypath(repo_index, "new-and-different.txt", 2));
cl_assert(entry = git_index_get_bypath(repo_index, "new-and-different.txt", 3));
}
/* 5ALT: ancest:*, head:head, remote:head = result:head */
void test_merge_workdir_trivial__5alt_1(void)
{
const git_index_entry *entry;
cl_git_pass(merge_trivial("trivial-5alt-1", "trivial-5alt-1-branch"));
cl_assert(entry = git_index_get_bypath(repo_index, "new-and-same.txt", 0));
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
cl_assert(merge_trivial_conflict_entrycount() == 0);
}
/* 5ALT: ancest:*, head:head, remote:head = result:head */
void test_merge_workdir_trivial__5alt_2(void)
{
const git_index_entry *entry;
cl_git_pass(merge_trivial("trivial-5alt-2", "trivial-5alt-2-branch"));
cl_assert(entry = git_index_get_bypath(repo_index, "modified-to-same.txt", 0));
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
cl_assert(merge_trivial_conflict_entrycount() == 0);
}
/* 6: ancest:ancest+, head:(empty), remote:(empty) = result:no merge */
void test_merge_workdir_trivial__6(void)
{
const git_index_entry *entry;
const git_index_reuc_entry *reuc;
cl_git_pass(merge_trivial("trivial-6", "trivial-6-branch"));
cl_assert((entry = git_index_get_bypath(repo_index, "removed-in-both.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(repo_index) == 1);
cl_assert(reuc = git_index_reuc_get_bypath(repo_index, "removed-in-both.txt"));
cl_assert(merge_trivial_conflict_entrycount() == 0);
}
/* 8: ancest:ancest^, head:(empty), remote:ancest = result:no merge */
void test_merge_workdir_trivial__8(void)
{
const git_index_entry *entry;
const git_index_reuc_entry *reuc;
cl_git_pass(merge_trivial("trivial-8", "trivial-8-branch"));
cl_assert((entry = git_index_get_bypath(repo_index, "removed-in-8.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(repo_index) == 1);
cl_assert(reuc = git_index_reuc_get_bypath(repo_index, "removed-in-8.txt"));
cl_assert(merge_trivial_conflict_entrycount() == 0);
}
/* 7: ancest:ancest+, head:(empty), remote:remote = result:no merge */
void test_merge_workdir_trivial__7(void)
{
const git_index_entry *entry;
cl_git_pass(merge_trivial("trivial-7", "trivial-7-branch"));
cl_assert((entry = git_index_get_bypath(repo_index, "removed-in-7.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
cl_assert(merge_trivial_conflict_entrycount() == 2);
cl_assert(entry = git_index_get_bypath(repo_index, "removed-in-7.txt", 1));
cl_assert(entry = git_index_get_bypath(repo_index, "removed-in-7.txt", 3));
}
/* 10: ancest:ancest^, head:ancest, remote:(empty) = result:no merge */
void test_merge_workdir_trivial__10(void)
{
const git_index_entry *entry;
const git_index_reuc_entry *reuc;
cl_git_pass(merge_trivial("trivial-10", "trivial-10-branch"));
cl_assert((entry = git_index_get_bypath(repo_index, "removed-in-10-branch.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(repo_index) == 1);
cl_assert(reuc = git_index_reuc_get_bypath(repo_index, "removed-in-10-branch.txt"));
cl_assert(merge_trivial_conflict_entrycount() == 0);
}
/* 9: ancest:ancest+, head:head, remote:(empty) = result:no merge */
void test_merge_workdir_trivial__9(void)
{
const git_index_entry *entry;
cl_git_pass(merge_trivial("trivial-9", "trivial-9-branch"));
cl_assert((entry = git_index_get_bypath(repo_index, "removed-in-9-branch.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
cl_assert(merge_trivial_conflict_entrycount() == 2);
cl_assert(entry = git_index_get_bypath(repo_index, "removed-in-9-branch.txt", 1));
cl_assert(entry = git_index_get_bypath(repo_index, "removed-in-9-branch.txt", 2));
}
/* 13: ancest:ancest+, head:head, remote:ancest = result:head */
void test_merge_workdir_trivial__13(void)
{
const git_index_entry *entry;
git_oid expected_oid;
cl_git_pass(merge_trivial("trivial-13", "trivial-13-branch"));
cl_assert(entry = git_index_get_bypath(repo_index, "modified-in-13.txt", 0));
cl_git_pass(git_oid_fromstr(&expected_oid, "1cff9ec6a47a537380dedfdd17c9e76d74259a2b"));
cl_assert(git_oid_cmp(&entry->id, &expected_oid) == 0);
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
cl_assert(merge_trivial_conflict_entrycount() == 0);
}
/* 14: ancest:ancest+, head:ancest, remote:remote = result:remote */
void test_merge_workdir_trivial__14(void)
{
const git_index_entry *entry;
git_oid expected_oid;
cl_git_pass(merge_trivial("trivial-14", "trivial-14-branch"));
cl_assert(entry = git_index_get_bypath(repo_index, "modified-in-14-branch.txt", 0));
cl_git_pass(git_oid_fromstr(&expected_oid, "26153a3ff3649b6c2bb652d3f06878c6e0a172f9"));
cl_assert(git_oid_cmp(&entry->id, &expected_oid) == 0);
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
cl_assert(merge_trivial_conflict_entrycount() == 0);
}
/* 11: ancest:ancest+, head:head, remote:remote = result:no merge */
void test_merge_workdir_trivial__11(void)
{
const git_index_entry *entry;
cl_git_pass(merge_trivial("trivial-11", "trivial-11-branch"));
cl_assert((entry = git_index_get_bypath(repo_index, "modified-in-both.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(repo_index) == 0);
cl_assert(merge_trivial_conflict_entrycount() == 3);
cl_assert(entry = git_index_get_bypath(repo_index, "modified-in-both.txt", 1));
cl_assert(entry = git_index_get_bypath(repo_index, "modified-in-both.txt", 2));
cl_assert(entry = git_index_get_bypath(repo_index, "modified-in-both.txt", 3));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/trees/treediff.c
|
#include "clar_libgit2.h"
#include "git2/tree.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "diff.h"
#include "diff_tform.h"
#include "git2/sys/hashsig.h"
static git_repository *repo;
#define TEST_REPO_PATH "merge-resolve"
#define TREE_OID_ANCESTOR "0d52e3a556e189ba0948ae56780918011c1b167d"
#define TREE_OID_MASTER "1f81433e3161efbf250576c58fede7f6b836f3d3"
#define TREE_OID_BRANCH "eea9286df54245fea72c5b557291470eb825f38f"
#define TREE_OID_RENAMES1 "f5f9dd5886a6ee20272be0aafc790cba43b31931"
#define TREE_OID_RENAMES2 "5fbfbdc04b4eca46f54f4853a3c5a1dce28f5165"
#define TREE_OID_DF_ANCESTOR "b8a3a806d3950e8c0a03a34f234a92eff0e2c68d"
#define TREE_OID_DF_SIDE1 "ee1d6f164893c1866a323f072eeed36b855656be"
#define TREE_OID_DF_SIDE2 "6178885b38fe96e825ac0f492c0a941f288b37f6"
#define TREE_OID_RENAME_CONFLICT_ANCESTOR "476dbb3e207313d1d8aaa120c6ad204bf1295e53"
#define TREE_OID_RENAME_CONFLICT_OURS "c4efe31e9decccc8b2b4d3df9aac2cdfe2995618"
#define TREE_OID_RENAME_CONFLICT_THEIRS "9e7f4359c469f309b6057febf4c6e80742cbed5b"
void test_merge_trees_treediff__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
}
void test_merge_trees_treediff__cleanup(void)
{
cl_git_sandbox_cleanup();
}
static void test_find_differences(
const char *ancestor_oidstr,
const char *ours_oidstr,
const char *theirs_oidstr,
struct merge_index_conflict_data *treediff_conflict_data,
size_t treediff_conflict_data_len)
{
git_merge_diff_list *merge_diff_list = git_merge_diff_list__alloc(repo);
git_oid ancestor_oid, ours_oid, theirs_oid;
git_tree *ancestor_tree, *ours_tree, *theirs_tree;
git_iterator *ancestor_iter, *ours_iter, *theirs_iter;
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
opts.flags |= GIT_MERGE_FIND_RENAMES;
opts.target_limit = 1000;
opts.rename_threshold = 50;
opts.metric = git__malloc(sizeof(git_diff_similarity_metric));
cl_assert(opts.metric != NULL);
opts.metric->file_signature = git_diff_find_similar__hashsig_for_file;
opts.metric->buffer_signature = git_diff_find_similar__hashsig_for_buf;
opts.metric->free_signature = git_diff_find_similar__hashsig_free;
opts.metric->similarity = git_diff_find_similar__calc_similarity;
opts.metric->payload = (void *)GIT_HASHSIG_SMART_WHITESPACE;
cl_git_pass(git_oid_fromstr(&ancestor_oid, ancestor_oidstr));
cl_git_pass(git_oid_fromstr(&ours_oid, ours_oidstr));
cl_git_pass(git_oid_fromstr(&theirs_oid, theirs_oidstr));
cl_git_pass(git_tree_lookup(&ancestor_tree, repo, &ancestor_oid));
cl_git_pass(git_tree_lookup(&ours_tree, repo, &ours_oid));
cl_git_pass(git_tree_lookup(&theirs_tree, repo, &theirs_oid));
iter_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&ancestor_iter, ancestor_tree, &iter_opts));
cl_git_pass(git_iterator_for_tree(&ours_iter, ours_tree, &iter_opts));
cl_git_pass(git_iterator_for_tree(&theirs_iter, theirs_tree, &iter_opts));
cl_git_pass(git_merge_diff_list__find_differences(merge_diff_list, ancestor_iter, ours_iter, theirs_iter));
cl_git_pass(git_merge_diff_list__find_renames(repo, merge_diff_list, &opts));
/*
dump_merge_index(merge_index);
*/
cl_assert(treediff_conflict_data_len == merge_diff_list->conflicts.length);
cl_assert(merge_test_merge_conflicts(&merge_diff_list->conflicts, treediff_conflict_data, treediff_conflict_data_len));
git_iterator_free(ancestor_iter);
git_iterator_free(ours_iter);
git_iterator_free(theirs_iter);
git_tree_free(ancestor_tree);
git_tree_free(ours_tree);
git_tree_free(theirs_tree);
git_merge_diff_list__free(merge_diff_list);
git__free(opts.metric);
}
void test_merge_trees_treediff__simple(void)
{
struct merge_index_conflict_data treediff_conflict_data[] = {
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "233c0919c998ed110a4b6ff36f353aec8b713487", 0, "added-in-master.txt" }, GIT_DELTA_ADDED },
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_NONE
},
{
{ { 0100644, "6212c31dab5e482247d7977e4f0dd3601decf13b", 0, "automergeable.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", 0, "automergeable.txt" }, GIT_DELTA_MODIFIED },
{ { 0100644, "058541fc37114bfc1dddf6bd6bffc7fae5c2e6fe", 0, "automergeable.txt" }, GIT_DELTA_MODIFIED },
GIT_MERGE_DIFF_BOTH_MODIFIED
},
{
{ { 0100644, "ab6c44a2e84492ad4b41bb6bac87353e9d02ac8b", 0, "changed-in-branch.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "ab6c44a2e84492ad4b41bb6bac87353e9d02ac8b", 0, "changed-in-branch.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "4eb04c9e79e88f6640d01ff5b25ca2a60764f216", 0, "changed-in-branch.txt" }, GIT_DELTA_MODIFIED },
GIT_MERGE_DIFF_NONE
},
{
{ { 0100644, "ab6c44a2e84492ad4b41bb6bac87353e9d02ac8b", 0, "changed-in-master.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "11deab00b2d3a6f5a3073988ac050c2d7b6655e2", 0, "changed-in-master.txt" }, GIT_DELTA_MODIFIED },
{ { 0100644, "ab6c44a2e84492ad4b41bb6bac87353e9d02ac8b", 0, "changed-in-master.txt" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_NONE
},
{
{ { 0100644, "d427e0b2e138501a3d15cc376077a3631e15bd46", 0, "conflicting.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 0, "conflicting.txt" }, GIT_DELTA_MODIFIED },
{ { 0100644, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", 0, "conflicting.txt" }, GIT_DELTA_MODIFIED },
GIT_MERGE_DIFF_BOTH_MODIFIED
},
{
{ { 0100644, "dfe3f22baa1f6fce5447901c3086bae368de6bdd", 0, "removed-in-branch.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "dfe3f22baa1f6fce5447901c3086bae368de6bdd", 0, "removed-in-branch.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
GIT_MERGE_DIFF_NONE
},
{
{ { 0100644, "5c3b68a71fc4fa5d362fd3875e53137c6a5ab7a5", 0, "removed-in-master.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
{ { 0100644, "5c3b68a71fc4fa5d362fd3875e53137c6a5ab7a5", 0, "removed-in-master.txt" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_NONE
},
};
test_find_differences(TREE_OID_ANCESTOR, TREE_OID_MASTER, TREE_OID_BRANCH, treediff_conflict_data, 7);
}
void test_merge_trees_treediff__df_conflicts(void)
{
struct merge_index_conflict_data treediff_conflict_data[] = {
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "49130a28ef567af9a6a6104c38773fedfa5f9742", 0, "dir-10" }, GIT_DELTA_ADDED },
{ { 0100644, "6c06dcd163587c2cc18be44857e0b71116382aeb", 0, "dir-10" }, GIT_DELTA_ADDED },
GIT_MERGE_DIFF_BOTH_ADDED,
},
{
{ { 0100644, "242591eb280ee9eeb2ce63524b9a8b9bc4cb515d", 0, "dir-10/file.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
GIT_MERGE_DIFF_BOTH_DELETED,
},
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "43aafd43bea779ec74317dc361f45ae3f532a505", 0, "dir-6" }, GIT_DELTA_ADDED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0100644, "cf8c5cc8a85a1ff5a4ba51e0bc7cf5665669924d", 0, "dir-6/file.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "cf8c5cc8a85a1ff5a4ba51e0bc7cf5665669924d", 0, "dir-6/file.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "a031a28ae70e33a641ce4b8a8f6317f1ab79dee4", 0, "dir-7" }, GIT_DELTA_ADDED },
GIT_MERGE_DIFF_DIRECTORY_FILE,
},
{
{ { 0100644, "5012fd565b1393bdfda1805d4ec38ce6619e1fd1", 0, "dir-7/file.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "a5563304ddf6caba25cb50323a2ea6f7dbfcadca", 0, "dir-7/file.txt" }, GIT_DELTA_MODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
GIT_MERGE_DIFF_DF_CHILD,
},
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "e9ad6ec3e38364a3d07feda7c4197d4d845c53b5", 0, "dir-8" }, GIT_DELTA_ADDED },
{ {0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0100644, "f20c9063fa0bda9a397c96947a7b687305c49753", 0, "dir-8/file.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
{ { 0100644, "f20c9063fa0bda9a397c96947a7b687305c49753", 0, "dir-8/file.txt" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "3ef4d30382ca33fdeba9fda895a99e0891ba37aa", 0, "dir-9" }, GIT_DELTA_ADDED },
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_DIRECTORY_FILE,
},
{
{ { 0100644, "fc4c636d6515e9e261f9260dbcf3cc6eca97ea08", 0, "dir-9/file.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
{ { 0100644, "76ab0e2868197ec158ddd6c78d8a0d2fd73d38f9", 0, "dir-9/file.txt" }, GIT_DELTA_MODIFIED },
GIT_MERGE_DIFF_DF_CHILD,
},
{
{ { 0100644, "1e4ff029aee68d0d69ef9eb6efa6cbf1ec732f99", 0, "file-1" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "1e4ff029aee68d0d69ef9eb6efa6cbf1ec732f99", 0, "file-1" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "5c2411f8075f48a6b2fdb85ebc0d371747c4df15", 0, "file-1/new" }, GIT_DELTA_ADDED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0100644, "a39a620dae5bc8b4e771cd4d251b7d080401a21e", 0, "file-2" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "d963979c237d08b6ba39062ee7bf64c7d34a27f8", 0, "file-2" }, GIT_DELTA_MODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
GIT_MERGE_DIFF_DIRECTORY_FILE,
},
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "5c341ead2ba6f2af98ce5ec3fe84f6b6d2899c0d", 0, "file-2/new" }, GIT_DELTA_ADDED },
GIT_MERGE_DIFF_DF_CHILD,
},
{
{ { 0100644, "032ebc5ab85d9553bb187d3cd40875ff23a63ed0", 0, "file-3" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
{ { 0100644, "032ebc5ab85d9553bb187d3cd40875ff23a63ed0", 0, "file-3" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "9efe7723802d4305142eee177e018fee1572c4f4", 0, "file-3/new" }, GIT_DELTA_ADDED },
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0100644, "bacac9b3493509aa15e1730e1545fc0919d1dae0", 0, "file-4" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
{ { 0100644, "7663fce0130db092936b137cabd693ec234eb060", 0, "file-4" }, GIT_DELTA_MODIFIED },
GIT_MERGE_DIFF_DIRECTORY_FILE,
},
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "e49f917b448d1340b31d76e54ba388268fd4c922", 0, "file-4/new" }, GIT_DELTA_ADDED },
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_DF_CHILD,
},
{
{ { 0100644, "ac4045f965119e6998f4340ed0f411decfb3ec05", 0, "file-5" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
GIT_MERGE_DIFF_BOTH_DELETED,
},
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "cab2cf23998b40f1af2d9d9a756dc9e285a8df4b", 0, "file-5/new" }, GIT_DELTA_ADDED },
{ { 0100644, "f5504f36e6f4eb797a56fc5bac6c6c7f32969bf2", 0, "file-5/new" }, GIT_DELTA_ADDED },
GIT_MERGE_DIFF_BOTH_ADDED,
},
};
test_find_differences(TREE_OID_DF_ANCESTOR, TREE_OID_DF_SIDE1, TREE_OID_DF_SIDE2, treediff_conflict_data, 20);
}
void test_merge_trees_treediff__strict_renames(void)
{
struct merge_index_conflict_data treediff_conflict_data[] = {
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "233c0919c998ed110a4b6ff36f353aec8b713487", 0, "added-in-master.txt" }, GIT_DELTA_ADDED },
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0100644, "6212c31dab5e482247d7977e4f0dd3601decf13b", 0, "automergeable.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", 0, "automergeable.txt" }, GIT_DELTA_MODIFIED },
{ { 0100644, "6212c31dab5e482247d7977e4f0dd3601decf13b", 0, "automergeable.txt" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0100644, "ab6c44a2e84492ad4b41bb6bac87353e9d02ac8b", 0, "changed-in-master.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "11deab00b2d3a6f5a3073988ac050c2d7b6655e2", 0, "changed-in-master.txt" }, GIT_DELTA_MODIFIED },
{ { 0100644, "ab6c44a2e84492ad4b41bb6bac87353e9d02ac8b", 0, "changed-in-master.txt" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0100644, "d427e0b2e138501a3d15cc376077a3631e15bd46", 0, "conflicting.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 0, "conflicting.txt" }, GIT_DELTA_MODIFIED },
{ { 0100644, "d427e0b2e138501a3d15cc376077a3631e15bd46", 0, "conflicting.txt" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0100644, "dfe3f22baa1f6fce5447901c3086bae368de6bdd", 0, "removed-in-branch.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "dfe3f22baa1f6fce5447901c3086bae368de6bdd", 0, "removed-in-branch.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "dfe3f22baa1f6fce5447901c3086bae368de6bdd", 0, "renamed-in-branch.txt" }, GIT_DELTA_RENAMED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0100644, "5c3b68a71fc4fa5d362fd3875e53137c6a5ab7a5", 0, "removed-in-master.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
{ { 0100644, "5c3b68a71fc4fa5d362fd3875e53137c6a5ab7a5", 0, "removed-in-master.txt" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "c8f06f2e3bb2964174677e91f0abead0e43c9e5d", 0, "renamed.txt" }, GIT_DELTA_ADDED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0100644, "c8f06f2e3bb2964174677e91f0abead0e43c9e5d", 0, "unchanged.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "c8f06f2e3bb2964174677e91f0abead0e43c9e5d", 0, "unchanged.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "c8f06f2e3bb2964174677e91f0abead0e43c9e5d", 0, "copied.txt" }, GIT_DELTA_RENAMED },
GIT_MERGE_DIFF_NONE,
},
};
test_find_differences(TREE_OID_ANCESTOR, TREE_OID_MASTER, TREE_OID_RENAMES1, treediff_conflict_data, 8);
}
void test_merge_trees_treediff__rename_conflicts(void)
{
struct merge_index_conflict_data treediff_conflict_data[] = {
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "f0ce2b8e4986084d9b308fb72709e414c23eb5e6", 0, "0b-duplicated-in-ours.txt" }, GIT_DELTA_ADDED },
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0100644, "f0ce2b8e4986084d9b308fb72709e414c23eb5e6", 0, "0b-rewritten-in-ours.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "e376fbdd06ebf021c92724da9f26f44212734e3e", 0, "0b-rewritten-in-ours.txt" }, GIT_DELTA_MODIFIED },
{ { 0100644, "b2d399ae15224e1d58066e3c8df70ce37de7a656", 0, "0b-rewritten-in-ours.txt" }, GIT_DELTA_MODIFIED },
GIT_MERGE_DIFF_BOTH_MODIFIED,
},
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "2f56120107d680129a5d9791b521cb1e73a2ed31", 0, "0c-duplicated-in-theirs.txt" }, GIT_DELTA_ADDED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0100644, "2f56120107d680129a5d9791b521cb1e73a2ed31", 0, "0c-rewritten-in-theirs.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "efc9121fdedaf08ba180b53ebfbcf71bd488ed09", 0, "0c-rewritten-in-theirs.txt" }, GIT_DELTA_MODIFIED },
{ { 0100644, "712ebba6669ea847d9829e4f1059d6c830c8b531", 0, "0c-rewritten-in-theirs.txt" }, GIT_DELTA_MODIFIED },
GIT_MERGE_DIFF_BOTH_MODIFIED,
},
{
{ { 0100644, "c3d02eeef75183df7584d8d13ac03053910c1301", 0, "1a-renamed-in-ours-edited-in-theirs.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "c3d02eeef75183df7584d8d13ac03053910c1301", 0, "1a-newname-in-ours-edited-in-theirs.txt" }, GIT_DELTA_RENAMED },
{ { 0100644, "0d872f8e871a30208305978ecbf9e66d864f1638", 0, "1a-renamed-in-ours-edited-in-theirs.txt" }, GIT_DELTA_MODIFIED },
GIT_MERGE_DIFF_RENAMED_MODIFIED,
},
{
{ { 0100644, "d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb", 0, "1a-renamed-in-ours.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb", 0, "1a-newname-in-ours.txt" }, GIT_DELTA_RENAMED },
{ { 0100644, "d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb", 0, "1a-renamed-in-ours.txt" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0100644, "241a1005cd9b980732741b74385b891142bcba28", 0, "1b-renamed-in-theirs-edited-in-ours.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "ed9523e62e453e50dd9be1606af19399b96e397a", 0, "1b-renamed-in-theirs-edited-in-ours.txt" }, GIT_DELTA_MODIFIED },
{ { 0100644, "241a1005cd9b980732741b74385b891142bcba28", 0, "1b-newname-in-theirs-edited-in-ours.txt" }, GIT_DELTA_RENAMED },
GIT_MERGE_DIFF_RENAMED_MODIFIED,
},
{
{ { 0100644, "2b5f1f181ee3b58ea751f5dd5d8f9b445520a136", 0, "1b-renamed-in-theirs.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "2b5f1f181ee3b58ea751f5dd5d8f9b445520a136", 0, "1b-renamed-in-theirs.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "2b5f1f181ee3b58ea751f5dd5d8f9b445520a136", 0, "1b-newname-in-theirs.txt" }, GIT_DELTA_RENAMED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0100644, "178940b450f238a56c0d75b7955cb57b38191982", 0, "2-renamed-in-both.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "178940b450f238a56c0d75b7955cb57b38191982", 0, "2-newname-in-both.txt" }, GIT_DELTA_RENAMED },
{ { 0100644, "178940b450f238a56c0d75b7955cb57b38191982", 0, "2-newname-in-both.txt" }, GIT_DELTA_RENAMED },
GIT_MERGE_DIFF_BOTH_RENAMED,
},
{
{ { 0100644, "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9", 0, "3a-renamed-in-ours-deleted-in-theirs.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9", 0, "3a-newname-in-ours-deleted-in-theirs.txt" }, GIT_DELTA_RENAMED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
GIT_MERGE_DIFF_RENAMED_DELETED,
},
{
{ { 0100644, "36219b49367146cb2e6a1555b5a9ebd4d0328495", 0, "3b-renamed-in-theirs-deleted-in-ours.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
{ { 0100644, "36219b49367146cb2e6a1555b5a9ebd4d0328495", 0, "3b-newname-in-theirs-deleted-in-ours.txt" }, GIT_DELTA_RENAMED },
GIT_MERGE_DIFF_RENAMED_DELETED,
},
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "8b5b53cb2aa9ceb1139f5312fcfa3cc3c5a47c9a", 0, "4a-newname-in-ours-added-in-theirs.txt" }, GIT_DELTA_ADDED },
GIT_MERGE_DIFF_RENAMED_ADDED,
},
{
{ { 0100644, "227792b52aaa0b238bea00ec7e509b02623f168c", 0, "4a-renamed-in-ours-added-in-theirs.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "227792b52aaa0b238bea00ec7e509b02623f168c", 0, "4a-newname-in-ours-added-in-theirs.txt" }, GIT_DELTA_RENAMED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
GIT_MERGE_DIFF_RENAMED_ADDED,
},
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "de872ee3618b894992e9d1e18ba2ebe256a112f9", 0, "4b-newname-in-theirs-added-in-ours.txt" }, GIT_DELTA_ADDED },
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_RENAMED_ADDED,
},
{
{ { 0100644, "98d52d07c0b0bbf2b46548f6aa521295c2cb55db", 0, "4b-renamed-in-theirs-added-in-ours.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
{ { 0100644, "98d52d07c0b0bbf2b46548f6aa521295c2cb55db", 0, "4b-newname-in-theirs-added-in-ours.txt" }, GIT_DELTA_RENAMED },
GIT_MERGE_DIFF_RENAMED_ADDED,
},
{
{ { 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 0, "5-both-renamed-1-to-2.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 0, "5-both-renamed-1-to-2-ours.txt" }, GIT_DELTA_RENAMED },
{ { 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 0, "5-both-renamed-1-to-2-theirs.txt" }, GIT_DELTA_RENAMED },
GIT_MERGE_DIFF_BOTH_RENAMED_1_TO_2,
},
{
{ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 0, "6-both-renamed-side-1.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 0, "6-both-renamed.txt" }, GIT_DELTA_RENAMED },
{ { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 0, "6-both-renamed-side-1.txt" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_BOTH_RENAMED_2_TO_1,
},
{
{ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 0, "6-both-renamed-side-2.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 0, "6-both-renamed-side-2.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 0, "6-both-renamed.txt" }, GIT_DELTA_RENAMED },
GIT_MERGE_DIFF_BOTH_RENAMED_2_TO_1,
},
};
test_find_differences(TREE_OID_RENAME_CONFLICT_ANCESTOR,
TREE_OID_RENAME_CONFLICT_OURS, TREE_OID_RENAME_CONFLICT_THEIRS, treediff_conflict_data, 18);
}
void test_merge_trees_treediff__best_renames(void)
{
struct merge_index_conflict_data treediff_conflict_data[] = {
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "233c0919c998ed110a4b6ff36f353aec8b713487", 0, "added-in-master.txt" }, GIT_DELTA_ADDED },
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0100644, "6212c31dab5e482247d7977e4f0dd3601decf13b", 0, "automergeable.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", 0, "automergeable.txt" }, GIT_DELTA_MODIFIED },
{ { 0100644, "45299c1ca5e07bba1fd90843056fb559f96b1f5a", 0, "renamed-90.txt" }, GIT_DELTA_RENAMED },
GIT_MERGE_DIFF_RENAMED_MODIFIED,
},
{
{ { 0100644, "ab6c44a2e84492ad4b41bb6bac87353e9d02ac8b", 0, "changed-in-master.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "11deab00b2d3a6f5a3073988ac050c2d7b6655e2", 0, "changed-in-master.txt" }, GIT_DELTA_MODIFIED },
{ { 0100644, "ab6c44a2e84492ad4b41bb6bac87353e9d02ac8b", 0, "changed-in-master.txt" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0100644, "d427e0b2e138501a3d15cc376077a3631e15bd46", 0, "conflicting.txt" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 0, "conflicting.txt" }, GIT_DELTA_MODIFIED },
{ { 0100644, "d427e0b2e138501a3d15cc376077a3631e15bd46", 0, "conflicting.txt" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0100644, "5c3b68a71fc4fa5d362fd3875e53137c6a5ab7a5", 0, "removed-in-master.txt" },GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_DELETED },
{ { 0100644, "5c3b68a71fc4fa5d362fd3875e53137c6a5ab7a5", 0, "removed-in-master.txt" }, GIT_DELTA_UNMODIFIED },
GIT_MERGE_DIFF_MODIFIED_DELETED,
},
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "5843febcb23480df0b5edb22a21c59c772bb8e29", 0, "renamed-50.txt" }, GIT_DELTA_ADDED },
GIT_MERGE_DIFF_NONE,
},
{
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0, "", 0, "" }, GIT_DELTA_UNMODIFIED },
{ { 0100644, "a77a56a49f8f3ae242e02717f18ebbc60c5cc543", 0, "renamed-75.txt" }, GIT_DELTA_ADDED },
GIT_MERGE_DIFF_NONE,
},
};
test_find_differences(TREE_OID_ANCESTOR, TREE_OID_MASTER, TREE_OID_RENAMES2, treediff_conflict_data, 7);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/trees/modeconflict.c
|
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "futils.h"
static git_repository *repo;
#define TEST_REPO_PATH "merge-resolve"
#define DF_SIDE1_BRANCH "df_side1"
#define DF_SIDE2_BRANCH "df_side2"
/* Fixture setup and teardown */
void test_merge_trees_modeconflict__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
}
void test_merge_trees_modeconflict__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_merge_trees_modeconflict__df_conflict(void)
{
git_index *index;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "49130a28ef567af9a6a6104c38773fedfa5f9742", 2, "dir-10" },
{ 0100644, "6c06dcd163587c2cc18be44857e0b71116382aeb", 3, "dir-10" },
{ 0100644, "43aafd43bea779ec74317dc361f45ae3f532a505", 0, "dir-6" },
{ 0100644, "a031a28ae70e33a641ce4b8a8f6317f1ab79dee4", 3, "dir-7" },
{ 0100644, "5012fd565b1393bdfda1805d4ec38ce6619e1fd1", 1, "dir-7/file.txt" },
{ 0100644, "a5563304ddf6caba25cb50323a2ea6f7dbfcadca", 2, "dir-7/file.txt" },
{ 0100644, "e9ad6ec3e38364a3d07feda7c4197d4d845c53b5", 0, "dir-8" },
{ 0100644, "3ef4d30382ca33fdeba9fda895a99e0891ba37aa", 2, "dir-9" },
{ 0100644, "fc4c636d6515e9e261f9260dbcf3cc6eca97ea08", 1, "dir-9/file.txt" },
{ 0100644, "76ab0e2868197ec158ddd6c78d8a0d2fd73d38f9", 3, "dir-9/file.txt" },
{ 0100644, "5c2411f8075f48a6b2fdb85ebc0d371747c4df15", 0, "file-1/new" },
{ 0100644, "a39a620dae5bc8b4e771cd4d251b7d080401a21e", 1, "file-2" },
{ 0100644, "d963979c237d08b6ba39062ee7bf64c7d34a27f8", 2, "file-2" },
{ 0100644, "5c341ead2ba6f2af98ce5ec3fe84f6b6d2899c0d", 0, "file-2/new" },
{ 0100644, "9efe7723802d4305142eee177e018fee1572c4f4", 0, "file-3/new" },
{ 0100644, "bacac9b3493509aa15e1730e1545fc0919d1dae0", 1, "file-4" },
{ 0100644, "7663fce0130db092936b137cabd693ec234eb060", 3, "file-4" },
{ 0100644, "e49f917b448d1340b31d76e54ba388268fd4c922", 0, "file-4/new" },
{ 0100644, "cab2cf23998b40f1af2d9d9a756dc9e285a8df4b", 2, "file-5/new" },
{ 0100644, "f5504f36e6f4eb797a56fc5bac6c6c7f32969bf2", 3, "file-5/new" },
};
cl_git_pass(merge_trees_from_branches(&index, repo, DF_SIDE1_BRANCH, DF_SIDE2_BRANCH, NULL));
cl_assert(merge_test_index(index, merge_index_entries, 20));
git_index_free(index);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/trees/recursive.c
|
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "merge.h"
#include "../merge_helpers.h"
static git_repository *repo;
#define TEST_REPO_PATH "merge-recursive"
void test_merge_trees_recursive__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
}
void test_merge_trees_recursive__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_merge_trees_recursive__one_base_commit(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "dea7215f259b2cced87d1bda6c72f8b4ce37a2ff", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "94d2c01087f48213bd157222d54edfefd77c9bba", 0, "veal.txt" },
};
cl_git_pass(merge_commits_from_branches(&index, repo, "branchA-1", "branchA-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 6));
git_index_free(index);
}
void test_merge_trees_recursive__one_base_commit_norecursive(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "dea7215f259b2cced87d1bda6c72f8b4ce37a2ff", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "94d2c01087f48213bd157222d54edfefd77c9bba", 0, "veal.txt" },
};
opts.flags |= GIT_MERGE_NO_RECURSIVE;
cl_git_pass(merge_commits_from_branches(&index, repo, "branchA-1", "branchA-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 6));
git_index_free(index);
}
void test_merge_trees_recursive__two_base_commits(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "666ffdfcf1eaa5641fa31064bf2607327e843c09", 0, "veal.txt" },
};
cl_git_pass(merge_commits_from_branches(&index, repo, "branchB-1", "branchB-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 6));
git_index_free(index);
}
void test_merge_trees_recursive__two_base_commits_norecursive(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "cb49ad76147f5f9439cbd6133708b76142660660", 1, "veal.txt" },
{ 0100644, "b2a81ead9e722af0099fccfb478cea88eea749a2", 2, "veal.txt" },
{ 0100644, "4e21d2d63357bde5027d1625f5ec6b430cdeb143", 3, "veal.txt" },
};
opts.flags |= GIT_MERGE_NO_RECURSIVE;
cl_git_pass(merge_commits_from_branches(&index, repo, "branchB-1", "branchB-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 8));
git_index_free(index);
}
void test_merge_trees_recursive__two_levels_of_multiple_bases(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "15faa0c9991f2d65686e844651faa2ff9827887b", 0, "veal.txt" },
};
cl_git_pass(merge_commits_from_branches(&index, repo, "branchC-1", "branchC-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 6));
git_index_free(index);
}
void test_merge_trees_recursive__two_levels_of_multiple_bases_norecursive(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "b2a81ead9e722af0099fccfb478cea88eea749a2", 1, "veal.txt" },
{ 0100644, "898d12687fb35be271c27c795a6b32c8b51da79e", 2, "veal.txt" },
{ 0100644, "68a2e1ee61a23a4728fe6b35580fbbbf729df370", 3, "veal.txt" },
};
opts.flags |= GIT_MERGE_NO_RECURSIVE;
cl_git_pass(merge_commits_from_branches(&index, repo, "branchC-1", "branchC-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 8));
git_index_free(index);
}
void test_merge_trees_recursive__three_levels_of_multiple_bases(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "d55e5dc038c52f1a36548625bcb666cbc06db9e6", 0, "veal.txt" },
};
cl_git_pass(merge_commits_from_branches(&index, repo, "branchD-2", "branchD-1", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 6));
git_index_free(index);
}
void test_merge_trees_recursive__three_levels_of_multiple_bases_norecursive(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "898d12687fb35be271c27c795a6b32c8b51da79e", 1, "veal.txt" },
{ 0100644, "f1b44c04989a3a1c14b036cfadfa328d53a7bc5e", 2, "veal.txt" },
{ 0100644, "5e8747f5200fac0f945a07daf6163ca9cb1a8da9", 3, "veal.txt" },
};
opts.flags |= GIT_MERGE_NO_RECURSIVE;
cl_git_pass(merge_commits_from_branches(&index, repo, "branchD-2", "branchD-1", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 8));
git_index_free(index);
}
void test_merge_trees_recursive__three_base_commits(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4f7269b07c76d02755d75ccaf05c0b4c36cdc6c", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "a7b066537e6be7109abfe4ff97b675d4e077da20", 0, "veal.txt" },
};
cl_git_pass(merge_commits_from_branches(&index, repo, "branchE-1", "branchE-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 6));
git_index_free(index);
}
void test_merge_trees_recursive__three_base_commits_norecursive(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "9e12bce04446d097ae1782967a5888c2e2a0d35b", 1, "gravy.txt" },
{ 0100644, "d8dd349b78f19a4ebe3357bacb8138f00bf5ed41", 2, "gravy.txt" },
{ 0100644, "e50fbbd701458757bdfe9815f58ed717c588d1b5", 3, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "a7b066537e6be7109abfe4ff97b675d4e077da20", 0, "veal.txt" },
};
opts.flags |= GIT_MERGE_NO_RECURSIVE;
cl_git_pass(merge_commits_from_branches(&index, repo, "branchE-1", "branchE-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 8));
git_index_free(index);
}
void test_merge_trees_recursive__conflict(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "fa567f568ed72157c0c617438d077695b99d9aac", 1, "veal.txt" },
{ 0100644, "21950d5e4e4d1a871b4dfcf72ecb6b9c162c434e", 2, "veal.txt" },
{ 0100644, "3855170cef875708da06ab9ad7fc6a73b531cda1", 3, "veal.txt" },
};
cl_git_pass(merge_commits_from_branches(&index, repo, "branchF-1", "branchF-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 8));
git_index_free(index);
}
/*
* Branch G-1 and G-2 have three common ancestors (815b5a1, ad2ace9, 483065d).
* The merge-base of the first two has two common ancestors (723181f, a34e5a1)
* which themselves have two common ancestors (8f35f30, 3a3f5a6), which
* finally has a common ancestor of 7c7bf85. This virtual merge base will
* be computed and merged with 483065d which also has a common ancestor of
* 7c7bf85.
*/
void test_merge_trees_recursive__oh_so_many_levels_of_recursion(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "7c7e08f9559d9e1551b91e1cf68f1d0066109add", 0, "oyster.txt" },
{ 0100644, "898d12687fb35be271c27c795a6b32c8b51da79e", 0, "veal.txt" },
};
cl_git_pass(merge_commits_from_branches(&index, repo, "branchG-1", "branchG-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 6));
git_index_free(index);
}
/* Branch H-1 and H-2 have two common ancestors (aa9e263, 6ef31d3). The two
* ancestors themselves conflict.
*/
void test_merge_trees_recursive__conflicting_merge_base(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "cfc01b0976122eae42a82064440bbf534eddd7a0", 1, "veal.txt" },
{ 0100644, "d604c75019c282144bdbbf3fd3462ba74b240efc", 2, "veal.txt" },
{ 0100644, "37a5054a9f9b4628e3924c5cb8f2147c6e2a3efc", 3, "veal.txt" },
};
cl_git_pass(merge_commits_from_branches(&index, repo, "branchH-1", "branchH-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 8));
git_index_free(index);
}
/* Branch H-1 and H-2 have two common ancestors (aa9e263, 6ef31d3). The two
* ancestors themselves conflict. The generated common ancestor file will
* have diff3 style conflicts inside it.
*/
void test_merge_trees_recursive__conflicting_merge_base_with_diff3(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "0b01d2f70a1c6b9ab60c382f3f9cdc8173da6736", 1, "veal.txt" },
{ 0100644, "37a5054a9f9b4628e3924c5cb8f2147c6e2a3efc", 2, "veal.txt" },
{ 0100644, "d604c75019c282144bdbbf3fd3462ba74b240efc", 3, "veal.txt" },
};
opts.file_flags |= GIT_MERGE_FILE_STYLE_DIFF3;
cl_git_pass(merge_commits_from_branches(&index, repo, "branchH-2", "branchH-1", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 8));
git_index_free(index);
}
/* Branch I-1 and I-2 have two common ancestors (aa9e263, 6ef31d3). The two
* ancestors themselves conflict, but when each was merged, the conflicts were
* resolved identically, thus merging I-1 into I-2 does not conflict.
*/
void test_merge_trees_recursive__conflicting_merge_base_since_resolved(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "a02d4fd126e0cc8fb46ee48cf38bad36d44f2dbc", 0, "veal.txt" },
};
cl_git_pass(merge_commits_from_branches(&index, repo, "branchI-1", "branchI-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 6));
git_index_free(index);
}
/* There are multiple levels of criss-cross merges, and multiple recursive
* merges would create a common ancestor that allows the merge to complete
* successfully. Test that we can build a single virtual base, then stop,
* which will produce a conflicting merge.
*/
void test_merge_trees_recursive__recursionlimit(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "53217e8ac3f52bccf7603b8fff0ed0f4817f9bb7", 1, "veal.txt" },
{ 0100644, "898d12687fb35be271c27c795a6b32c8b51da79e", 2, "veal.txt" },
{ 0100644, "68a2e1ee61a23a4728fe6b35580fbbbf729df370", 3, "veal.txt" },
};
opts.recursion_limit = 1;
cl_git_pass(merge_commits_from_branches(&index, repo, "branchC-1", "branchC-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 8));
git_index_free(index);
}
/* There are multiple levels of criss-cross merges. This ensures
* that the virtual merge base parents are compared in the same
* order as git. If the base parents are created in the order as
* git does, then the file `targetfile.txt` is automerged. If not,
* `targetfile.txt` will be in conflict due to the virtual merge
* base.
*/
void test_merge_trees_recursive__merge_base_for_virtual_commit(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "1bde1883de4977ea3e664b315da951d1f614c3b1", 0, "targetfile.txt" },
{ 0100644, "b7de2b52ba055688061355fad1599a5d214ce8f8", 1, "version.txt" },
{ 0100644, "358efd6f589384fa8baf92234db9c7899a53916e", 2, "version.txt" },
{ 0100644, "a664873b1c0b9a1ed300f8644dde536fdaa3a34f", 3, "version.txt" },
};
cl_git_pass(merge_commits_from_branches(&index, repo, "branchJ-1", "branchJ-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 4));
git_index_free(index);
}
/* This test is the same as above, but the graph is constructed such
* that the 1st-recursion merge bases of the two heads are
* in a different order.
*/
void test_merge_trees_recursive__merge_base_for_virtual_commit_2(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "4a06b258fed8a4d15967ec4253ae7366b70f727d", 0, "targetfile.txt" },
{ 0100644, "b6bd0f9952f396e757d3f91e08c59a7e91707201", 1, "version.txt" },
{ 0100644, "f0856993e005c0d8ed2dc7cdc222cc1d89fb3c77", 2, "version.txt" },
{ 0100644, "2cba583804a4a6fad1baf97c959be447238d1489", 3, "version.txt" },
};
cl_git_pass(merge_commits_from_branches(&index, repo, "branchK-1", "branchK-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 4));
git_index_free(index);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/trees/whitespace.c
|
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "futils.h"
static git_repository *repo;
#define TEST_REPO_PATH "merge-whitespace"
#define BRANCH_A_EOL "branch_a_eol"
#define BRANCH_B_EOL "branch_b_eol"
#define BRANCH_A_CHANGE "branch_a_change"
#define BRANCH_B_CHANGE "branch_b_change"
/* Fixture setup and teardown */
void test_merge_trees_whitespace__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
}
void test_merge_trees_whitespace__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_merge_trees_whitespace__conflict(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "4026a6c83f39c56881c9ac62e7582db9e3d33a4f", 1, "test.txt" },
{ 0100644, "c3b1fb31424c98072542cc8e42b48c92e52f494a", 2, "test.txt" },
{ 0100644, "262f67de0de2e535a59ae1bc3c739601e98c354d", 3, "test.txt" },
};
cl_git_pass(merge_trees_from_branches(&index, repo, BRANCH_A_EOL, BRANCH_B_EOL, &opts));
cl_assert(merge_test_index(index, merge_index_entries, 3));
git_index_free(index);
}
void test_merge_trees_whitespace__eol(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ee3c2aac8e03224c323b58ecb1f9eef616745467", 0, "test.txt" },
};
opts.file_flags |= GIT_MERGE_FILE_IGNORE_WHITESPACE_EOL;
cl_git_pass(merge_trees_from_branches(&index, repo, BRANCH_A_EOL, BRANCH_B_EOL, &opts));
cl_assert(merge_test_index(index, merge_index_entries, 1));
git_index_free(index);
}
void test_merge_trees_whitespace__change(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "a827eab4fd66ab37a6ebcfaa7b7e341abfd55947", 0, "test.txt" },
};
opts.file_flags |= GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE;
cl_git_pass(merge_trees_from_branches(&index, repo, BRANCH_A_CHANGE, BRANCH_B_CHANGE, &opts));
cl_assert(merge_test_index(index, merge_index_entries, 1));
git_index_free(index);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/trees/renames.c
|
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "buffer.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "futils.h"
static git_repository *repo;
#define TEST_REPO_PATH "merge-resolve"
#define BRANCH_RENAME_OURS "rename_conflict_ours"
#define BRANCH_RENAME_THEIRS "rename_conflict_theirs"
/* Fixture setup and teardown */
void test_merge_trees_renames__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
}
void test_merge_trees_renames__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_merge_trees_renames__index(void)
{
git_index *index;
git_merge_options *opts = NULL;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e", 0, "0a-no-change.txt" },
{ 0100644, "f0ce2b8e4986084d9b308fb72709e414c23eb5e6", 0, "0b-duplicated-in-ours.txt" },
{ 0100644, "f0ce2b8e4986084d9b308fb72709e414c23eb5e6", 1, "0b-rewritten-in-ours.txt" },
{ 0100644, "e376fbdd06ebf021c92724da9f26f44212734e3e", 2, "0b-rewritten-in-ours.txt" },
{ 0100644, "b2d399ae15224e1d58066e3c8df70ce37de7a656", 3, "0b-rewritten-in-ours.txt" },
{ 0100644, "2f56120107d680129a5d9791b521cb1e73a2ed31", 0, "0c-duplicated-in-theirs.txt" },
{ 0100644, "2f56120107d680129a5d9791b521cb1e73a2ed31", 1, "0c-rewritten-in-theirs.txt" },
{ 0100644, "efc9121fdedaf08ba180b53ebfbcf71bd488ed09", 2, "0c-rewritten-in-theirs.txt" },
{ 0100644, "712ebba6669ea847d9829e4f1059d6c830c8b531", 3, "0c-rewritten-in-theirs.txt" },
{ 0100644, "0d872f8e871a30208305978ecbf9e66d864f1638", 0, "1a-newname-in-ours-edited-in-theirs.txt" },
{ 0100644, "d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb", 0, "1a-newname-in-ours.txt" },
{ 0100644, "ed9523e62e453e50dd9be1606af19399b96e397a", 0, "1b-newname-in-theirs-edited-in-ours.txt" },
{ 0100644, "2b5f1f181ee3b58ea751f5dd5d8f9b445520a136", 0, "1b-newname-in-theirs.txt" },
{ 0100644, "178940b450f238a56c0d75b7955cb57b38191982", 0, "2-newname-in-both.txt" },
{ 0100644, "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9", 2, "3a-newname-in-ours-deleted-in-theirs.txt" },
{ 0100644, "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9", 1, "3a-renamed-in-ours-deleted-in-theirs.txt" },
{ 0100644, "36219b49367146cb2e6a1555b5a9ebd4d0328495", 3, "3b-newname-in-theirs-deleted-in-ours.txt" },
{ 0100644, "36219b49367146cb2e6a1555b5a9ebd4d0328495", 1, "3b-renamed-in-theirs-deleted-in-ours.txt" },
{ 0100644, "227792b52aaa0b238bea00ec7e509b02623f168c", 2, "4a-newname-in-ours-added-in-theirs.txt" },
{ 0100644, "8b5b53cb2aa9ceb1139f5312fcfa3cc3c5a47c9a", 3, "4a-newname-in-ours-added-in-theirs.txt" },
{ 0100644, "227792b52aaa0b238bea00ec7e509b02623f168c", 1, "4a-renamed-in-ours-added-in-theirs.txt" },
{ 0100644, "de872ee3618b894992e9d1e18ba2ebe256a112f9", 2, "4b-newname-in-theirs-added-in-ours.txt" },
{ 0100644, "98d52d07c0b0bbf2b46548f6aa521295c2cb55db", 3, "4b-newname-in-theirs-added-in-ours.txt" },
{ 0100644, "98d52d07c0b0bbf2b46548f6aa521295c2cb55db", 1, "4b-renamed-in-theirs-added-in-ours.txt" },
{ 0100644, "d3719a5ae8e4d92276b5313ce976f6ee5af2b436", 2, "5a-newname-in-ours-added-in-theirs.txt" },
{ 0100644, "98ba4205fcf31f5dd93c916d35fe3f3b3d0e6714", 3, "5a-newname-in-ours-added-in-theirs.txt" },
{ 0100644, "d3719a5ae8e4d92276b5313ce976f6ee5af2b436", 1, "5a-renamed-in-ours-added-in-theirs.txt" },
{ 0100644, "d3719a5ae8e4d92276b5313ce976f6ee5af2b436", 3, "5a-renamed-in-ours-added-in-theirs.txt" },
{ 0100644, "385c8a0f26ddf79e9041e15e17dc352ed2c4cced", 2, "5b-newname-in-theirs-added-in-ours.txt" },
{ 0100644, "63247125386de9ec90a27ad36169307bf8a11a38", 3, "5b-newname-in-theirs-added-in-ours.txt" },
{ 0100644, "63247125386de9ec90a27ad36169307bf8a11a38", 1, "5b-renamed-in-theirs-added-in-ours.txt" },
{ 0100644, "63247125386de9ec90a27ad36169307bf8a11a38", 2, "5b-renamed-in-theirs-added-in-ours.txt" },
{ 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 2, "6-both-renamed-1-to-2-ours.txt" },
{ 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 3, "6-both-renamed-1-to-2-theirs.txt" },
{ 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 1, "6-both-renamed-1-to-2.txt" },
{ 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 1, "7-both-renamed-side-1.txt" },
{ 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 3, "7-both-renamed-side-1.txt" },
{ 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 1, "7-both-renamed-side-2.txt" },
{ 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 2, "7-both-renamed-side-2.txt" },
{ 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 2, "7-both-renamed.txt" },
{ 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 3, "7-both-renamed.txt" },
};
struct merge_name_entry merge_name_entries[] = {
{
"3a-renamed-in-ours-deleted-in-theirs.txt",
"3a-newname-in-ours-deleted-in-theirs.txt",
""
},
{
"3b-renamed-in-theirs-deleted-in-ours.txt",
"",
"3b-newname-in-theirs-deleted-in-ours.txt",
},
{
"4a-renamed-in-ours-added-in-theirs.txt",
"4a-newname-in-ours-added-in-theirs.txt",
"",
},
{
"4b-renamed-in-theirs-added-in-ours.txt",
"",
"4b-newname-in-theirs-added-in-ours.txt",
},
{
"5a-renamed-in-ours-added-in-theirs.txt",
"5a-newname-in-ours-added-in-theirs.txt",
"5a-renamed-in-ours-added-in-theirs.txt",
},
{
"5b-renamed-in-theirs-added-in-ours.txt",
"5b-renamed-in-theirs-added-in-ours.txt",
"5b-newname-in-theirs-added-in-ours.txt",
},
{
"6-both-renamed-1-to-2.txt",
"6-both-renamed-1-to-2-ours.txt",
"6-both-renamed-1-to-2-theirs.txt",
},
{
"7-both-renamed-side-1.txt",
"7-both-renamed.txt",
"7-both-renamed-side-1.txt",
},
{
"7-both-renamed-side-2.txt",
"7-both-renamed-side-2.txt",
"7-both-renamed.txt",
},
};
struct merge_reuc_entry merge_reuc_entries[] = {
{ "1a-newname-in-ours-edited-in-theirs.txt",
0, 0100644, 0,
"",
"c3d02eeef75183df7584d8d13ac03053910c1301",
"" },
{ "1a-newname-in-ours.txt",
0, 0100644, 0,
"",
"d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb",
"" },
{ "1a-renamed-in-ours-edited-in-theirs.txt",
0100644, 0, 0100644,
"c3d02eeef75183df7584d8d13ac03053910c1301",
"",
"0d872f8e871a30208305978ecbf9e66d864f1638" },
{ "1a-renamed-in-ours.txt",
0100644, 0, 0100644,
"d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb",
"",
"d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb" },
{ "1b-newname-in-theirs-edited-in-ours.txt",
0, 0, 0100644,
"",
"",
"241a1005cd9b980732741b74385b891142bcba28" },
{ "1b-newname-in-theirs.txt",
0, 0, 0100644,
"",
"",
"2b5f1f181ee3b58ea751f5dd5d8f9b445520a136" },
{ "1b-renamed-in-theirs-edited-in-ours.txt",
0100644, 0100644, 0,
"241a1005cd9b980732741b74385b891142bcba28",
"ed9523e62e453e50dd9be1606af19399b96e397a",
"" },
{ "1b-renamed-in-theirs.txt",
0100644, 0100644, 0,
"2b5f1f181ee3b58ea751f5dd5d8f9b445520a136",
"2b5f1f181ee3b58ea751f5dd5d8f9b445520a136",
"" },
{ "2-newname-in-both.txt",
0, 0100644, 0100644,
"",
"178940b450f238a56c0d75b7955cb57b38191982",
"178940b450f238a56c0d75b7955cb57b38191982" },
{ "2-renamed-in-both.txt",
0100644, 0, 0,
"178940b450f238a56c0d75b7955cb57b38191982",
"",
"" },
};
cl_git_pass(merge_trees_from_branches(&index, repo,
BRANCH_RENAME_OURS, BRANCH_RENAME_THEIRS,
opts));
cl_assert(merge_test_index(index, merge_index_entries, 41));
cl_assert(merge_test_names(index, merge_name_entries, 9));
cl_assert(merge_test_reuc(index, merge_reuc_entries, 10));
git_index_free(index);
}
void test_merge_trees_renames__no_rename_index(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e", 0, "0a-no-change.txt" },
{ 0100644, "f0ce2b8e4986084d9b308fb72709e414c23eb5e6", 0, "0b-duplicated-in-ours.txt" },
{ 0100644, "f0ce2b8e4986084d9b308fb72709e414c23eb5e6", 1, "0b-rewritten-in-ours.txt" },
{ 0100644, "e376fbdd06ebf021c92724da9f26f44212734e3e", 2, "0b-rewritten-in-ours.txt" },
{ 0100644, "b2d399ae15224e1d58066e3c8df70ce37de7a656", 3, "0b-rewritten-in-ours.txt" },
{ 0100644, "2f56120107d680129a5d9791b521cb1e73a2ed31", 0, "0c-duplicated-in-theirs.txt" },
{ 0100644, "2f56120107d680129a5d9791b521cb1e73a2ed31", 1, "0c-rewritten-in-theirs.txt" },
{ 0100644, "efc9121fdedaf08ba180b53ebfbcf71bd488ed09", 2, "0c-rewritten-in-theirs.txt" },
{ 0100644, "712ebba6669ea847d9829e4f1059d6c830c8b531", 3, "0c-rewritten-in-theirs.txt" },
{ 0100644, "c3d02eeef75183df7584d8d13ac03053910c1301", 0, "1a-newname-in-ours-edited-in-theirs.txt" },
{ 0100644, "d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb", 0, "1a-newname-in-ours.txt" },
{ 0100644, "c3d02eeef75183df7584d8d13ac03053910c1301", 1, "1a-renamed-in-ours-edited-in-theirs.txt" },
{ 0100644, "0d872f8e871a30208305978ecbf9e66d864f1638", 3, "1a-renamed-in-ours-edited-in-theirs.txt" },
{ 0100644, "241a1005cd9b980732741b74385b891142bcba28", 0, "1b-newname-in-theirs-edited-in-ours.txt" },
{ 0100644, "2b5f1f181ee3b58ea751f5dd5d8f9b445520a136", 0, "1b-newname-in-theirs.txt" },
{ 0100644, "241a1005cd9b980732741b74385b891142bcba28", 1, "1b-renamed-in-theirs-edited-in-ours.txt" },
{ 0100644, "ed9523e62e453e50dd9be1606af19399b96e397a", 2, "1b-renamed-in-theirs-edited-in-ours.txt" },
{ 0100644, "178940b450f238a56c0d75b7955cb57b38191982", 0, "2-newname-in-both.txt" },
{ 0100644, "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9", 0, "3a-newname-in-ours-deleted-in-theirs.txt" },
{ 0100644, "36219b49367146cb2e6a1555b5a9ebd4d0328495", 0, "3b-newname-in-theirs-deleted-in-ours.txt" },
{ 0100644, "227792b52aaa0b238bea00ec7e509b02623f168c", 2, "4a-newname-in-ours-added-in-theirs.txt" },
{ 0100644, "8b5b53cb2aa9ceb1139f5312fcfa3cc3c5a47c9a", 3, "4a-newname-in-ours-added-in-theirs.txt" },
{ 0100644, "de872ee3618b894992e9d1e18ba2ebe256a112f9", 2, "4b-newname-in-theirs-added-in-ours.txt" },
{ 0100644, "98d52d07c0b0bbf2b46548f6aa521295c2cb55db", 3, "4b-newname-in-theirs-added-in-ours.txt" },
{ 0100644, "d3719a5ae8e4d92276b5313ce976f6ee5af2b436", 2, "5a-newname-in-ours-added-in-theirs.txt" },
{ 0100644, "98ba4205fcf31f5dd93c916d35fe3f3b3d0e6714", 3, "5a-newname-in-ours-added-in-theirs.txt" },
{ 0100644, "385c8a0f26ddf79e9041e15e17dc352ed2c4cced", 2, "5b-newname-in-theirs-added-in-ours.txt" },
{ 0100644, "63247125386de9ec90a27ad36169307bf8a11a38", 3, "5b-newname-in-theirs-added-in-ours.txt" },
{ 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 0, "6-both-renamed-1-to-2-ours.txt" },
{ 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450", 0, "6-both-renamed-1-to-2-theirs.txt" },
{ 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 2, "7-both-renamed.txt" },
{ 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 3, "7-both-renamed.txt" },
};
opts.flags &= ~GIT_MERGE_FIND_RENAMES;
cl_git_pass(merge_trees_from_branches(&index, repo,
BRANCH_RENAME_OURS, BRANCH_RENAME_THEIRS,
&opts));
cl_assert(merge_test_index(index, merge_index_entries, 32));
git_index_free(index);
}
void test_merge_trees_renames__submodules(void)
{
git_index *index;
git_merge_options *opts = NULL;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "cd3e8d4aa06bdc781f264171030bc28f2b370fee", 0, ".gitmodules" },
{ 0100644, "4dd1ef7569b18d92d93c0a35bb6b93049137b355", 1, "file.txt" },
{ 0100644, "a2d8d1824c68541cca94ffb90f79291eba495921", 2, "file.txt" },
{ 0100644, "63ec604d491161ddafdae4179843c26d54bd999a", 3, "file.txt" },
{ 0160000, "0000000000000000000000000000000000000001", 1, "submodule1" },
{ 0160000, "0000000000000000000000000000000000000002", 3, "submodule1" },
{ 0160000, "0000000000000000000000000000000000000003", 0, "submodule2" },
};
cl_git_pass(merge_trees_from_branches(&index, repo,
"submodule_rename1", "submodule_rename2",
opts));
cl_assert(merge_test_index(index, merge_index_entries, 7));
git_index_free(index);
}
void test_merge_trees_renames__cache_recomputation(void)
{
git_oid blob, binary, ancestor_oid, theirs_oid, ours_oid;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
git_buf path = GIT_BUF_INIT;
git_treebuilder *builder;
git_tree *ancestor_tree, *their_tree, *our_tree;
git_index *index;
size_t blob_size;
void *data;
size_t i;
cl_git_pass(git_oid_fromstr(&blob, "a2d8d1824c68541cca94ffb90f79291eba495921"));
/*
* Create a 50MB blob that consists of NUL bytes only. It is important
* that this blob is of a special format, most importantly it cannot
* contain more than four non-consecutive newlines or NUL bytes. This
* is because of git_hashsig's inner workings where all files with less
* than four "lines" are deemed to small.
*/
blob_size = 50 * 1024 * 1024;
cl_assert(data = git__calloc(blob_size, 1));
cl_git_pass(git_blob_create_from_buffer(&binary, repo, data, blob_size));
/*
* Create the common ancestor, which has 1000 dummy blobs and the binary
* blob. The dummy blobs serve as potential rename targets for the
* dummy blob.
*/
cl_git_pass(git_treebuilder_new(&builder, repo, NULL));
for (i = 0; i < 1000; i++) {
cl_git_pass(git_buf_printf(&path, "%"PRIuZ".txt", i));
cl_git_pass(git_treebuilder_insert(NULL, builder, path.ptr, &blob, GIT_FILEMODE_BLOB));
git_buf_clear(&path);
}
cl_git_pass(git_treebuilder_insert(NULL, builder, "original.bin", &binary, GIT_FILEMODE_BLOB));
cl_git_pass(git_treebuilder_write(&ancestor_oid, builder));
/* We now the binary blob in our tree. */
cl_git_pass(git_treebuilder_remove(builder, "original.bin"));
cl_git_pass(git_treebuilder_insert(NULL, builder, "renamed.bin", &binary, GIT_FILEMODE_BLOB));
cl_git_pass(git_treebuilder_write(&ours_oid, builder));
git_treebuilder_free(builder);
/* And move everything into a subdirectory in their tree. */
cl_git_pass(git_treebuilder_new(&builder, repo, NULL));
cl_git_pass(git_treebuilder_insert(NULL, builder, "subdir", &ancestor_oid, GIT_FILEMODE_TREE));
cl_git_pass(git_treebuilder_write(&theirs_oid, builder));
/*
* Now merge ancestor, ours and theirs. As `git_hashsig` refuses to
* create a hash signature for the 50MB binary file, we historically
* didn't cache the hashsig computation for it. As a result, we now
* started looking up the 50MB blob and scanning it at least 1000
* times, which takes a long time.
*
* The number of 1000 blobs is chosen in such a way that it's
* noticeable when the bug creeps in again, as it takes around 12
* minutes on my machine to compute the following merge.
*/
opts.target_limit = 5000;
cl_git_pass(git_tree_lookup(&ancestor_tree, repo, &ancestor_oid));
cl_git_pass(git_tree_lookup(&their_tree, repo, &theirs_oid));
cl_git_pass(git_tree_lookup(&our_tree, repo, &ours_oid));
cl_git_pass(git_merge_trees(&index, repo, ancestor_tree, our_tree, their_tree, &opts));
git_treebuilder_free(builder);
git_buf_dispose(&path);
git_index_free(index);
git_tree_free(ancestor_tree);
git_tree_free(their_tree);
git_tree_free(our_tree);
git__free(data);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/trees/commits.c
|
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "../conflict_data.h"
static git_repository *repo;
#define TEST_REPO_PATH "merge-resolve"
void test_merge_trees_commits__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
}
void test_merge_trees_commits__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_merge_trees_commits__automerge(void)
{
git_index *index;
const git_index_entry *entry;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
git_blob *blob;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "233c0919c998ed110a4b6ff36f353aec8b713487", 0, "added-in-master.txt" },
{ 0100644, "f2e1550a0c9e53d5811175864a29536642ae3821", 0, "automergeable.txt" },
{ 0100644, "4eb04c9e79e88f6640d01ff5b25ca2a60764f216", 0, "changed-in-branch.txt" },
{ 0100644, "11deab00b2d3a6f5a3073988ac050c2d7b6655e2", 0, "changed-in-master.txt" },
{ 0100644, "d427e0b2e138501a3d15cc376077a3631e15bd46", 1, "conflicting.txt" },
{ 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 2, "conflicting.txt" },
{ 0100644, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", 3, "conflicting.txt" },
{ 0100644, "c8f06f2e3bb2964174677e91f0abead0e43c9e5d", 0, "unchanged.txt" },
};
struct merge_reuc_entry merge_reuc_entries[] = {
{ "automergeable.txt", 0100644, 0100644, 0100644, \
"6212c31dab5e482247d7977e4f0dd3601decf13b", \
"ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", \
"058541fc37114bfc1dddf6bd6bffc7fae5c2e6fe" },
{ "removed-in-branch.txt", 0100644, 0100644, 0, \
"dfe3f22baa1f6fce5447901c3086bae368de6bdd", \
"dfe3f22baa1f6fce5447901c3086bae368de6bdd", \
"" },
{ "removed-in-master.txt", 0100644, 0, 0100644, \
"5c3b68a71fc4fa5d362fd3875e53137c6a5ab7a5", \
"", \
"5c3b68a71fc4fa5d362fd3875e53137c6a5ab7a5" },
};
cl_git_pass(merge_commits_from_branches(&index, repo, "master", "branch", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 8));
cl_assert(merge_test_reuc(index, merge_reuc_entries, 3));
cl_assert((entry = git_index_get_bypath(index, "automergeable.txt", 0)) != NULL);
cl_assert(entry->file_size == strlen(AUTOMERGEABLE_MERGED_FILE));
cl_git_pass(git_object_lookup((git_object **)&blob, repo, &entry->id, GIT_OBJECT_BLOB));
cl_assert(memcmp(git_blob_rawcontent(blob), AUTOMERGEABLE_MERGED_FILE, (size_t)entry->file_size) == 0);
git_index_free(index);
git_blob_free(blob);
}
void test_merge_trees_commits__no_ancestor(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "233c0919c998ed110a4b6ff36f353aec8b713487", 0, "added-in-master.txt" },
{ 0100644, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", 2, "automergeable.txt" },
{ 0100644, "d07ec190c306ec690bac349e87d01c4358e49bb2", 3, "automergeable.txt" },
{ 0100644, "ab6c44a2e84492ad4b41bb6bac87353e9d02ac8b", 0, "changed-in-branch.txt" },
{ 0100644, "11deab00b2d3a6f5a3073988ac050c2d7b6655e2", 0, "changed-in-master.txt" },
{ 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 2, "conflicting.txt" },
{ 0100644, "4b253da36a0ae8bfce63aeabd8c5b58429925594", 3, "conflicting.txt" },
{ 0100644, "ef58fdd8086c243bdc81f99e379acacfd21d32d6", 0, "new-in-unrelated1.txt" },
{ 0100644, "948ba6e701c1edab0c2d394fb7c5538334129793", 0, "new-in-unrelated2.txt" },
{ 0100644, "dfe3f22baa1f6fce5447901c3086bae368de6bdd", 0, "removed-in-branch.txt" },
{ 0100644, "c8f06f2e3bb2964174677e91f0abead0e43c9e5d", 0, "unchanged.txt" },
};
cl_git_pass(merge_commits_from_branches(&index, repo, "master", "unrelated", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 11));
git_index_free(index);
}
void test_merge_trees_commits__df_conflict(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "49130a28ef567af9a6a6104c38773fedfa5f9742", 2, "dir-10" },
{ 0100644, "6c06dcd163587c2cc18be44857e0b71116382aeb", 3, "dir-10" },
{ 0100644, "43aafd43bea779ec74317dc361f45ae3f532a505", 0, "dir-6" },
{ 0100644, "a031a28ae70e33a641ce4b8a8f6317f1ab79dee4", 3, "dir-7" },
{ 0100644, "5012fd565b1393bdfda1805d4ec38ce6619e1fd1", 1, "dir-7/file.txt" },
{ 0100644, "a5563304ddf6caba25cb50323a2ea6f7dbfcadca", 2, "dir-7/file.txt" },
{ 0100644, "e9ad6ec3e38364a3d07feda7c4197d4d845c53b5", 0, "dir-8" },
{ 0100644, "3ef4d30382ca33fdeba9fda895a99e0891ba37aa", 2, "dir-9" },
{ 0100644, "fc4c636d6515e9e261f9260dbcf3cc6eca97ea08", 1, "dir-9/file.txt" },
{ 0100644, "76ab0e2868197ec158ddd6c78d8a0d2fd73d38f9", 3, "dir-9/file.txt" },
{ 0100644, "5c2411f8075f48a6b2fdb85ebc0d371747c4df15", 0, "file-1/new" },
{ 0100644, "a39a620dae5bc8b4e771cd4d251b7d080401a21e", 1, "file-2" },
{ 0100644, "d963979c237d08b6ba39062ee7bf64c7d34a27f8", 2, "file-2" },
{ 0100644, "5c341ead2ba6f2af98ce5ec3fe84f6b6d2899c0d", 0, "file-2/new" },
{ 0100644, "9efe7723802d4305142eee177e018fee1572c4f4", 0, "file-3/new" },
{ 0100644, "bacac9b3493509aa15e1730e1545fc0919d1dae0", 1, "file-4" },
{ 0100644, "7663fce0130db092936b137cabd693ec234eb060", 3, "file-4" },
{ 0100644, "e49f917b448d1340b31d76e54ba388268fd4c922", 0, "file-4/new" },
{ 0100644, "cab2cf23998b40f1af2d9d9a756dc9e285a8df4b", 2, "file-5/new" },
{ 0100644, "f5504f36e6f4eb797a56fc5bac6c6c7f32969bf2", 3, "file-5/new" },
};
cl_git_pass(merge_trees_from_branches(&index, repo, "df_side1", "df_side2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 20));
git_index_free(index);
}
void test_merge_trees_commits__fail_on_conflict(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
opts.flags |= GIT_MERGE_FAIL_ON_CONFLICT;
cl_git_fail_with(GIT_EMERGECONFLICT,
merge_trees_from_branches(&index, repo, "df_side1", "df_side2", &opts));
cl_git_fail_with(GIT_EMERGECONFLICT,
merge_commits_from_branches(&index, repo, "master", "unrelated", &opts));
cl_git_fail_with(GIT_EMERGECONFLICT,
merge_commits_from_branches(&index, repo, "master", "branch", &opts));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/trees/trivial.c
|
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "merge.h"
#include "../merge_helpers.h"
#include "refs.h"
#include "futils.h"
#include "git2/sys/index.h"
static git_repository *repo;
#define TEST_REPO_PATH "merge-resolve"
#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
/* Fixture setup and teardown */
void test_merge_trees_trivial__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
}
void test_merge_trees_trivial__cleanup(void)
{
cl_git_sandbox_cleanup();
}
static int merge_trivial(git_index **index, const char *ours, const char *theirs)
{
git_commit *our_commit, *their_commit, *ancestor_commit;
git_tree *our_tree, *their_tree, *ancestor_tree;
git_oid our_oid, their_oid, ancestor_oid;
git_buf branch_buf = GIT_BUF_INIT;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours);
cl_git_pass(git_reference_name_to_id(&our_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid));
git_buf_clear(&branch_buf);
git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs);
cl_git_pass(git_reference_name_to_id(&their_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&their_commit, repo, &their_oid));
cl_git_pass(git_merge_base(&ancestor_oid, repo, git_commit_id(our_commit), git_commit_id(their_commit)));
cl_git_pass(git_commit_lookup(&ancestor_commit, repo, &ancestor_oid));
cl_git_pass(git_commit_tree(&ancestor_tree, ancestor_commit));
cl_git_pass(git_commit_tree(&our_tree, our_commit));
cl_git_pass(git_commit_tree(&their_tree, their_commit));
cl_git_pass(git_merge_trees(index, repo, ancestor_tree, our_tree, their_tree, &opts));
git_buf_dispose(&branch_buf);
git_tree_free(our_tree);
git_tree_free(their_tree);
git_tree_free(ancestor_tree);
git_commit_free(our_commit);
git_commit_free(their_commit);
git_commit_free(ancestor_commit);
return 0;
}
static int merge_trivial_conflict_entrycount(git_index *index)
{
const git_index_entry *entry;
int count = 0;
size_t i;
for (i = 0; i < git_index_entrycount(index); i++) {
cl_assert(entry = git_index_get_byindex(index, i));
if (git_index_entry_is_conflict(entry))
count++;
}
return count;
}
/* 2ALT: ancest:(empty)+, head:*empty*, remote:remote = result:remote */
void test_merge_trees_trivial__2alt(void)
{
git_index *result;
const git_index_entry *entry;
cl_git_pass(merge_trivial(&result, "trivial-2alt", "trivial-2alt-branch"));
cl_assert(entry = git_index_get_bypath(result, "new-in-branch.txt", 0));
cl_assert(git_index_reuc_entrycount(result) == 0);
cl_assert(merge_trivial_conflict_entrycount(result) == 0);
git_index_free(result);
}
/* 3ALT: ancest:(empty)+, head:head, remote:*empty* = result:head */
void test_merge_trees_trivial__3alt(void)
{
git_index *result;
const git_index_entry *entry;
cl_git_pass(merge_trivial(&result, "trivial-3alt", "trivial-3alt-branch"));
cl_assert(entry = git_index_get_bypath(result, "new-in-3alt.txt", 0));
cl_assert(git_index_reuc_entrycount(result) == 0);
cl_assert(merge_trivial_conflict_entrycount(result) == 0);
git_index_free(result);
}
/* 4: ancest:(empty)^, head:head, remote:remote = result:no merge */
void test_merge_trees_trivial__4(void)
{
git_index *result;
const git_index_entry *entry;
cl_git_pass(merge_trivial(&result, "trivial-4", "trivial-4-branch"));
cl_assert((entry = git_index_get_bypath(result, "new-and-different.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 0);
cl_assert(merge_trivial_conflict_entrycount(result) == 2);
cl_assert(entry = git_index_get_bypath(result, "new-and-different.txt", 2));
cl_assert(entry = git_index_get_bypath(result, "new-and-different.txt", 3));
git_index_free(result);
}
/* 5ALT: ancest:*, head:head, remote:head = result:head */
void test_merge_trees_trivial__5alt_1(void)
{
git_index *result;
const git_index_entry *entry;
cl_git_pass(merge_trivial(&result, "trivial-5alt-1", "trivial-5alt-1-branch"));
cl_assert(entry = git_index_get_bypath(result, "new-and-same.txt", 0));
cl_assert(git_index_reuc_entrycount(result) == 0);
cl_assert(merge_trivial_conflict_entrycount(result) == 0);
git_index_free(result);
}
/* 5ALT: ancest:*, head:head, remote:head = result:head */
void test_merge_trees_trivial__5alt_2(void)
{
git_index *result;
const git_index_entry *entry;
cl_git_pass(merge_trivial(&result, "trivial-5alt-2", "trivial-5alt-2-branch"));
cl_assert(entry = git_index_get_bypath(result, "modified-to-same.txt", 0));
cl_assert(git_index_reuc_entrycount(result) == 0);
cl_assert(merge_trivial_conflict_entrycount(result) == 0);
git_index_free(result);
}
/* 6: ancest:ancest+, head:(empty), remote:(empty) = result:no merge */
void test_merge_trees_trivial__6(void)
{
git_index *result;
const git_index_entry *entry;
const git_index_reuc_entry *reuc;
cl_git_pass(merge_trivial(&result, "trivial-6", "trivial-6-branch"));
cl_assert((entry = git_index_get_bypath(result, "removed-in-both.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 1);
cl_assert(reuc = git_index_reuc_get_bypath(result, "removed-in-both.txt"));
cl_assert(merge_trivial_conflict_entrycount(result) == 0);
git_index_free(result);
}
/* 8: ancest:ancest^, head:(empty), remote:ancest = result:no merge */
void test_merge_trees_trivial__8(void)
{
git_index *result;
const git_index_entry *entry;
const git_index_reuc_entry *reuc;
cl_git_pass(merge_trivial(&result, "trivial-8", "trivial-8-branch"));
cl_assert((entry = git_index_get_bypath(result, "removed-in-8.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 1);
cl_assert(reuc = git_index_reuc_get_bypath(result, "removed-in-8.txt"));
cl_assert(merge_trivial_conflict_entrycount(result) == 0);
git_index_free(result);
}
/* 7: ancest:ancest+, head:(empty), remote:remote = result:no merge */
void test_merge_trees_trivial__7(void)
{
git_index *result;
const git_index_entry *entry;
cl_git_pass(merge_trivial(&result, "trivial-7", "trivial-7-branch"));
cl_assert((entry = git_index_get_bypath(result, "removed-in-7.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 0);
cl_assert(merge_trivial_conflict_entrycount(result) == 2);
cl_assert(entry = git_index_get_bypath(result, "removed-in-7.txt", 1));
cl_assert(entry = git_index_get_bypath(result, "removed-in-7.txt", 3));
git_index_free(result);
}
/* 10: ancest:ancest^, head:ancest, remote:(empty) = result:no merge */
void test_merge_trees_trivial__10(void)
{
git_index *result;
const git_index_entry *entry;
const git_index_reuc_entry *reuc;
cl_git_pass(merge_trivial(&result, "trivial-10", "trivial-10-branch"));
cl_assert((entry = git_index_get_bypath(result, "removed-in-10-branch.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 1);
cl_assert(reuc = git_index_reuc_get_bypath(result, "removed-in-10-branch.txt"));
cl_assert(merge_trivial_conflict_entrycount(result) == 0);
git_index_free(result);
}
/* 9: ancest:ancest+, head:head, remote:(empty) = result:no merge */
void test_merge_trees_trivial__9(void)
{
git_index *result;
const git_index_entry *entry;
cl_git_pass(merge_trivial(&result, "trivial-9", "trivial-9-branch"));
cl_assert((entry = git_index_get_bypath(result, "removed-in-9-branch.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 0);
cl_assert(merge_trivial_conflict_entrycount(result) == 2);
cl_assert(entry = git_index_get_bypath(result, "removed-in-9-branch.txt", 1));
cl_assert(entry = git_index_get_bypath(result, "removed-in-9-branch.txt", 2));
git_index_free(result);
}
/* 13: ancest:ancest+, head:head, remote:ancest = result:head */
void test_merge_trees_trivial__13(void)
{
git_index *result;
const git_index_entry *entry;
git_oid expected_oid;
cl_git_pass(merge_trivial(&result, "trivial-13", "trivial-13-branch"));
cl_assert(entry = git_index_get_bypath(result, "modified-in-13.txt", 0));
cl_git_pass(git_oid_fromstr(&expected_oid, "1cff9ec6a47a537380dedfdd17c9e76d74259a2b"));
cl_assert_equal_oid(&expected_oid, &entry->id);
cl_assert(git_index_reuc_entrycount(result) == 0);
cl_assert(merge_trivial_conflict_entrycount(result) == 0);
git_index_free(result);
}
/* 14: ancest:ancest+, head:ancest, remote:remote = result:remote */
void test_merge_trees_trivial__14(void)
{
git_index *result;
const git_index_entry *entry;
git_oid expected_oid;
cl_git_pass(merge_trivial(&result, "trivial-14", "trivial-14-branch"));
cl_assert(entry = git_index_get_bypath(result, "modified-in-14-branch.txt", 0));
cl_git_pass(git_oid_fromstr(&expected_oid, "26153a3ff3649b6c2bb652d3f06878c6e0a172f9"));
cl_assert(git_oid_cmp(&entry->id, &expected_oid) == 0);
cl_assert(git_index_reuc_entrycount(result) == 0);
cl_assert(merge_trivial_conflict_entrycount(result) == 0);
git_index_free(result);
}
/* 11: ancest:ancest+, head:head, remote:remote = result:no merge */
void test_merge_trees_trivial__11(void)
{
git_index *result;
const git_index_entry *entry;
cl_git_pass(merge_trivial(&result, "trivial-11", "trivial-11-branch"));
cl_assert((entry = git_index_get_bypath(result, "modified-in-both.txt", 0)) == NULL);
cl_assert(git_index_reuc_entrycount(result) == 0);
cl_assert(merge_trivial_conflict_entrycount(result) == 3);
cl_assert(entry = git_index_get_bypath(result, "modified-in-both.txt", 1));
cl_assert(entry = git_index_get_bypath(result, "modified-in-both.txt", 2));
cl_assert(entry = git_index_get_bypath(result, "modified-in-both.txt", 3));
git_index_free(result);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/merge/trees/automerge.c
|
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "buffer.h"
#include "merge.h"
#include "futils.h"
#include "../merge_helpers.h"
#include "../conflict_data.h"
static git_repository *repo;
#define TEST_REPO_PATH "merge-resolve"
#define TEST_INDEX_PATH TEST_REPO_PATH "/.git/index"
#define THEIRS_AUTOMERGE_BRANCH "branch"
#define THEIRS_UNRELATED_BRANCH "unrelated"
#define THEIRS_UNRELATED_OID "55b4e4687e7a0d9ca367016ed930f385d4022e6f"
#define THEIRS_UNRELATED_PARENT "d6cf6c7741b3316826af1314042550c97ded1d50"
#define OURS_DIRECTORY_FILE "df_side1"
#define THEIRS_DIRECTORY_FILE "df_side2"
/* Non-conflicting files, index entries are common to every merge operation */
#define ADDED_IN_MASTER_INDEX_ENTRY \
{ 0100644, "233c0919c998ed110a4b6ff36f353aec8b713487", 0, "added-in-master.txt" }
#define AUTOMERGEABLE_INDEX_ENTRY \
{ 0100644, "f2e1550a0c9e53d5811175864a29536642ae3821", 0, "automergeable.txt" }
#define CHANGED_IN_BRANCH_INDEX_ENTRY \
{ 0100644, "4eb04c9e79e88f6640d01ff5b25ca2a60764f216", 0, "changed-in-branch.txt" }
#define CHANGED_IN_MASTER_INDEX_ENTRY \
{ 0100644, "11deab00b2d3a6f5a3073988ac050c2d7b6655e2", 0, "changed-in-master.txt" }
#define UNCHANGED_INDEX_ENTRY \
{ 0100644, "c8f06f2e3bb2964174677e91f0abead0e43c9e5d", 0, "unchanged.txt" }
/* Expected REUC entries */
#define AUTOMERGEABLE_REUC_ENTRY \
{ "automergeable.txt", 0100644, 0100644, 0100644, \
"6212c31dab5e482247d7977e4f0dd3601decf13b", \
"ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", \
"058541fc37114bfc1dddf6bd6bffc7fae5c2e6fe" }
#define CONFLICTING_REUC_ENTRY \
{ "conflicting.txt", 0100644, 0100644, 0100644, \
"d427e0b2e138501a3d15cc376077a3631e15bd46", \
"4e886e602529caa9ab11d71f86634bd1b6e0de10", \
"2bd0a343aeef7a2cf0d158478966a6e587ff3863" }
#define REMOVED_IN_BRANCH_REUC_ENTRY \
{ "removed-in-branch.txt", 0100644, 0100644, 0, \
"dfe3f22baa1f6fce5447901c3086bae368de6bdd", \
"dfe3f22baa1f6fce5447901c3086bae368de6bdd", \
"" }
#define REMOVED_IN_MASTER_REUC_ENTRY \
{ "removed-in-master.txt", 0100644, 0, 0100644, \
"5c3b68a71fc4fa5d362fd3875e53137c6a5ab7a5", \
"", \
"5c3b68a71fc4fa5d362fd3875e53137c6a5ab7a5" }
/* Fixture setup and teardown */
void test_merge_trees_automerge__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
}
void test_merge_trees_automerge__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_merge_trees_automerge__automerge(void)
{
git_index *index;
const git_index_entry *entry;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
git_blob *blob;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
AUTOMERGEABLE_INDEX_ENTRY,
CHANGED_IN_BRANCH_INDEX_ENTRY,
CHANGED_IN_MASTER_INDEX_ENTRY,
{ 0100644, "d427e0b2e138501a3d15cc376077a3631e15bd46", 1, "conflicting.txt" },
{ 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 2, "conflicting.txt" },
{ 0100644, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", 3, "conflicting.txt" },
UNCHANGED_INDEX_ENTRY,
};
struct merge_reuc_entry merge_reuc_entries[] = {
AUTOMERGEABLE_REUC_ENTRY,
REMOVED_IN_BRANCH_REUC_ENTRY,
REMOVED_IN_MASTER_REUC_ENTRY
};
cl_git_pass(merge_trees_from_branches(&index, repo, "master", THEIRS_AUTOMERGE_BRANCH, &opts));
cl_assert(merge_test_index(index, merge_index_entries, 8));
cl_assert(merge_test_reuc(index, merge_reuc_entries, 3));
cl_assert((entry = git_index_get_bypath(index, "automergeable.txt", 0)) != NULL);
cl_assert(entry->file_size == strlen(AUTOMERGEABLE_MERGED_FILE));
cl_git_pass(git_object_lookup((git_object **)&blob, repo, &entry->id, GIT_OBJECT_BLOB));
cl_assert(memcmp(git_blob_rawcontent(blob), AUTOMERGEABLE_MERGED_FILE, (size_t)entry->file_size) == 0);
git_index_free(index);
git_blob_free(blob);
}
void test_merge_trees_automerge__favor_ours(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
AUTOMERGEABLE_INDEX_ENTRY,
CHANGED_IN_BRANCH_INDEX_ENTRY,
CHANGED_IN_MASTER_INDEX_ENTRY,
{ 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 0, "conflicting.txt" },
UNCHANGED_INDEX_ENTRY,
};
struct merge_reuc_entry merge_reuc_entries[] = {
AUTOMERGEABLE_REUC_ENTRY,
CONFLICTING_REUC_ENTRY,
REMOVED_IN_BRANCH_REUC_ENTRY,
REMOVED_IN_MASTER_REUC_ENTRY,
};
opts.file_favor = GIT_MERGE_FILE_FAVOR_OURS;
cl_git_pass(merge_trees_from_branches(&index, repo, "master", THEIRS_AUTOMERGE_BRANCH, &opts));
cl_assert(merge_test_index(index, merge_index_entries, 6));
cl_assert(merge_test_reuc(index, merge_reuc_entries, 4));
git_index_free(index);
}
void test_merge_trees_automerge__favor_theirs(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
ADDED_IN_MASTER_INDEX_ENTRY,
AUTOMERGEABLE_INDEX_ENTRY,
CHANGED_IN_BRANCH_INDEX_ENTRY,
CHANGED_IN_MASTER_INDEX_ENTRY,
{ 0100644, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", 0, "conflicting.txt" },
UNCHANGED_INDEX_ENTRY,
};
struct merge_reuc_entry merge_reuc_entries[] = {
AUTOMERGEABLE_REUC_ENTRY,
CONFLICTING_REUC_ENTRY,
REMOVED_IN_BRANCH_REUC_ENTRY,
REMOVED_IN_MASTER_REUC_ENTRY,
};
opts.file_favor = GIT_MERGE_FILE_FAVOR_THEIRS;
cl_git_pass(merge_trees_from_branches(&index, repo, "master", THEIRS_AUTOMERGE_BRANCH, &opts));
cl_assert(merge_test_index(index, merge_index_entries, 6));
cl_assert(merge_test_reuc(index, merge_reuc_entries, 4));
git_index_free(index);
}
void test_merge_trees_automerge__unrelated(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "233c0919c998ed110a4b6ff36f353aec8b713487", 0, "added-in-master.txt" },
{ 0100644, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", 2, "automergeable.txt" },
{ 0100644, "d07ec190c306ec690bac349e87d01c4358e49bb2", 3, "automergeable.txt" },
{ 0100644, "ab6c44a2e84492ad4b41bb6bac87353e9d02ac8b", 0, "changed-in-branch.txt" },
{ 0100644, "11deab00b2d3a6f5a3073988ac050c2d7b6655e2", 0, "changed-in-master.txt" },
{ 0100644, "4e886e602529caa9ab11d71f86634bd1b6e0de10", 2, "conflicting.txt" },
{ 0100644, "4b253da36a0ae8bfce63aeabd8c5b58429925594", 3, "conflicting.txt" },
{ 0100644, "ef58fdd8086c243bdc81f99e379acacfd21d32d6", 0, "new-in-unrelated1.txt" },
{ 0100644, "948ba6e701c1edab0c2d394fb7c5538334129793", 0, "new-in-unrelated2.txt" },
{ 0100644, "dfe3f22baa1f6fce5447901c3086bae368de6bdd", 0, "removed-in-branch.txt" },
{ 0100644, "c8f06f2e3bb2964174677e91f0abead0e43c9e5d", 0, "unchanged.txt" },
};
cl_git_pass(merge_trees_from_branches(&index, repo, "master", THEIRS_UNRELATED_BRANCH, &opts));
cl_assert(merge_test_index(index, merge_index_entries, 11));
git_index_free(index);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/ignore/path.c
|
#include "clar_libgit2.h"
#include "posix.h"
#include "path.h"
#include "futils.h"
static git_repository *g_repo = NULL;
void test_ignore_path__initialize(void)
{
g_repo = cl_git_sandbox_init("attr");
}
void test_ignore_path__cleanup(void)
{
cl_git_sandbox_cleanup();
g_repo = NULL;
}
static void assert_is_ignored_(
bool expected, const char *filepath,
const char *file, const char *func, int line)
{
int is_ignored = 0;
cl_git_expect(
git_ignore_path_is_ignored(&is_ignored, g_repo, filepath), 0, file, func, line);
clar__assert_equal(
file, func, line, "expected != is_ignored", 1, "%d",
(int)(expected != 0), (int)(is_ignored != 0));
}
#define assert_is_ignored(expected, filepath) \
assert_is_ignored_(expected, filepath, __FILE__, __func__, __LINE__)
void test_ignore_path__honor_temporary_rules(void)
{
cl_git_rewritefile("attr/.gitignore", "/NewFolder\n/NewFolder/NewFolder");
assert_is_ignored(false, "File.txt");
assert_is_ignored(true, "NewFolder");
assert_is_ignored(true, "NewFolder/NewFolder");
assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
}
void test_ignore_path__allow_root(void)
{
cl_git_rewritefile("attr/.gitignore", "/");
assert_is_ignored(false, "File.txt");
assert_is_ignored(false, "NewFolder");
assert_is_ignored(false, "NewFolder/NewFolder");
assert_is_ignored(false, "NewFolder/NewFolder/File.txt");
}
void test_ignore_path__ignore_space(void)
{
cl_git_rewritefile("attr/.gitignore", "/\n\n/NewFolder \n/NewFolder/NewFolder");
assert_is_ignored(false, "File.txt");
assert_is_ignored(true, "NewFolder");
assert_is_ignored(true, "NewFolder/NewFolder");
assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
}
void test_ignore_path__intermittent_space(void)
{
cl_git_rewritefile("attr/.gitignore", "foo bar\n");
assert_is_ignored(false, "foo");
assert_is_ignored(false, "bar");
assert_is_ignored(true, "foo bar");
}
void test_ignore_path__trailing_space(void)
{
cl_git_rewritefile(
"attr/.gitignore",
"foo \n"
"bar \n"
);
assert_is_ignored(true, "foo");
assert_is_ignored(false, "foo ");
assert_is_ignored(true, "bar");
assert_is_ignored(false, "bar ");
assert_is_ignored(false, "bar ");
}
void test_ignore_path__escaped_trailing_spaces(void)
{
cl_git_rewritefile(
"attr/.gitignore",
"foo\\ \n"
"bar\\ \\ \n"
"baz \\ \n"
"qux\\ \n"
);
assert_is_ignored(false, "foo");
assert_is_ignored(true, "foo ");
assert_is_ignored(false, "bar");
assert_is_ignored(false, "bar ");
assert_is_ignored(true, "bar ");
assert_is_ignored(true, "baz ");
assert_is_ignored(false, "baz ");
assert_is_ignored(true, "qux ");
assert_is_ignored(false, "qux");
assert_is_ignored(false, "qux ");
}
void test_ignore_path__ignore_dir(void)
{
cl_git_rewritefile("attr/.gitignore", "dir/\n");
assert_is_ignored(true, "dir");
assert_is_ignored(true, "dir/file");
}
void test_ignore_path__ignore_dir_with_trailing_space(void)
{
cl_git_rewritefile("attr/.gitignore", "dir/ \n");
assert_is_ignored(true, "dir");
assert_is_ignored(true, "dir/file");
}
void test_ignore_path__ignore_root(void)
{
cl_git_rewritefile("attr/.gitignore", "/\n\n/NewFolder\n/NewFolder/NewFolder");
assert_is_ignored(false, "File.txt");
assert_is_ignored(true, "NewFolder");
assert_is_ignored(true, "NewFolder/NewFolder");
assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
}
void test_ignore_path__full_paths(void)
{
cl_git_rewritefile("attr/.gitignore", "Folder/*/Contained");
assert_is_ignored(true, "Folder/Middle/Contained");
assert_is_ignored(false, "Folder/Middle/More/More/Contained");
cl_git_rewritefile("attr/.gitignore", "Folder/**/Contained");
assert_is_ignored(true, "Folder/Middle/Contained");
assert_is_ignored(true, "Folder/Middle/More/More/Contained");
cl_git_rewritefile("attr/.gitignore", "Folder/**/Contained/*/Child");
assert_is_ignored(true, "Folder/Middle/Contained/Happy/Child");
assert_is_ignored(false, "Folder/Middle/Contained/Not/Happy/Child");
assert_is_ignored(true, "Folder/Middle/More/More/Contained/Happy/Child");
assert_is_ignored(false, "Folder/Middle/More/More/Contained/Not/Happy/Child");
}
void test_ignore_path__more_starstar_cases(void)
{
cl_must_pass(p_unlink("attr/.gitignore"));
cl_git_mkfile(
"attr/dir/.gitignore",
"sub/**/*.html\n");
assert_is_ignored(false, "aaa.html");
assert_is_ignored(false, "dir");
assert_is_ignored(false, "dir/sub");
assert_is_ignored(true, "dir/sub/sub2/aaa.html");
assert_is_ignored(true, "dir/sub/aaa.html");
assert_is_ignored(false, "dir/aaa.html");
assert_is_ignored(false, "sub");
assert_is_ignored(false, "sub/aaa.html");
assert_is_ignored(false, "sub/sub2/aaa.html");
}
void test_ignore_path__leading_stars(void)
{
cl_git_rewritefile(
"attr/.gitignore",
"*/onestar\n"
"**/twostars\n"
"*/parent1/kid1/*\n"
"**/parent2/kid2/*\n");
assert_is_ignored(true, "dir1/onestar");
assert_is_ignored(true, "dir1/onestar/child"); /* in ignored dir */
assert_is_ignored(false, "dir1/dir2/onestar");
assert_is_ignored(true, "dir1/twostars");
assert_is_ignored(true, "dir1/twostars/child"); /* in ignored dir */
assert_is_ignored(true, "dir1/dir2/twostars");
assert_is_ignored(true, "dir1/dir2/twostars/child"); /* in ignored dir */
assert_is_ignored(true, "dir1/dir2/dir3/twostars");
assert_is_ignored(true, "dir1/parent1/kid1/file");
assert_is_ignored(true, "dir1/parent1/kid1/file/inside/parent");
assert_is_ignored(false, "dir1/dir2/parent1/kid1/file");
assert_is_ignored(false, "dir1/parent1/file");
assert_is_ignored(false, "dir1/kid1/file");
assert_is_ignored(true, "dir1/parent2/kid2/file");
assert_is_ignored(true, "dir1/parent2/kid2/file/inside/parent");
assert_is_ignored(true, "dir1/dir2/parent2/kid2/file");
assert_is_ignored(true, "dir1/dir2/dir3/parent2/kid2/file");
assert_is_ignored(false, "dir1/parent2/file");
assert_is_ignored(false, "dir1/kid2/file");
}
void test_ignore_path__globs_and_path_delimiters(void)
{
cl_git_rewritefile("attr/.gitignore", "foo/bar/**");
assert_is_ignored(true, "foo/bar/baz");
assert_is_ignored(true, "foo/bar/baz/quux");
cl_git_rewritefile("attr/.gitignore", "_*/");
assert_is_ignored(true, "sub/_test/a/file");
assert_is_ignored(false, "test_folder/file");
assert_is_ignored(true, "_test/file");
assert_is_ignored(true, "_test/a/file");
cl_git_rewritefile("attr/.gitignore", "**/_*/");
assert_is_ignored(true, "sub/_test/a/file");
assert_is_ignored(false, "test_folder/file");
assert_is_ignored(true, "_test/file");
assert_is_ignored(true, "_test/a/file");
cl_git_rewritefile("attr/.gitignore", "**/_*/foo/bar/*ux");
assert_is_ignored(true, "sub/_test/foo/bar/qux/file");
assert_is_ignored(true, "_test/foo/bar/qux/file");
assert_is_ignored(true, "_test/foo/bar/crux/file");
assert_is_ignored(false, "_test/foo/bar/code/file");
}
void test_ignore_path__globs_without_star(void)
{
cl_git_rewritefile(
"attr/.gitignore",
"*.foo\n"
"**.bar\n"
);
assert_is_ignored(true, ".foo");
assert_is_ignored(true, "xyz.foo");
assert_is_ignored(true, ".bar");
assert_is_ignored(true, "x.bar");
assert_is_ignored(true, "xyz.bar");
assert_is_ignored(true, "test/.foo");
assert_is_ignored(true, "test/x.foo");
assert_is_ignored(true, "test/xyz.foo");
assert_is_ignored(true, "test/.bar");
assert_is_ignored(true, "test/x.bar");
assert_is_ignored(true, "test/xyz.bar");
}
void test_ignore_path__skip_gitignore_directory(void)
{
cl_git_rewritefile("attr/.git/info/exclude", "/NewFolder\n/NewFolder/NewFolder");
cl_must_pass(p_unlink("attr/.gitignore"));
cl_assert(!git_path_exists("attr/.gitignore"));
p_mkdir("attr/.gitignore", 0777);
cl_git_mkfile("attr/.gitignore/garbage.txt", "new_file\n");
assert_is_ignored(false, "File.txt");
assert_is_ignored(true, "NewFolder");
assert_is_ignored(true, "NewFolder/NewFolder");
assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
}
void test_ignore_path__subdirectory_gitignore(void)
{
cl_must_pass(p_unlink("attr/.gitignore"));
cl_assert(!git_path_exists("attr/.gitignore"));
cl_git_mkfile(
"attr/.gitignore",
"file1\n");
cl_git_mkfile(
"attr/dir/.gitignore",
"file2/\n");
assert_is_ignored(true, "file1");
assert_is_ignored(true, "dir/file1");
assert_is_ignored(true, "dir/file2/actual_file"); /* in ignored dir */
assert_is_ignored(false, "dir/file3");
}
void test_ignore_path__expand_tilde_to_homedir(void)
{
git_config *cfg;
assert_is_ignored(false, "example.global_with_tilde");
cl_fake_home();
/* construct fake home with fake global excludes */
cl_git_mkfile("home/globalexclude", "# found me\n*.global_with_tilde\n");
cl_git_pass(git_repository_config(&cfg, g_repo));
cl_git_pass(git_config_set_string(cfg, "core.excludesfile", "~/globalexclude"));
git_config_free(cfg);
git_attr_cache_flush(g_repo); /* must reset to pick up change */
assert_is_ignored(true, "example.global_with_tilde");
cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES));
cl_fake_home_cleanup(NULL);
git_attr_cache_flush(g_repo); /* must reset to pick up change */
assert_is_ignored(false, "example.global_with_tilde");
}
/* Ensure that the .gitignore in the subdirectory only affects
* items in the subdirectory. */
void test_ignore_path__gitignore_in_subdir(void)
{
cl_git_rmfile("attr/.gitignore");
cl_must_pass(p_mkdir("attr/dir1", 0777));
cl_must_pass(p_mkdir("attr/dir1/dir2", 0777));
cl_must_pass(p_mkdir("attr/dir1/dir2/dir3", 0777));
cl_git_mkfile("attr/dir1/dir2/dir3/.gitignore", "dir1/\ndir1/subdir/");
assert_is_ignored(false, "dir1/file");
assert_is_ignored(false, "dir1/dir2/file");
assert_is_ignored(false, "dir1/dir2/dir3/file");
assert_is_ignored(true, "dir1/dir2/dir3/dir1/file");
assert_is_ignored(true, "dir1/dir2/dir3/dir1/subdir/foo");
if (cl_repo_get_bool(g_repo, "core.ignorecase")) {
cl_git_mkfile("attr/dir1/dir2/dir3/.gitignore", "DiR1/\nDiR1/subdir/\n");
assert_is_ignored(false, "dir1/file");
assert_is_ignored(false, "dir1/dir2/file");
assert_is_ignored(false, "dir1/dir2/dir3/file");
assert_is_ignored(true, "dir1/dir2/dir3/dir1/file");
assert_is_ignored(true, "dir1/dir2/dir3/dir1/subdir/foo");
}
}
/* Ensure that files do not match folder cases */
void test_ignore_path__dont_ignore_files_for_folder(void)
{
cl_git_rmfile("attr/.gitignore");
cl_git_mkfile("attr/dir/.gitignore", "test/\n");
/* Create "test" as a file; ensure it is not ignored. */
cl_git_mkfile("attr/dir/test", "This is a file.");
assert_is_ignored(false, "dir/test");
if (cl_repo_get_bool(g_repo, "core.ignorecase"))
assert_is_ignored(false, "dir/TeSt");
/* Create "test" as a directory; ensure it is ignored. */
cl_git_rmfile("attr/dir/test");
cl_must_pass(p_mkdir("attr/dir/test", 0777));
assert_is_ignored(true, "dir/test");
if (cl_repo_get_bool(g_repo, "core.ignorecase"))
assert_is_ignored(true, "dir/TeSt");
/* Remove "test" entirely; ensure it is not ignored.
* (As it doesn't exist, it is not a directory.)
*/
cl_must_pass(p_rmdir("attr/dir/test"));
assert_is_ignored(false, "dir/test");
if (cl_repo_get_bool(g_repo, "core.ignorecase"))
assert_is_ignored(false, "dir/TeSt");
}
void test_ignore_path__symlink_to_outside(void)
{
#ifdef GIT_WIN32
cl_skip();
#endif
cl_git_rewritefile("attr/.gitignore", "symlink\n");
cl_git_mkfile("target", "target");
cl_git_pass(p_symlink("../target", "attr/symlink"));
assert_is_ignored(true, "symlink");
assert_is_ignored(true, "lala/../symlink");
}
void test_ignore_path__test(void)
{
cl_git_rewritefile("attr/.gitignore",
"/*/\n"
"!/src\n");
assert_is_ignored(false, "src/foo.c");
assert_is_ignored(false, "src/foo/foo.c");
assert_is_ignored(false, "README.md");
assert_is_ignored(true, "dist/foo.o");
assert_is_ignored(true, "bin/foo");
}
void test_ignore_path__unignore_dir_succeeds(void)
{
cl_git_rewritefile("attr/.gitignore",
"*.c\n"
"!src/*.c\n");
assert_is_ignored(false, "src/foo.c");
assert_is_ignored(true, "src/foo/foo.c");
}
void test_ignore_path__case_insensitive_unignores_previous_rule(void)
{
git_config *cfg;
cl_git_rewritefile("attr/.gitignore",
"/case\n"
"!/Case/\n");
cl_git_pass(git_repository_config(&cfg, g_repo));
cl_git_pass(git_config_set_bool(cfg, "core.ignorecase", true));
cl_must_pass(p_mkdir("attr/case", 0755));
cl_git_mkfile("attr/case/file", "content");
assert_is_ignored(false, "case/file");
}
void test_ignore_path__case_sensitive_unignore_does_nothing(void)
{
git_config *cfg;
cl_git_rewritefile("attr/.gitignore",
"/case\n"
"!/Case/\n");
cl_git_pass(git_repository_config(&cfg, g_repo));
cl_git_pass(git_config_set_bool(cfg, "core.ignorecase", false));
cl_must_pass(p_mkdir("attr/case", 0755));
cl_git_mkfile("attr/case/file", "content");
assert_is_ignored(true, "case/file");
}
void test_ignore_path__ignored_subdirfiles_with_subdir_rule(void)
{
cl_git_rewritefile(
"attr/.gitignore",
"dir/*\n"
"!dir/sub1/sub2/**\n");
assert_is_ignored(true, "dir/a.test");
assert_is_ignored(true, "dir/sub1/a.test");
assert_is_ignored(true, "dir/sub1/sub2");
}
void test_ignore_path__ignored_subdirfiles_with_negations(void)
{
cl_git_rewritefile(
"attr/.gitignore",
"dir/*\n"
"!dir/a.test\n");
assert_is_ignored(false, "dir/a.test");
assert_is_ignored(true, "dir/b.test");
assert_is_ignored(true, "dir/sub1/c.test");
}
void test_ignore_path__negative_directory_rules_only_match_directories(void)
{
cl_git_rewritefile(
"attr/.gitignore",
"*\n"
"!/**/\n"
"!*.keep\n"
"!.gitignore\n"
);
assert_is_ignored(true, "src");
assert_is_ignored(true, "src/A");
assert_is_ignored(false, "src/");
assert_is_ignored(false, "src/A.keep");
assert_is_ignored(false, ".gitignore");
}
void test_ignore_path__escaped_character(void)
{
cl_git_rewritefile("attr/.gitignore", "\\c\n");
assert_is_ignored(true, "c");
assert_is_ignored(false, "\\c");
}
void test_ignore_path__escaped_newline(void)
{
cl_git_rewritefile(
"attr/.gitignore",
"\\\nnewline\n"
);
assert_is_ignored(true, "\nnewline");
}
void test_ignore_path__escaped_glob(void)
{
cl_git_rewritefile("attr/.gitignore", "\\*\n");
assert_is_ignored(true, "*");
assert_is_ignored(false, "foo");
}
void test_ignore_path__escaped_comments(void)
{
cl_git_rewritefile(
"attr/.gitignore",
"#foo\n"
"\\#bar\n"
"\\##baz\n"
"\\#\\\\#qux\n"
);
assert_is_ignored(false, "#foo");
assert_is_ignored(true, "#bar");
assert_is_ignored(false, "\\#bar");
assert_is_ignored(true, "##baz");
assert_is_ignored(false, "\\##baz");
assert_is_ignored(true, "#\\#qux");
assert_is_ignored(false, "##qux");
assert_is_ignored(false, "\\##qux");
}
void test_ignore_path__escaped_slash(void)
{
cl_git_rewritefile(
"attr/.gitignore",
"\\\\\n"
"\\\\preceding\n"
"inter\\\\mittent\n"
"trailing\\\\\n"
);
#ifndef GIT_WIN32
assert_is_ignored(true, "\\");
assert_is_ignored(true, "\\preceding");
#endif
assert_is_ignored(true, "inter\\mittent");
assert_is_ignored(true, "trailing\\");
}
void test_ignore_path__escaped_space(void)
{
cl_git_rewritefile(
"attr/.gitignore",
"foo\\\\ \n"
"bar\\\\\\ \n");
assert_is_ignored(true, "foo\\");
assert_is_ignored(false, "foo\\ ");
assert_is_ignored(false, "foo\\\\ ");
assert_is_ignored(false, "foo\\\\");
assert_is_ignored(true, "bar\\ ");
assert_is_ignored(false, "bar\\\\");
assert_is_ignored(false, "bar\\\\ ");
assert_is_ignored(false, "bar\\\\\\");
assert_is_ignored(false, "bar\\\\\\ ");
}
void test_ignore_path__invalid_pattern(void)
{
cl_git_rewritefile("attr/.gitignore", "[");
assert_is_ignored(false, "[f");
assert_is_ignored(false, "f");
}
void test_ignore_path__negative_prefix_rule(void)
{
cl_git_rewritefile("attr/.gitignore", "ff*\n!f\n");
assert_is_ignored(true, "fff");
assert_is_ignored(true, "ff");
assert_is_ignored(false, "f");
}
void test_ignore_path__negative_more_specific(void)
{
cl_git_rewritefile("attr/.gitignore", "*.txt\n!/dir/test.txt\n");
assert_is_ignored(true, "test.txt");
assert_is_ignored(false, "dir/test.txt");
assert_is_ignored(true, "outer/dir/test.txt");
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/ignore/status.c
|
#include "clar_libgit2.h"
#include "futils.h"
#include "git2/attr.h"
#include "ignore.h"
#include "attr.h"
#include "status/status_helpers.h"
static git_repository *g_repo = NULL;
void test_ignore_status__initialize(void)
{
}
void test_ignore_status__cleanup(void)
{
cl_git_sandbox_cleanup();
}
static void assert_ignored_(
bool expected, const char *filepath,
const char *file, const char *func, int line)
{
int is_ignored = 0;
cl_git_expect(
git_status_should_ignore(&is_ignored, g_repo, filepath), 0, file, func, line);
clar__assert(
(expected != 0) == (is_ignored != 0),
file, func, line, "expected != is_ignored", filepath, 1);
}
#define assert_ignored(expected, filepath) \
assert_ignored_(expected, filepath, __FILE__, __func__, __LINE__)
#define assert_is_ignored(filepath) \
assert_ignored_(true, filepath, __FILE__, __func__, __LINE__)
#define refute_is_ignored(filepath) \
assert_ignored_(false, filepath, __FILE__, __func__, __LINE__)
void test_ignore_status__0(void)
{
struct {
const char *path;
int expected;
} test_cases[] = {
/* pattern "ign" from .gitignore */
{ "file", 0 },
{ "ign", 1 },
{ "sub", 0 },
{ "sub/file", 0 },
{ "sub/ign", 1 },
{ "sub/ign/file", 1 },
{ "sub/ign/sub", 1 },
{ "sub/ign/sub/file", 1 },
{ "sub/sub", 0 },
{ "sub/sub/file", 0 },
{ "sub/sub/ign", 1 },
{ "sub/sub/sub", 0 },
/* pattern "dir/" from .gitignore */
{ "dir", 1 },
{ "dir/", 1 },
{ "sub/dir", 1 },
{ "sub/dir/", 1 },
{ "sub/dir/file", 1 }, /* contained in ignored parent */
{ "sub/sub/dir", 0 }, /* dir is not actually a dir, but a file */
{ NULL, 0 }
}, *one_test;
g_repo = cl_git_sandbox_init("attr");
for (one_test = test_cases; one_test->path != NULL; one_test++)
assert_ignored(one_test->expected, one_test->path);
/* confirm that ignore files were cached */
cl_assert(git_attr_cache__is_cached(
g_repo, GIT_ATTR_FILE_SOURCE_FILE, ".git/info/exclude"));
cl_assert(git_attr_cache__is_cached(
g_repo, GIT_ATTR_FILE_SOURCE_FILE, ".gitignore"));
}
void test_ignore_status__1(void)
{
g_repo = cl_git_sandbox_init("attr");
cl_git_rewritefile("attr/.gitignore", "/*.txt\n/dir/\n");
git_attr_cache_flush(g_repo);
assert_is_ignored("root_test4.txt");
refute_is_ignored("sub/subdir_test2.txt");
assert_is_ignored("dir");
assert_is_ignored("dir/");
refute_is_ignored("sub/dir");
refute_is_ignored("sub/dir/");
}
void test_ignore_status__empty_repo_with_gitignore_rewrite(void)
{
status_entry_single st;
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_mkfile(
"empty_standard_repo/look-ma.txt", "I'm going to be ignored!");
memset(&st, 0, sizeof(st));
cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
cl_assert(st.count == 1);
cl_assert(st.status == GIT_STATUS_WT_NEW);
cl_git_pass(git_status_file(&st.status, g_repo, "look-ma.txt"));
cl_assert(st.status == GIT_STATUS_WT_NEW);
refute_is_ignored("look-ma.txt");
cl_git_rewritefile("empty_standard_repo/.gitignore", "*.nomatch\n");
memset(&st, 0, sizeof(st));
cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
cl_assert(st.count == 2);
cl_assert(st.status == GIT_STATUS_WT_NEW);
cl_git_pass(git_status_file(&st.status, g_repo, "look-ma.txt"));
cl_assert(st.status == GIT_STATUS_WT_NEW);
refute_is_ignored("look-ma.txt");
cl_git_rewritefile("empty_standard_repo/.gitignore", "*.txt\n");
memset(&st, 0, sizeof(st));
cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
cl_assert(st.count == 2);
cl_assert(st.status == GIT_STATUS_IGNORED);
cl_git_pass(git_status_file(&st.status, g_repo, "look-ma.txt"));
cl_assert(st.status == GIT_STATUS_IGNORED);
assert_is_ignored("look-ma.txt");
}
void test_ignore_status__ignore_pattern_contains_space(void)
{
unsigned int flags;
const mode_t mode = 0777;
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_rewritefile("empty_standard_repo/.gitignore", "foo bar.txt\n");
cl_git_mkfile(
"empty_standard_repo/foo bar.txt", "I'm going to be ignored!");
cl_git_pass(git_status_file(&flags, g_repo, "foo bar.txt"));
cl_assert(flags == GIT_STATUS_IGNORED);
cl_git_pass(git_futils_mkdir_r("empty_standard_repo/foo", mode));
cl_git_mkfile("empty_standard_repo/foo/look-ma.txt", "I'm not going to be ignored!");
cl_git_pass(git_status_file(&flags, g_repo, "foo/look-ma.txt"));
cl_assert(flags == GIT_STATUS_WT_NEW);
}
void test_ignore_status__ignore_pattern_ignorecase(void)
{
unsigned int flags;
bool ignore_case;
git_index *index;
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_rewritefile("empty_standard_repo/.gitignore", "a.txt\n");
cl_git_mkfile("empty_standard_repo/A.txt", "Differs in case");
cl_git_pass(git_repository_index(&index, g_repo));
ignore_case = (git_index_caps(index) & GIT_INDEX_CAPABILITY_IGNORE_CASE) != 0;
git_index_free(index);
cl_git_pass(git_status_file(&flags, g_repo, "A.txt"));
cl_assert(flags == ignore_case ? GIT_STATUS_IGNORED : GIT_STATUS_WT_NEW);
}
void test_ignore_status__subdirectories(void)
{
status_entry_single st;
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_mkfile(
"empty_standard_repo/ignore_me", "I'm going to be ignored!");
cl_git_rewritefile("empty_standard_repo/.gitignore", "ignore_me\n");
memset(&st, 0, sizeof(st));
cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
cl_assert_equal_i(2, st.count);
cl_assert(st.status == GIT_STATUS_IGNORED);
cl_git_pass(git_status_file(&st.status, g_repo, "ignore_me"));
cl_assert(st.status == GIT_STATUS_IGNORED);
assert_is_ignored("ignore_me");
/* I've changed libgit2 so that the behavior here now differs from
* core git but seems to make more sense. In core git, the following
* items are skipped completed, even if --ignored is passed to status.
* It you mirror these steps and run "git status -uall --ignored" then
* you will not see "test/ignore_me/" in the results.
*
* However, we had a couple reports of this as a bug, plus there is a
* similar circumstance where we were differing for core git when you
* used a rooted path for an ignore, so I changed this behavior.
*/
cl_git_pass(git_futils_mkdir_r(
"empty_standard_repo/test/ignore_me", 0775));
cl_git_mkfile(
"empty_standard_repo/test/ignore_me/file", "I'm going to be ignored!");
cl_git_mkfile(
"empty_standard_repo/test/ignore_me/file2", "Me, too!");
memset(&st, 0, sizeof(st));
cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
cl_assert_equal_i(3, st.count);
cl_git_pass(git_status_file(&st.status, g_repo, "test/ignore_me/file"));
cl_assert(st.status == GIT_STATUS_IGNORED);
assert_is_ignored("test/ignore_me/file");
}
static void make_test_data(const char *reponame, const char **files)
{
const char **scan;
size_t repolen = strlen(reponame) + 1;
g_repo = cl_git_sandbox_init(reponame);
for (scan = files; *scan != NULL; ++scan) {
cl_git_pass(git_futils_mkdir_relative(
*scan + repolen, reponame,
0777, GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST, NULL));
cl_git_mkfile(*scan, "contents");
}
}
static const char *test_repo_1 = "empty_standard_repo";
static const char *test_files_1[] = {
"empty_standard_repo/dir/a/ignore_me",
"empty_standard_repo/dir/b/ignore_me",
"empty_standard_repo/dir/ignore_me",
"empty_standard_repo/ignore_also/file",
"empty_standard_repo/ignore_me",
"empty_standard_repo/test/ignore_me/file",
"empty_standard_repo/test/ignore_me/file2",
"empty_standard_repo/test/ignore_me/and_me/file",
NULL
};
void test_ignore_status__subdirectories_recursion(void)
{
/* Let's try again with recursing into ignored dirs turned on */
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
status_entry_counts counts;
static const char *paths_r[] = {
".gitignore",
"dir/a/ignore_me",
"dir/b/ignore_me",
"dir/ignore_me",
"ignore_also/file",
"ignore_me",
"test/ignore_me/and_me/file",
"test/ignore_me/file",
"test/ignore_me/file2",
};
static const unsigned int statuses_r[] = {
GIT_STATUS_WT_NEW, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED,
GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED,
GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED,
};
static const char *paths_nr[] = {
".gitignore",
"dir/a/ignore_me",
"dir/b/ignore_me",
"dir/ignore_me",
"ignore_also/",
"ignore_me",
"test/ignore_me/",
};
static const unsigned int statuses_nr[] = {
GIT_STATUS_WT_NEW,
GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED,
GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED,
};
make_test_data(test_repo_1, test_files_1);
cl_git_rewritefile("empty_standard_repo/.gitignore", "ignore_me\n/ignore_also\n");
memset(&counts, 0x0, sizeof(status_entry_counts));
counts.expected_entry_count = 9;
counts.expected_paths = paths_r;
counts.expected_statuses = statuses_r;
opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_RECURSE_IGNORED_DIRS;
cl_git_pass(git_status_foreach_ext(
g_repo, &opts, cb_status__normal, &counts));
cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
cl_assert_equal_i(0, counts.wrong_status_flags_count);
cl_assert_equal_i(0, counts.wrong_sorted_path);
memset(&counts, 0x0, sizeof(status_entry_counts));
counts.expected_entry_count = 7;
counts.expected_paths = paths_nr;
counts.expected_statuses = statuses_nr;
opts.flags = GIT_STATUS_OPT_DEFAULTS;
cl_git_pass(git_status_foreach_ext(
g_repo, &opts, cb_status__normal, &counts));
cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
cl_assert_equal_i(0, counts.wrong_status_flags_count);
cl_assert_equal_i(0, counts.wrong_sorted_path);
}
void test_ignore_status__subdirectories_not_at_root(void)
{
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
status_entry_counts counts;
static const char *paths_1[] = {
"dir/.gitignore",
"dir/a/ignore_me",
"dir/b/ignore_me",
"dir/ignore_me",
"ignore_also/file",
"ignore_me",
"test/.gitignore",
"test/ignore_me/and_me/file",
"test/ignore_me/file",
"test/ignore_me/file2",
};
static const unsigned int statuses_1[] = {
GIT_STATUS_WT_NEW, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED,
GIT_STATUS_IGNORED, GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW,
GIT_STATUS_WT_NEW, GIT_STATUS_IGNORED, GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW,
};
make_test_data(test_repo_1, test_files_1);
cl_git_rewritefile("empty_standard_repo/dir/.gitignore", "ignore_me\n/ignore_also\n");
cl_git_rewritefile("empty_standard_repo/test/.gitignore", "and_me\n");
memset(&counts, 0x0, sizeof(status_entry_counts));
counts.expected_entry_count = 10;
counts.expected_paths = paths_1;
counts.expected_statuses = statuses_1;
opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_RECURSE_IGNORED_DIRS;
cl_git_pass(git_status_foreach_ext(
g_repo, &opts, cb_status__normal, &counts));
cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
cl_assert_equal_i(0, counts.wrong_status_flags_count);
cl_assert_equal_i(0, counts.wrong_sorted_path);
}
void test_ignore_status__leading_slash_ignores(void)
{
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
status_entry_counts counts;
static const char *paths_2[] = {
"dir/.gitignore",
"dir/a/ignore_me",
"dir/b/ignore_me",
"dir/ignore_me",
"ignore_also/file",
"ignore_me",
"test/.gitignore",
"test/ignore_me/and_me/file",
"test/ignore_me/file",
"test/ignore_me/file2",
};
static const unsigned int statuses_2[] = {
GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW,
GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED,
GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW,
};
make_test_data(test_repo_1, test_files_1);
cl_fake_home();
cl_git_mkfile("home/.gitignore", "/ignore_me\n");
{
git_config *cfg;
cl_git_pass(git_repository_config(&cfg, g_repo));
cl_git_pass(git_config_set_string(
cfg, "core.excludesfile", "~/.gitignore"));
git_config_free(cfg);
}
cl_git_rewritefile("empty_standard_repo/.git/info/exclude", "/ignore_also\n");
cl_git_rewritefile("empty_standard_repo/dir/.gitignore", "/ignore_me\n");
cl_git_rewritefile("empty_standard_repo/test/.gitignore", "/and_me\n");
memset(&counts, 0x0, sizeof(status_entry_counts));
counts.expected_entry_count = 10;
counts.expected_paths = paths_2;
counts.expected_statuses = statuses_2;
opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_RECURSE_IGNORED_DIRS;
cl_git_pass(git_status_foreach_ext(
g_repo, &opts, cb_status__normal, &counts));
cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
cl_assert_equal_i(0, counts.wrong_status_flags_count);
cl_assert_equal_i(0, counts.wrong_sorted_path);
}
void test_ignore_status__multiple_leading_slash(void)
{
static const char *test_files[] = {
"empty_standard_repo/a.test",
"empty_standard_repo/b.test",
"empty_standard_repo/c.test",
"empty_standard_repo/d.test",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/.gitignore",
"a.test\n"
"/b.test\n"
"//c.test\n"
"///d.test\n");
assert_is_ignored("a.test");
assert_is_ignored("b.test");
refute_is_ignored("c.test");
refute_is_ignored("d.test");
}
void test_ignore_status__contained_dir_with_matching_name(void)
{
static const char *test_files[] = {
"empty_standard_repo/subdir_match/aaa/subdir_match/file",
"empty_standard_repo/subdir_match/zzz_ignoreme",
NULL
};
static const char *expected_paths[] = {
"subdir_match/.gitignore",
"subdir_match/aaa/subdir_match/file",
"subdir_match/zzz_ignoreme",
};
static const unsigned int expected_statuses[] = {
GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW, GIT_STATUS_IGNORED
};
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
status_entry_counts counts;
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/subdir_match/.gitignore", "*_ignoreme\n");
refute_is_ignored("subdir_match/aaa/subdir_match/file");
assert_is_ignored("subdir_match/zzz_ignoreme");
memset(&counts, 0x0, sizeof(status_entry_counts));
counts.expected_entry_count = 3;
counts.expected_paths = expected_paths;
counts.expected_statuses = expected_statuses;
opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_RECURSE_IGNORED_DIRS;
cl_git_pass(git_status_foreach_ext(
g_repo, &opts, cb_status__normal, &counts));
cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
cl_assert_equal_i(0, counts.wrong_status_flags_count);
cl_assert_equal_i(0, counts.wrong_sorted_path);
}
void test_ignore_status__trailing_slash_star(void)
{
static const char *test_files[] = {
"empty_standard_repo/file",
"empty_standard_repo/subdir/file",
"empty_standard_repo/subdir/sub2/sub3/file",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/subdir/.gitignore", "/**/*\n");
refute_is_ignored("file");
assert_is_ignored("subdir/sub2/sub3/file");
assert_is_ignored("subdir/file");
}
void test_ignore_status__adding_internal_ignores(void)
{
g_repo = cl_git_sandbox_init("empty_standard_repo");
refute_is_ignored("one.txt");
refute_is_ignored("two.bar");
cl_git_pass(git_ignore_add_rule(g_repo, "*.nomatch\n"));
refute_is_ignored("one.txt");
refute_is_ignored("two.bar");
cl_git_pass(git_ignore_add_rule(g_repo, "*.txt\n"));
assert_is_ignored("one.txt");
refute_is_ignored("two.bar");
cl_git_pass(git_ignore_add_rule(g_repo, "*.bar\n"));
assert_is_ignored("one.txt");
assert_is_ignored("two.bar");
cl_git_pass(git_ignore_clear_internal_rules(g_repo));
refute_is_ignored("one.txt");
refute_is_ignored("two.bar");
cl_git_pass(git_ignore_add_rule(
g_repo, "multiple\n*.rules\n# comment line\n*.bar\n"));
refute_is_ignored("one.txt");
assert_is_ignored("two.bar");
}
void test_ignore_status__add_internal_as_first_thing(void)
{
const char *add_me = "\n#################\n## Eclipse\n#################\n\n*.pydevproject\n.project\n.metadata\nbin/\ntmp/\n*.tmp\n\n";
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_pass(git_ignore_add_rule(g_repo, add_me));
assert_is_ignored("one.tmp");
refute_is_ignored("two.bar");
}
void test_ignore_status__internal_ignores_inside_deep_paths(void)
{
const char *add_me = "Debug\nthis/is/deep\npatterned*/dir\n";
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_pass(git_ignore_add_rule(g_repo, add_me));
assert_is_ignored("Debug");
assert_is_ignored("and/Debug");
assert_is_ignored("really/Debug/this/file");
assert_is_ignored("Debug/what/I/say");
refute_is_ignored("and/NoDebug");
refute_is_ignored("NoDebug/this");
refute_is_ignored("please/NoDebug/this");
assert_is_ignored("this/is/deep");
/* pattern containing slash gets FNM_PATHNAME so all slashes must match */
refute_is_ignored("and/this/is/deep");
assert_is_ignored("this/is/deep/too");
/* pattern containing slash gets FNM_PATHNAME so all slashes must match */
refute_is_ignored("but/this/is/deep/and/ignored");
refute_is_ignored("this/is/not/deep");
refute_is_ignored("is/this/not/as/deep");
refute_is_ignored("this/is/deepish");
refute_is_ignored("xthis/is/deep");
}
void test_ignore_status__automatically_ignore_bad_files(void)
{
g_repo = cl_git_sandbox_init("empty_standard_repo");
assert_is_ignored(".git");
assert_is_ignored("this/file/.");
assert_is_ignored("path/../funky");
refute_is_ignored("path/whatever.c");
cl_git_pass(git_ignore_add_rule(g_repo, "*.c\n"));
assert_is_ignored(".git");
assert_is_ignored("this/file/.");
assert_is_ignored("path/../funky");
assert_is_ignored("path/whatever.c");
cl_git_pass(git_ignore_clear_internal_rules(g_repo));
assert_is_ignored(".git");
assert_is_ignored("this/file/.");
assert_is_ignored("path/../funky");
refute_is_ignored("path/whatever.c");
}
void test_ignore_status__filenames_with_special_prefixes_do_not_interfere_with_status_retrieval(void)
{
status_entry_single st;
char *test_cases[] = {
"!file",
"#blah",
"[blah]",
"[attr]",
"[attr]blah",
NULL
};
int i;
for (i = 0; *(test_cases + i) != NULL; i++) {
git_buf file = GIT_BUF_INIT;
char *file_name = *(test_cases + i);
git_repository *repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_pass(git_buf_joinpath(&file, "empty_standard_repo", file_name));
cl_git_mkfile(git_buf_cstr(&file), "Please don't ignore me!");
memset(&st, 0, sizeof(st));
cl_git_pass(git_status_foreach(repo, cb_status__single, &st));
cl_assert(st.count == 1);
cl_assert(st.status == GIT_STATUS_WT_NEW);
cl_git_pass(git_status_file(&st.status, repo, file_name));
cl_assert(st.status == GIT_STATUS_WT_NEW);
cl_git_sandbox_cleanup();
git_buf_dispose(&file);
}
}
void test_ignore_status__issue_1766_negated_ignores(void)
{
unsigned int status;
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_pass(git_futils_mkdir_r(
"empty_standard_repo/a", 0775));
cl_git_mkfile(
"empty_standard_repo/a/.gitignore", "*\n!.gitignore\n");
cl_git_mkfile(
"empty_standard_repo/a/ignoreme", "I should be ignored\n");
refute_is_ignored("a/.gitignore");
assert_is_ignored("a/ignoreme");
cl_git_pass(git_futils_mkdir_r(
"empty_standard_repo/b", 0775));
cl_git_mkfile(
"empty_standard_repo/b/.gitignore", "*\n!.gitignore\n");
cl_git_mkfile(
"empty_standard_repo/b/ignoreme", "I should be ignored\n");
refute_is_ignored("b/.gitignore");
assert_is_ignored("b/ignoreme");
/* shouldn't have changed results from first couple either */
refute_is_ignored("a/.gitignore");
assert_is_ignored("a/ignoreme");
/* status should find the two ignore files and nothing else */
cl_git_pass(git_status_file(&status, g_repo, "a/.gitignore"));
cl_assert_equal_i(GIT_STATUS_WT_NEW, (int)status);
cl_git_pass(git_status_file(&status, g_repo, "a/ignoreme"));
cl_assert_equal_i(GIT_STATUS_IGNORED, (int)status);
cl_git_pass(git_status_file(&status, g_repo, "b/.gitignore"));
cl_assert_equal_i(GIT_STATUS_WT_NEW, (int)status);
cl_git_pass(git_status_file(&status, g_repo, "b/ignoreme"));
cl_assert_equal_i(GIT_STATUS_IGNORED, (int)status);
{
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
status_entry_counts counts;
static const char *paths[] = {
"a/.gitignore",
"a/ignoreme",
"b/.gitignore",
"b/ignoreme",
};
static const unsigned int statuses[] = {
GIT_STATUS_WT_NEW,
GIT_STATUS_IGNORED,
GIT_STATUS_WT_NEW,
GIT_STATUS_IGNORED,
};
memset(&counts, 0x0, sizeof(status_entry_counts));
counts.expected_entry_count = 4;
counts.expected_paths = paths;
counts.expected_statuses = statuses;
opts.flags = GIT_STATUS_OPT_DEFAULTS;
cl_git_pass(git_status_foreach_ext(
g_repo, &opts, cb_status__normal, &counts));
cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
cl_assert_equal_i(0, counts.wrong_status_flags_count);
cl_assert_equal_i(0, counts.wrong_sorted_path);
}
}
static void add_one_to_index(const char *file)
{
git_index *index;
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_index_add_bypath(index, file));
git_index_free(index);
}
/* Some further broken scenarios that have been reported */
void test_ignore_status__more_breakage(void)
{
static const char *test_files[] = {
"empty_standard_repo/d1/pfx-d2/d3/d4/d5/tracked",
"empty_standard_repo/d1/pfx-d2/d3/d4/d5/untracked",
"empty_standard_repo/d1/pfx-d2/d3/d4/untracked",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/.gitignore",
"/d1/pfx-*\n"
"!/d1/pfx-d2/\n"
"/d1/pfx-d2/*\n"
"!/d1/pfx-d2/d3/\n"
"/d1/pfx-d2/d3/*\n"
"!/d1/pfx-d2/d3/d4/\n");
add_one_to_index("d1/pfx-d2/d3/d4/d5/tracked");
{
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
status_entry_counts counts;
static const char *files[] = {
".gitignore",
"d1/pfx-d2/d3/d4/d5/tracked",
"d1/pfx-d2/d3/d4/d5/untracked",
"d1/pfx-d2/d3/d4/untracked",
};
static const unsigned int statuses[] = {
GIT_STATUS_WT_NEW,
GIT_STATUS_INDEX_NEW,
GIT_STATUS_WT_NEW,
GIT_STATUS_WT_NEW,
};
memset(&counts, 0x0, sizeof(status_entry_counts));
counts.expected_entry_count = 4;
counts.expected_paths = files;
counts.expected_statuses = statuses;
opts.flags = GIT_STATUS_OPT_DEFAULTS |
GIT_STATUS_OPT_INCLUDE_IGNORED |
GIT_STATUS_OPT_RECURSE_IGNORED_DIRS;
cl_git_pass(git_status_foreach_ext(
g_repo, &opts, cb_status__normal, &counts));
cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
cl_assert_equal_i(0, counts.wrong_status_flags_count);
cl_assert_equal_i(0, counts.wrong_sorted_path);
}
refute_is_ignored("d1/pfx-d2/d3/d4/d5/tracked");
refute_is_ignored("d1/pfx-d2/d3/d4/d5/untracked");
refute_is_ignored("d1/pfx-d2/d3/d4/untracked");
}
void test_ignore_status__negative_ignores_inside_ignores(void)
{
static const char *test_files[] = {
"empty_standard_repo/top/mid/btm/tracked",
"empty_standard_repo/top/mid/btm/untracked",
"empty_standard_repo/zoo/bar",
"empty_standard_repo/zoo/foo/bar",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/.gitignore",
"top\n"
"!top/mid/btm\n"
"zoo/*\n"
"!zoo/bar\n"
"!zoo/foo/bar\n");
add_one_to_index("top/mid/btm/tracked");
{
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
status_entry_counts counts;
static const char *files[] = {
".gitignore", "top/mid/btm/tracked", "top/mid/btm/untracked",
"zoo/bar", "zoo/foo/bar",
};
static const unsigned int statuses[] = {
GIT_STATUS_WT_NEW, GIT_STATUS_INDEX_NEW, GIT_STATUS_IGNORED,
GIT_STATUS_WT_NEW, GIT_STATUS_IGNORED,
};
memset(&counts, 0x0, sizeof(status_entry_counts));
counts.expected_entry_count = 5;
counts.expected_paths = files;
counts.expected_statuses = statuses;
opts.flags = GIT_STATUS_OPT_DEFAULTS |
GIT_STATUS_OPT_INCLUDE_IGNORED |
GIT_STATUS_OPT_RECURSE_IGNORED_DIRS;
cl_git_pass(git_status_foreach_ext(
g_repo, &opts, cb_status__normal, &counts));
cl_assert_equal_i(counts.expected_entry_count, counts.entry_count);
cl_assert_equal_i(0, counts.wrong_status_flags_count);
cl_assert_equal_i(0, counts.wrong_sorted_path);
}
assert_is_ignored("top/mid/btm/tracked");
assert_is_ignored("top/mid/btm/untracked");
refute_is_ignored("foo/bar");
}
void test_ignore_status__negative_ignores_in_slash_star(void)
{
git_status_options status_opts = GIT_STATUS_OPTIONS_INIT;
git_status_list *list;
int found_look_ma = 0, found_what_about = 0;
size_t i;
static const char *test_files[] = {
"empty_standard_repo/bin/look-ma.txt",
"empty_standard_repo/bin/what-about-me.txt",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/.gitignore",
"bin/*\n"
"!bin/w*\n");
assert_is_ignored("bin/look-ma.txt");
refute_is_ignored("bin/what-about-me.txt");
status_opts.flags = GIT_STATUS_OPT_DEFAULTS;
cl_git_pass(git_status_list_new(&list, g_repo, &status_opts));
for (i = 0; i < git_status_list_entrycount(list); i++) {
const git_status_entry *entry = git_status_byindex(list, i);
if (!strcmp("bin/look-ma.txt", entry->index_to_workdir->new_file.path))
found_look_ma = 1;
if (!strcmp("bin/what-about-me.txt", entry->index_to_workdir->new_file.path))
found_what_about = 1;
}
git_status_list_free(list);
cl_assert(found_look_ma);
cl_assert(found_what_about);
}
void test_ignore_status__negative_ignores_without_trailing_slash_inside_ignores(void)
{
git_status_options status_opts = GIT_STATUS_OPTIONS_INIT;
git_status_list *list;
int found_parent_file = 0, found_parent_child1_file = 0, found_parent_child2_file = 0;
size_t i;
static const char *test_files[] = {
"empty_standard_repo/parent/file.txt",
"empty_standard_repo/parent/force.txt",
"empty_standard_repo/parent/child1/file.txt",
"empty_standard_repo/parent/child2/file.txt",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/.gitignore",
"parent/*\n"
"!parent/force.txt\n"
"!parent/child1\n"
"!parent/child2/\n");
add_one_to_index("parent/force.txt");
assert_is_ignored("parent/file.txt");
refute_is_ignored("parent/force.txt");
refute_is_ignored("parent/child1/file.txt");
refute_is_ignored("parent/child2/file.txt");
status_opts.flags = GIT_STATUS_OPT_DEFAULTS;
cl_git_pass(git_status_list_new(&list, g_repo, &status_opts));
for (i = 0; i < git_status_list_entrycount(list); i++) {
const git_status_entry *entry = git_status_byindex(list, i);
if (!entry->index_to_workdir)
continue;
if (!strcmp("parent/file.txt", entry->index_to_workdir->new_file.path))
found_parent_file = 1;
if (!strcmp("parent/force.txt", entry->index_to_workdir->new_file.path))
found_parent_file = 1;
if (!strcmp("parent/child1/file.txt", entry->index_to_workdir->new_file.path))
found_parent_child1_file = 1;
if (!strcmp("parent/child2/file.txt", entry->index_to_workdir->new_file.path))
found_parent_child2_file = 1;
}
git_status_list_free(list);
cl_assert(found_parent_file);
cl_assert(found_parent_child1_file);
cl_assert(found_parent_child2_file);
}
void test_ignore_status__negative_directory_ignores(void)
{
static const char *test_files[] = {
"empty_standard_repo/parent/child1/bar.txt",
"empty_standard_repo/parent/child2/bar.txt",
"empty_standard_repo/parent/child3/foo.txt",
"empty_standard_repo/parent/child4/bar.txt",
"empty_standard_repo/parent/nested/child5/bar.txt",
"empty_standard_repo/parent/nested/child6/bar.txt",
"empty_standard_repo/parent/nested/child7/bar.txt",
"empty_standard_repo/padded_parent/child8/bar.txt",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/.gitignore",
"foo.txt\n"
"parent/child1\n"
"parent/child2\n"
"parent/child4\n"
"parent/nested/child5\n"
"nested/child6\n"
"nested/child7\n"
"padded_parent/child8\n"
/* test simple exact match */
"!parent/child1\n"
/* test negating file without negating dir */
"!parent/child2/bar.txt\n"
/* test negative pattern on dir with its content
* being ignored */
"!parent/child3\n"
/* test with partial match at end */
"!child4\n"
/* test with partial match with '/' at end */
"!nested/child5\n"
/* test with complete match */
"!nested/child6\n"
/* test with trailing '/' */
"!child7/\n"
/* test with partial dir match */
"!_parent/child8\n");
refute_is_ignored("parent/child1/bar.txt");
assert_is_ignored("parent/child2/bar.txt");
assert_is_ignored("parent/child3/foo.txt");
refute_is_ignored("parent/child4/bar.txt");
assert_is_ignored("parent/nested/child5/bar.txt");
refute_is_ignored("parent/nested/child6/bar.txt");
refute_is_ignored("parent/nested/child7/bar.txt");
assert_is_ignored("padded_parent/child8/bar.txt");
}
void test_ignore_status__unignore_entry_in_ignored_dir(void)
{
static const char *test_files[] = {
"empty_standard_repo/bar.txt",
"empty_standard_repo/parent/bar.txt",
"empty_standard_repo/parent/child/bar.txt",
"empty_standard_repo/nested/parent/child/bar.txt",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/.gitignore",
"bar.txt\n"
"!parent/child/bar.txt\n");
assert_is_ignored("bar.txt");
assert_is_ignored("parent/bar.txt");
refute_is_ignored("parent/child/bar.txt");
assert_is_ignored("nested/parent/child/bar.txt");
}
void test_ignore_status__do_not_unignore_basename_prefix(void)
{
static const char *test_files[] = {
"empty_standard_repo/foo_bar.txt",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/.gitignore",
"foo_bar.txt\n"
"!bar.txt\n");
assert_is_ignored("foo_bar.txt");
}
void test_ignore_status__filename_with_cr(void)
{
int ignored;
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_mkfile("empty_standard_repo/.gitignore", "Icon\r\r\n");
cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "Icon\r"));
cl_assert_equal_i(1, ignored);
cl_git_mkfile("empty_standard_repo/.gitignore", "Ico\rn\n");
cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "Ico\rn"));
cl_assert_equal_i(1, ignored);
cl_git_mkfile("empty_standard_repo/.gitignore", "Ico\rn\r\n");
cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "Ico\rn"));
cl_assert_equal_i(1, ignored);
cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "Ico\rn\r"));
cl_assert_equal_i(0, ignored);
cl_git_mkfile("empty_standard_repo/.gitignore", "Ico\rn\r\r\n");
cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "Ico\rn\r"));
cl_assert_equal_i(1, ignored);
cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "Icon\r"));
cl_assert_equal_i(0, ignored);
cl_git_mkfile("empty_standard_repo/.gitignore", "Icon\r\n");
cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "Icon\r"));
cl_assert_equal_i(0, ignored);
cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "Icon"));
cl_assert_equal_i(1, ignored);
}
void test_ignore_status__subdir_doesnt_match_above(void)
{
int ignored, icase = 0, error;
git_config *cfg;
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_pass(git_repository_config_snapshot(&cfg, g_repo));
error = git_config_get_bool(&icase, cfg, "core.ignorecase");
git_config_free(cfg);
if (error == GIT_ENOTFOUND)
error = 0;
cl_git_pass(error);
cl_git_pass(p_mkdir("empty_standard_repo/src", 0777));
cl_git_pass(p_mkdir("empty_standard_repo/src/src", 0777));
cl_git_mkfile("empty_standard_repo/src/.gitignore", "src\n");
cl_git_mkfile("empty_standard_repo/.gitignore", "");
cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "src/test.txt"));
cl_assert_equal_i(0, ignored);
cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "src/src/test.txt"));
cl_assert_equal_i(1, ignored);
cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "src/foo/test.txt"));
cl_assert_equal_i(0, ignored);
cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "SRC/src/test.txt"));
cl_assert_equal_i(icase, ignored);
cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "src/SRC/test.txt"));
cl_assert_equal_i(icase, ignored);
}
void test_ignore_status__negate_exact_previous(void)
{
int ignored;
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_mkfile("empty_standard_repo/.gitignore", "*.com\ntags\n!tags/\n.buildpath");
cl_git_mkfile("empty_standard_repo/.buildpath", "");
cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, ".buildpath"));
cl_assert_equal_i(1, ignored);
}
void test_ignore_status__negate_starstar(void)
{
int ignored;
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_mkfile("empty_standard_repo/.gitignore",
"code/projects/**/packages/*\n"
"!code/projects/**/packages/repositories.config");
cl_git_pass(git_futils_mkdir_r("empty_standard_repo/code/projects/foo/bar/packages", 0777));
cl_git_mkfile("empty_standard_repo/code/projects/foo/bar/packages/repositories.config", "");
cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "code/projects/foo/bar/packages/repositories.config"));
cl_assert_equal_i(0, ignored);
}
void test_ignore_status__ignore_all_toplevel_dirs_include_files(void)
{
static const char *test_files[] = {
"empty_standard_repo/README.md",
"empty_standard_repo/src/main.c",
"empty_standard_repo/src/foo/foo.c",
"empty_standard_repo/dist/foo.o",
"empty_standard_repo/dist/main.o",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/.gitignore",
"/*/\n"
"!/src\n");
assert_is_ignored("dist/foo.o");
assert_is_ignored("dist/main.o");
refute_is_ignored("README.md");
refute_is_ignored("src/foo.c");
refute_is_ignored("src/foo/foo.c");
}
void test_ignore_status__subdir_ignore_all_toplevel_dirs_include_files(void)
{
static const char *test_files[] = {
"empty_standard_repo/project/README.md",
"empty_standard_repo/project/src/main.c",
"empty_standard_repo/project/src/foo/foo.c",
"empty_standard_repo/project/dist/foo.o",
"empty_standard_repo/project/dist/main.o",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/project/.gitignore",
"/*/\n"
"!/src\n");
assert_is_ignored("project/dist/foo.o");
assert_is_ignored("project/dist/main.o");
refute_is_ignored("project/src/foo.c");
refute_is_ignored("project/src/foo/foo.c");
refute_is_ignored("project/README.md");
}
void test_ignore_status__subdir_ignore_everything_except_certain_files(void)
{
static const char *test_files[] = {
"empty_standard_repo/project/README.md",
"empty_standard_repo/project/some_file",
"empty_standard_repo/project/src/main.c",
"empty_standard_repo/project/src/foo/foo.c",
"empty_standard_repo/project/dist/foo.o",
"empty_standard_repo/project/dist/main.o",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/project/.gitignore",
"/*\n"
"!/src\n"
"!README.md\n");
assert_is_ignored("project/some_file");
assert_is_ignored("project/dist/foo.o");
assert_is_ignored("project/dist/main.o");
refute_is_ignored("project/README.md");
refute_is_ignored("project/src/foo.c");
refute_is_ignored("project/src/foo/foo.c");
}
void test_ignore_status__deeper(void)
{
const char *test_files[] = {
"empty_standard_repo/foo.data",
"empty_standard_repo/bar.data",
"empty_standard_repo/dont_ignore/foo.data",
"empty_standard_repo/dont_ignore/bar.data",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile("empty_standard_repo/.gitignore",
"*.data\n"
"!dont_ignore/*.data\n");
assert_is_ignored("foo.data");
assert_is_ignored("bar.data");
refute_is_ignored("dont_ignore/foo.data");
refute_is_ignored("dont_ignore/bar.data");
}
void test_ignore_status__unignored_dir_with_ignored_contents(void)
{
static const char *test_files[] = {
"empty_standard_repo/dir/a.test",
"empty_standard_repo/dir/subdir/a.test",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/.gitignore",
"*.test\n"
"!dir/*\n");
refute_is_ignored("dir/a.test");
assert_is_ignored("dir/subdir/a.test");
}
void test_ignore_status__unignored_subdirs(void)
{
static const char *test_files[] = {
"empty_standard_repo/dir/a.test",
"empty_standard_repo/dir/subdir/a.test",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/.gitignore",
"dir/*\n"
"!dir/*/\n");
assert_is_ignored("dir/a.test");
refute_is_ignored("dir/subdir/a.test");
}
void test_ignore_status__skips_bom(void)
{
static const char *test_files[] = {
"empty_standard_repo/a.test",
"empty_standard_repo/b.test",
"empty_standard_repo/c.test",
"empty_standard_repo/foo.txt",
"empty_standard_repo/bar.txt",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/.gitignore",
"\xEF\xBB\xBF*.test\n");
assert_is_ignored("a.test");
assert_is_ignored("b.test");
assert_is_ignored("c.test");
refute_is_ignored("foo.txt");
refute_is_ignored("bar.txt");
}
void test_ignore_status__leading_spaces_are_significant(void)
{
static const char *test_files[] = {
"empty_standard_repo/a.test",
"empty_standard_repo/b.test",
"empty_standard_repo/c.test",
"empty_standard_repo/d.test",
NULL
};
make_test_data("empty_standard_repo", test_files);
cl_git_mkfile(
"empty_standard_repo/.gitignore",
" a.test\n"
"# this is a comment\n"
"b.test\n"
"\tc.test\n"
" # not a comment\n"
"d.test\n");
refute_is_ignored("a.test");
assert_is_ignored(" a.test");
refute_is_ignored("# this is a comment");
assert_is_ignored("b.test");
refute_is_ignored("c.test");
assert_is_ignored("\tc.test");
assert_is_ignored(" # not a comment");
assert_is_ignored("d.test");
}
void test_ignore_status__override_nested_wildcard_unignore(void)
{
git_repository *repo = cl_git_sandbox_init("empty_standard_repo");
git_status_list *statuslist;
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
const git_status_entry *status;
cl_git_pass(git_futils_mkdir_r("empty_standard_repo/dir", 0777));
cl_git_pass(git_futils_mkdir_r("empty_standard_repo/dir/subdir", 0777));
cl_git_mkfile("empty_standard_repo/.gitignore", "a.test\n");
cl_git_mkfile("empty_standard_repo/dir/.gitignore", "!*.test\n");
cl_git_mkfile("empty_standard_repo/dir/subdir/.gitignore", "a.test\n");
cl_git_mkfile("empty_standard_repo/dir/a.test", "pong");
cl_git_mkfile("empty_standard_repo/dir/subdir/a.test", "pong");
opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
cl_git_pass(git_status_list_new(&statuslist, repo, &opts));
cl_assert_equal_sz(4, git_status_list_entrycount(statuslist));
status = git_status_byindex(statuslist, 0);
cl_assert(status != NULL);
cl_assert_equal_s(".gitignore", status->index_to_workdir->old_file.path);
cl_assert_equal_i(GIT_STATUS_WT_NEW, status->status);
status = git_status_byindex(statuslist, 1);
cl_assert(status != NULL);
cl_assert_equal_s("dir/.gitignore", status->index_to_workdir->old_file.path);
cl_assert_equal_i(GIT_STATUS_WT_NEW, status->status);
status = git_status_byindex(statuslist, 2);
cl_assert(status != NULL);
cl_assert_equal_s("dir/a.test", status->index_to_workdir->old_file.path);
cl_assert_equal_i(GIT_STATUS_WT_NEW, status->status);
status = git_status_byindex(statuslist, 3);
cl_assert(status != NULL);
cl_assert_equal_s("dir/subdir/.gitignore", status->index_to_workdir->old_file.path);
cl_assert_equal_i(GIT_STATUS_WT_NEW, status->status);
git_status_list_free(statuslist);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/email/create.c
|
#include "clar.h"
#include "clar_libgit2.h"
#include "buffer.h"
#include "diff_generate.h"
static git_repository *repo;
void test_email_create__initialize(void)
{
repo = cl_git_sandbox_init("diff_format_email");
}
void test_email_create__cleanup(void)
{
cl_git_sandbox_cleanup();
}
static void email_for_commit(
git_buf *out,
const char *commit_id,
git_email_create_options *opts)
{
git_oid oid;
git_commit *commit = NULL;
git_diff *diff = NULL;
git_oid_fromstr(&oid, commit_id);
cl_git_pass(git_commit_lookup(&commit, repo, &oid));
cl_git_pass(git_email_create_from_commit(out, commit, opts));
git_diff_free(diff);
git_commit_free(commit);
}
static void assert_email_match(
const char *expected,
const char *commit_id,
git_email_create_options *opts)
{
git_buf buf = GIT_BUF_INIT;
email_for_commit(&buf, commit_id, opts);
cl_assert_equal_s(expected, git_buf_cstr(&buf));
git_buf_dispose(&buf);
}
static void assert_subject_match(
const char *expected,
const char *commit_id,
git_email_create_options *opts)
{
git_buf buf = GIT_BUF_INIT;
const char *loc;
email_for_commit(&buf, commit_id, opts);
cl_assert((loc = strstr(buf.ptr, "\nSubject: ")) != NULL);
git_buf_consume(&buf, (loc + 10));
git_buf_truncate_at_char(&buf, '\n');
cl_assert_equal_s(expected, git_buf_cstr(&buf));
git_buf_dispose(&buf);
}
void test_email_create__commit(void)
{
const char *expected =
"From 9264b96c6d104d0e07ae33d3007b6a48246c6f92 Mon Sep 17 00:00:00 2001\n" \
"From: Jacques Germishuys <[email protected]>\n" \
"Date: Wed, 9 Apr 2014 20:57:01 +0200\n" \
"Subject: [PATCH] Modify some content\n" \
"\n" \
"---\n" \
" file1.txt | 8 +++++---\n" \
" 1 file changed, 5 insertions(+), 3 deletions(-)\n" \
"\n" \
"diff --git a/file1.txt b/file1.txt\n" \
"index 94aaae8..af8f41d 100644\n" \
"--- a/file1.txt\n" \
"+++ b/file1.txt\n" \
"@@ -1,15 +1,17 @@\n" \
" file1.txt\n" \
" file1.txt\n" \
"+_file1.txt_\n" \
" file1.txt\n" \
" file1.txt\n" \
" file1.txt\n" \
" file1.txt\n" \
"+\n" \
"+\n" \
" file1.txt\n" \
" file1.txt\n" \
" file1.txt\n" \
" file1.txt\n" \
" file1.txt\n" \
"-file1.txt\n" \
"-file1.txt\n" \
"-file1.txt\n" \
"+_file1.txt_\n" \
"+_file1.txt_\n" \
" file1.txt\n" \
"--\n" \
"libgit2 " LIBGIT2_VERSION "\n" \
"\n";
assert_email_match(
expected, "9264b96c6d104d0e07ae33d3007b6a48246c6f92", NULL);
}
void test_email_create__rename(void)
{
const char *expected =
"From 6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d Mon Sep 17 00:00:00 2001\n" \
"From: Jacques Germishuys <[email protected]>\n" \
"Date: Wed, 9 Apr 2014 21:15:56 +0200\n" \
"Subject: [PATCH] Renamed file1.txt -> file1.txt.renamed\n" \
"\n" \
"---\n" \
" file1.txt => file1.txt.renamed | 4 ++--\n" \
" 1 file changed, 2 insertions(+), 2 deletions(-)\n" \
"\n" \
"diff --git a/file1.txt b/file1.txt.renamed\n" \
"similarity index 86%\n" \
"rename from file1.txt\n" \
"rename to file1.txt.renamed\n" \
"index af8f41d..a97157a 100644\n" \
"--- a/file1.txt\n" \
"+++ b/file1.txt.renamed\n" \
"@@ -3,13 +3,13 @@ file1.txt\n" \
" _file1.txt_\n" \
" file1.txt\n" \
" file1.txt\n" \
"-file1.txt\n" \
"+file1.txt_renamed\n" \
" file1.txt\n" \
" \n" \
" \n" \
" file1.txt\n" \
" file1.txt\n" \
"-file1.txt\n" \
"+file1.txt_renamed\n" \
" file1.txt\n" \
" file1.txt\n" \
" _file1.txt_\n" \
"--\n" \
"libgit2 " LIBGIT2_VERSION "\n" \
"\n";
assert_email_match(expected, "6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d", NULL);
}
void test_email_create__rename_as_add_delete(void)
{
const char *expected =
"From 6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d Mon Sep 17 00:00:00 2001\n" \
"From: Jacques Germishuys <[email protected]>\n" \
"Date: Wed, 9 Apr 2014 21:15:56 +0200\n" \
"Subject: [PATCH] Renamed file1.txt -> file1.txt.renamed\n" \
"\n" \
"---\n" \
" file1.txt | 17 -----------------\n" \
" file1.txt.renamed | 17 +++++++++++++++++\n" \
" 2 files changed, 17 insertions(+), 17 deletions(-)\n" \
" delete mode 100644 file1.txt\n" \
" create mode 100644 file1.txt.renamed\n" \
"\n" \
"diff --git a/file1.txt b/file1.txt\n" \
"deleted file mode 100644\n" \
"index af8f41d..0000000\n" \
"--- a/file1.txt\n" \
"+++ /dev/null\n" \
"@@ -1,17 +0,0 @@\n" \
"-file1.txt\n" \
"-file1.txt\n" \
"-_file1.txt_\n" \
"-file1.txt\n" \
"-file1.txt\n" \
"-file1.txt\n" \
"-file1.txt\n" \
"-\n" \
"-\n" \
"-file1.txt\n" \
"-file1.txt\n" \
"-file1.txt\n" \
"-file1.txt\n" \
"-file1.txt\n" \
"-_file1.txt_\n" \
"-_file1.txt_\n" \
"-file1.txt\n" \
"diff --git a/file1.txt.renamed b/file1.txt.renamed\n" \
"new file mode 100644\n" \
"index 0000000..a97157a\n" \
"--- /dev/null\n" \
"+++ b/file1.txt.renamed\n" \
"@@ -0,0 +1,17 @@\n" \
"+file1.txt\n" \
"+file1.txt\n" \
"+_file1.txt_\n" \
"+file1.txt\n" \
"+file1.txt\n" \
"+file1.txt_renamed\n" \
"+file1.txt\n" \
"+\n" \
"+\n" \
"+file1.txt\n" \
"+file1.txt\n" \
"+file1.txt_renamed\n" \
"+file1.txt\n" \
"+file1.txt\n" \
"+_file1.txt_\n" \
"+_file1.txt_\n" \
"+file1.txt\n" \
"--\n" \
"libgit2 " LIBGIT2_VERSION "\n" \
"\n";
git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT;
opts.flags |= GIT_EMAIL_CREATE_NO_RENAMES;
assert_email_match(expected, "6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d", &opts);
}
void test_email_create__binary(void)
{
const char *expected =
"From 8d7523f6fcb2404257889abe0d96f093d9f524f9 Mon Sep 17 00:00:00 2001\n" \
"From: Jacques Germishuys <[email protected]>\n" \
"Date: Sun, 13 Apr 2014 18:10:18 +0200\n" \
"Subject: [PATCH] Modified binary file\n" \
"\n" \
"---\n" \
" binary.bin | Bin 3 -> 5 bytes\n" \
" 1 file changed, 0 insertions(+), 0 deletions(-)\n" \
"\n" \
"diff --git a/binary.bin b/binary.bin\n" \
"index bd474b2519cc15eab801ff851cc7d50f0dee49a1..9ac35ff15cd8864aeafd889e4826a3150f0b06c4 100644\n" \
"GIT binary patch\n" \
"literal 5\n" \
"Mc${NkU}WL~000&M4gdfE\n" \
"\n" \
"literal 3\n" \
"Kc${Nk-~s>u4FC%O\n" \
"\n" \
"--\n" \
"libgit2 " LIBGIT2_VERSION "\n" \
"\n";
assert_email_match(expected, "8d7523f6fcb2404257889abe0d96f093d9f524f9", NULL);
}
void test_email_create__binary_not_included(void)
{
const char *expected =
"From 8d7523f6fcb2404257889abe0d96f093d9f524f9 Mon Sep 17 00:00:00 2001\n" \
"From: Jacques Germishuys <[email protected]>\n" \
"Date: Sun, 13 Apr 2014 18:10:18 +0200\n" \
"Subject: [PATCH] Modified binary file\n" \
"\n" \
"---\n" \
" binary.bin | Bin 3 -> 5 bytes\n" \
" 1 file changed, 0 insertions(+), 0 deletions(-)\n" \
"\n" \
"diff --git a/binary.bin b/binary.bin\n" \
"index bd474b2..9ac35ff 100644\n" \
"Binary files a/binary.bin and b/binary.bin differ\n" \
"--\n" \
"libgit2 " LIBGIT2_VERSION "\n" \
"\n";
git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT;
opts.diff_opts.flags &= ~GIT_DIFF_SHOW_BINARY;
assert_email_match(expected, "8d7523f6fcb2404257889abe0d96f093d9f524f9", &opts);
}
void test_email_create__custom_summary_and_body(void)
{
const char *expected = "From 627e7e12d87e07a83fad5b6bfa25e86ead4a5270 Mon Sep 17 00:00:00 2001\n" \
"From: Patrick Steinhardt <[email protected]>\n" \
"Date: Tue, 24 Nov 2015 13:34:39 +0100\n" \
"Subject: [PPPPPATCH 2/4] This is a subject\n" \
"\n" \
"Modify content of file3.txt by appending a new line. Make this\n" \
"commit message somewhat longer to test behavior with newlines\n" \
"embedded in the message body.\n" \
"\n" \
"Also test if new paragraphs are included correctly.\n" \
"---\n" \
" file3.txt | 1 +\n" \
" 1 file changed, 1 insertion(+)\n" \
"\n" \
"diff --git a/file3.txt b/file3.txt\n" \
"index 9a2d780..7309653 100644\n" \
"--- a/file3.txt\n" \
"+++ b/file3.txt\n" \
"@@ -3,3 +3,4 @@ file3!\n" \
" file3\n" \
" file3\n" \
" file3\n" \
"+file3\n" \
"--\n" \
"libgit2 " LIBGIT2_VERSION "\n" \
"\n";
const char *summary = "This is a subject\nwith\nnewlines";
const char *body = "Modify content of file3.txt by appending a new line. Make this\n" \
"commit message somewhat longer to test behavior with newlines\n" \
"embedded in the message body.\n" \
"\n" \
"Also test if new paragraphs are included correctly.";
git_oid oid;
git_commit *commit = NULL;
git_diff *diff = NULL;
git_buf buf = GIT_BUF_INIT;
git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT;
opts.subject_prefix = "PPPPPATCH";
git_oid_fromstr(&oid, "627e7e12d87e07a83fad5b6bfa25e86ead4a5270");
cl_git_pass(git_commit_lookup(&commit, repo, &oid));
cl_git_pass(git_diff__commit(&diff, repo, commit, NULL));
cl_git_pass(git_email_create_from_diff(&buf, diff, 2, 4, &oid, summary, body, git_commit_author(commit), &opts));
cl_assert_equal_s(expected, git_buf_cstr(&buf));
git_diff_free(diff);
git_commit_free(commit);
git_buf_dispose(&buf);
}
void test_email_create__commit_subjects(void)
{
git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT;
assert_subject_match("[PATCH] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts);
opts.reroll_number = 42;
assert_subject_match("[PATCH v42] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts);
opts.flags |= GIT_EMAIL_CREATE_ALWAYS_NUMBER;
assert_subject_match("[PATCH v42 1/1] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts);
opts.start_number = 9;
assert_subject_match("[PATCH v42 9/9] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts);
opts.subject_prefix = "";
assert_subject_match("[v42 9/9] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts);
opts.reroll_number = 0;
assert_subject_match("[9/9] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts);
opts.start_number = 0;
assert_subject_match("[1/1] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts);
opts.flags = GIT_EMAIL_CREATE_OMIT_NUMBERS;
assert_subject_match("Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/delta/apply.c
|
#include "clar_libgit2.h"
#include "delta.h"
void test_delta_apply__read_at_off(void)
{
unsigned char base[16] = { 0 }, delta[] = { 0x10, 0x10, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00 };
void *out;
size_t outlen;
cl_git_fail(git_delta_apply(&out, &outlen, base, sizeof(base), delta, sizeof(delta)));
}
void test_delta_apply__read_after_limit(void)
{
unsigned char base[16] = { 0 }, delta[] = { 0x10, 0x70, 0xff };
void *out;
size_t outlen;
cl_git_fail(git_delta_apply(&out, &outlen, base, sizeof(base), delta, sizeof(delta)));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/readonly.c
|
#include "clar_libgit2.h"
#include "config_backend.h"
#include "config.h"
#include "path.h"
static git_config *cfg;
void test_config_readonly__initialize(void)
{
cl_git_pass(git_config_new(&cfg));
}
void test_config_readonly__cleanup(void)
{
git_config_free(cfg);
cfg = NULL;
}
void test_config_readonly__writing_to_readonly_fails(void)
{
git_config_backend *backend;
cl_git_pass(git_config_backend_from_file(&backend, "global"));
backend->readonly = 1;
cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
cl_git_fail_with(GIT_ENOTFOUND, git_config_set_string(cfg, "foo.bar", "baz"));
cl_assert(!git_path_exists("global"));
}
void test_config_readonly__writing_to_cfg_with_rw_precedence_succeeds(void)
{
git_config_backend *backend;
cl_git_pass(git_config_backend_from_file(&backend, "global"));
backend->readonly = 1;
cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
cl_git_pass(git_config_backend_from_file(&backend, "local"));
cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_LOCAL, NULL, 0));
cl_git_pass(git_config_set_string(cfg, "foo.bar", "baz"));
cl_assert(git_path_exists("local"));
cl_assert(!git_path_exists("global"));
cl_git_pass(p_unlink("local"));
}
void test_config_readonly__writing_to_cfg_with_ro_precedence_succeeds(void)
{
git_config_backend *backend;
cl_git_pass(git_config_backend_from_file(&backend, "local"));
backend->readonly = 1;
cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_LOCAL, NULL, 0));
cl_git_pass(git_config_backend_from_file(&backend, "global"));
cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
cl_git_pass(git_config_set_string(cfg, "foo.bar", "baz"));
cl_assert(!git_path_exists("local"));
cl_assert(git_path_exists("global"));
cl_git_pass(p_unlink("global"));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/multivar.c
|
#include "clar_libgit2.h"
static const char *_name = "remote.ab.url";
void test_config_multivar__initialize(void)
{
cl_fixture_sandbox("config");
}
void test_config_multivar__cleanup(void)
{
cl_fixture_cleanup("config");
}
static int mv_read_cb(const git_config_entry *entry, void *data)
{
int *n = (int *) data;
if (!strcmp(entry->name, _name))
(*n)++;
return 0;
}
void test_config_multivar__foreach(void)
{
git_config *cfg;
int n = 0;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config11")));
cl_git_pass(git_config_foreach(cfg, mv_read_cb, &n));
cl_assert(n == 2);
git_config_free(cfg);
}
static int cb(const git_config_entry *entry, void *data)
{
int *n = (int *) data;
GIT_UNUSED(entry);
(*n)++;
return 0;
}
static void check_get_multivar_foreach(
git_config *cfg, int expected, int expected_patterned)
{
int n = 0;
if (expected > 0) {
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
cl_assert_equal_i(expected, n);
} else {
cl_assert_equal_i(GIT_ENOTFOUND,
git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
}
n = 0;
if (expected_patterned > 0) {
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, "example", cb, &n));
cl_assert_equal_i(expected_patterned, n);
} else {
cl_assert_equal_i(GIT_ENOTFOUND,
git_config_get_multivar_foreach(cfg, _name, "example", cb, &n));
}
}
static void check_get_multivar(git_config *cfg, int expected)
{
git_config_iterator *iter;
git_config_entry *entry;
int n = 0;
cl_git_pass(git_config_multivar_iterator_new(&iter, cfg, _name, NULL));
while (git_config_next(&entry, iter) == 0)
n++;
cl_assert_equal_i(expected, n);
git_config_iterator_free(iter);
}
void test_config_multivar__get(void)
{
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
check_get_multivar_foreach(cfg, 2, 1);
/* add another that has the _name entry */
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config9", GIT_CONFIG_LEVEL_SYSTEM, NULL, 1));
check_get_multivar_foreach(cfg, 3, 2);
/* add another that does not have the _name entry */
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config0", GIT_CONFIG_LEVEL_GLOBAL, NULL, 1));
check_get_multivar_foreach(cfg, 3, 2);
/* add another that does not have the _name entry at the end */
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config1", GIT_CONFIG_LEVEL_APP, NULL, 1));
check_get_multivar_foreach(cfg, 3, 2);
/* drop original file */
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config2", GIT_CONFIG_LEVEL_LOCAL, NULL, 1));
check_get_multivar_foreach(cfg, 1, 1);
/* drop other file with match */
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config3", GIT_CONFIG_LEVEL_SYSTEM, NULL, 1));
check_get_multivar_foreach(cfg, 0, 0);
/* reload original file (add different place in order) */
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config11", GIT_CONFIG_LEVEL_SYSTEM, NULL, 1));
check_get_multivar_foreach(cfg, 2, 1);
check_get_multivar(cfg, 2);
git_config_free(cfg);
}
void test_config_multivar__add(void)
{
git_config *cfg;
int n;
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
cl_git_pass(git_config_set_multivar(cfg, _name, "nonexistant", "git://git.otherplace.org/libgit2"));
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
cl_assert_equal_i(n, 3);
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, "otherplace", cb, &n));
cl_assert_equal_i(n, 1);
git_config_free(cfg);
/* We know it works in memory, let's see if the file is written correctly */
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
cl_assert_equal_i(n, 3);
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, "otherplace", cb, &n));
cl_assert_equal_i(n, 1);
git_config_free(cfg);
}
void test_config_multivar__add_new(void)
{
const char *var = "a.brand.new";
git_config *cfg;
int n;
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
cl_git_pass(git_config_set_multivar(cfg, var, "$^", "variable"));
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, var, NULL, cb, &n));
cl_assert_equal_i(n, 1);
git_config_free(cfg);
}
void test_config_multivar__replace(void)
{
git_config *cfg;
int n;
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
cl_assert(n == 2);
cl_git_pass(git_config_set_multivar(cfg, _name, "github", "git://git.otherplace.org/libgit2"));
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
cl_assert(n == 2);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
cl_assert(n == 2);
git_config_free(cfg);
}
void test_config_multivar__replace_multiple(void)
{
git_config *cfg;
int n;
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
cl_git_pass(git_config_set_multivar(cfg, _name, "git://", "git://git.otherplace.org/libgit2"));
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, "otherplace", cb, &n));
cl_assert_equal_i(n, 2);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, "otherplace", cb, &n));
cl_assert_equal_i(n, 2);
git_config_free(cfg);
}
void test_config_multivar__delete(void)
{
git_config *cfg;
int n;
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
cl_assert_equal_i(2, n);
cl_git_pass(git_config_delete_multivar(cfg, _name, "github"));
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
cl_assert_equal_i(1, n);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
cl_assert_equal_i(1, n);
git_config_free(cfg);
}
void test_config_multivar__delete_multiple(void)
{
git_config *cfg;
int n;
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
n = 0;
cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n));
cl_assert(n == 2);
cl_git_pass(git_config_delete_multivar(cfg, _name, "git"));
n = 0;
cl_git_fail_with(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n), GIT_ENOTFOUND);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
n = 0;
cl_git_fail_with(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n), GIT_ENOTFOUND);
git_config_free(cfg);
}
void test_config_multivar__delete_notfound(void)
{
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
cl_git_fail_with(git_config_delete_multivar(cfg, "remote.ab.noturl", "git"), GIT_ENOTFOUND);
git_config_free(cfg);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/read.c
|
#include "clar_libgit2.h"
#include "buffer.h"
#include "path.h"
static git_buf buf = GIT_BUF_INIT;
void test_config_read__cleanup(void)
{
git_buf_dispose(&buf);
}
void test_config_read__simple_read(void)
{
git_config *cfg;
int32_t i;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config0")));
cl_git_pass(git_config_get_int32(&i, cfg, "core.repositoryformatversion"));
cl_assert(i == 0);
cl_git_pass(git_config_get_bool(&i, cfg, "core.filemode"));
cl_assert(i == 1);
cl_git_pass(git_config_get_bool(&i, cfg, "core.bare"));
cl_assert(i == 0);
cl_git_pass(git_config_get_bool(&i, cfg, "core.logallrefupdates"));
cl_assert(i == 1);
git_config_free(cfg);
}
void test_config_read__case_sensitive(void)
{
git_config *cfg;
int i;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config1")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.that.other"));
cl_assert_equal_s("true", git_buf_cstr(&buf));
git_buf_clear(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.That.other"));
cl_assert_equal_s("yes", git_buf_cstr(&buf));
cl_git_pass(git_config_get_bool(&i, cfg, "this.that.other"));
cl_assert(i == 1);
cl_git_pass(git_config_get_bool(&i, cfg, "this.That.other"));
cl_assert(i == 1);
/* This one doesn't exist */
cl_must_fail(git_config_get_bool(&i, cfg, "this.thaT.other"));
git_config_free(cfg);
}
/*
* If \ is the last non-space character on the line, we read the next
* one, separating each line with SP.
*/
void test_config_read__multiline_value(void)
{
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config2")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.That.and"));
cl_assert_equal_s("one one one two two three three", git_buf_cstr(&buf));
git_config_free(cfg);
}
static void clean_test_config(void *unused)
{
GIT_UNUSED(unused);
cl_fixture_cleanup("./testconfig");
}
void test_config_read__multiline_value_and_eof(void)
{
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[header]\n key1 = foo\\\n");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "header.key1"));
cl_assert_equal_s("foo", git_buf_cstr(&buf));
git_config_free(cfg);
}
void test_config_read__multiline_eof(void)
{
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[header]\n key1 = \\\n");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "header.key1"));
cl_assert_equal_s("", git_buf_cstr(&buf));
git_config_free(cfg);
}
/*
* This kind of subsection declaration is case-insensitive
*/
void test_config_read__subsection_header(void)
{
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config3")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "section.subsection.var"));
cl_assert_equal_s("hello", git_buf_cstr(&buf));
/* The subsection is transformed to lower-case */
cl_must_fail(git_config_get_string_buf(&buf, cfg, "section.subSectIon.var"));
git_config_free(cfg);
}
void test_config_read__lone_variable(void)
{
git_config *cfg;
int i;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config4")));
cl_git_fail(git_config_get_int32(&i, cfg, "some.section.variable"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.section.variable"));
cl_assert_equal_s("", git_buf_cstr(&buf));
git_buf_clear(&buf);
cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variable"));
cl_assert(i == 1);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.section.variableeq"));
cl_assert_equal_s("", git_buf_cstr(&buf));
cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variableeq"));
cl_assert(i == 0);
git_config_free(cfg);
}
void test_config_read__number_suffixes(void)
{
git_config *cfg;
int64_t i;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config5")));
cl_git_pass(git_config_get_int64(&i, cfg, "number.simple"));
cl_assert(i == 1);
cl_git_pass(git_config_get_int64(&i, cfg, "number.k"));
cl_assert(i == 1 * 1024);
cl_git_pass(git_config_get_int64(&i, cfg, "number.kk"));
cl_assert(i == 1 * 1024);
cl_git_pass(git_config_get_int64(&i, cfg, "number.m"));
cl_assert(i == 1 * 1024 * 1024);
cl_git_pass(git_config_get_int64(&i, cfg, "number.mm"));
cl_assert(i == 1 * 1024 * 1024);
cl_git_pass(git_config_get_int64(&i, cfg, "number.g"));
cl_assert(i == 1 * 1024 * 1024 * 1024);
cl_git_pass(git_config_get_int64(&i, cfg, "number.gg"));
cl_assert(i == 1 * 1024 * 1024 * 1024);
git_config_free(cfg);
}
void test_config_read__blank_lines(void)
{
git_config *cfg;
int i;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config6")));
cl_git_pass(git_config_get_bool(&i, cfg, "valid.subsection.something"));
cl_assert(i == 1);
cl_git_pass(git_config_get_bool(&i, cfg, "something.else.something"));
cl_assert(i == 0);
git_config_free(cfg);
}
void test_config_read__invalid_ext_headers(void)
{
git_config *cfg;
cl_must_fail(git_config_open_ondisk(&cfg, cl_fixture("config/config7")));
}
void test_config_read__empty_files(void)
{
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config8")));
git_config_free(cfg);
}
void test_config_read__symbol_headers(void)
{
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config20")));
git_config_free(cfg);
}
void test_config_read__multiline_multiple_quoted_comment_chars(void)
{
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config21")));
git_config_free(cfg);
}
void test_config_read__header_in_last_line(void)
{
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config10")));
git_config_free(cfg);
}
void test_config_read__prefixes(void)
{
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "remote.ab.url"));
cl_assert_equal_s("http://example.com/git/ab", git_buf_cstr(&buf));
git_buf_clear(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "remote.abba.url"));
cl_assert_equal_s("http://example.com/git/abba", git_buf_cstr(&buf));
git_config_free(cfg);
}
void test_config_read__escaping_quotes(void)
{
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config13")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.editor"));
cl_assert_equal_s("\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"", git_buf_cstr(&buf));
git_config_free(cfg);
}
void test_config_read__invalid_escape_sequence(void)
{
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[header]\n key1 = \\\\\\;\n key2 = value2\n");
cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig"));
git_config_free(cfg);
}
static int count_cfg_entries_and_compare_levels(
const git_config_entry *entry, void *payload)
{
int *count = payload;
if (!strcmp(entry->value, "7") || !strcmp(entry->value, "17"))
cl_assert(entry->level == GIT_CONFIG_LEVEL_GLOBAL);
else
cl_assert(entry->level == GIT_CONFIG_LEVEL_SYSTEM);
(*count)++;
return 0;
}
static int cfg_callback_countdown(const git_config_entry *entry, void *payload)
{
int *count = payload;
GIT_UNUSED(entry);
(*count)--;
if (*count == 0)
return -100;
return 0;
}
void test_config_read__foreach(void)
{
git_config *cfg;
int count, ret;
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
GIT_CONFIG_LEVEL_SYSTEM, NULL, 0));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
count = 0;
cl_git_pass(git_config_foreach(cfg, count_cfg_entries_and_compare_levels, &count));
cl_assert_equal_i(7, count);
count = 3;
cl_git_fail(ret = git_config_foreach(cfg, cfg_callback_countdown, &count));
cl_assert_equal_i(-100, ret);
git_config_free(cfg);
}
void test_config_read__iterator(void)
{
const char *keys[] = {
"core.dummy2",
"core.verylong",
"core.dummy",
"remote.ab.url",
"remote.abba.url",
"core.dummy2",
"core.global"
};
git_config *cfg;
git_config_iterator *iter;
git_config_entry *entry;
int count, ret;
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
GIT_CONFIG_LEVEL_SYSTEM, NULL, 0));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
count = 0;
cl_git_pass(git_config_iterator_new(&iter, cfg));
while ((ret = git_config_next(&entry, iter)) == 0) {
cl_assert_equal_s(entry->name, keys[count]);
count++;
}
git_config_iterator_free(iter);
cl_assert_equal_i(GIT_ITEROVER, ret);
cl_assert_equal_i(7, count);
count = 3;
cl_git_pass(git_config_iterator_new(&iter, cfg));
git_config_iterator_free(iter);
git_config_free(cfg);
}
static int count_cfg_entries(const git_config_entry *entry, void *payload)
{
int *count = payload;
GIT_UNUSED(entry);
(*count)++;
return 0;
}
void test_config_read__foreach_match(void)
{
git_config *cfg;
int count;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9")));
count = 0;
cl_git_pass(
git_config_foreach_match(cfg, "core.*", count_cfg_entries, &count));
cl_assert_equal_i(3, count);
count = 0;
cl_git_pass(
git_config_foreach_match(cfg, "remote\\.ab.*", count_cfg_entries, &count));
cl_assert_equal_i(2, count);
count = 0;
cl_git_pass(
git_config_foreach_match(cfg, ".*url$", count_cfg_entries, &count));
cl_assert_equal_i(2, count);
count = 0;
cl_git_pass(
git_config_foreach_match(cfg, ".*dummy.*", count_cfg_entries, &count));
cl_assert_equal_i(2, count);
count = 0;
cl_git_pass(
git_config_foreach_match(cfg, ".*nomatch.*", count_cfg_entries, &count));
cl_assert_equal_i(0, count);
git_config_free(cfg);
}
static void check_glob_iter(git_config *cfg, const char *regexp, int expected)
{
git_config_iterator *iter;
git_config_entry *entry;
int count, error;
cl_git_pass(git_config_iterator_glob_new(&iter, cfg, regexp));
count = 0;
while ((error = git_config_next(&entry, iter)) == 0)
count++;
cl_assert_equal_i(GIT_ITEROVER, error);
cl_assert_equal_i(expected, count);
git_config_iterator_free(iter);
}
void test_config_read__iterator_invalid_glob(void)
{
git_config *cfg;
git_config_iterator *iter;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9")));
cl_git_fail(git_config_iterator_glob_new(&iter, cfg, "*"));
git_config_free(cfg);
}
void test_config_read__iterator_glob(void)
{
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9")));
check_glob_iter(cfg, "core.*", 3);
check_glob_iter(cfg, "remote\\.ab.*", 2);
check_glob_iter(cfg, ".*url$", 2);
check_glob_iter(cfg, ".*dummy.*", 2);
check_glob_iter(cfg, ".*nomatch.*", 0);
git_config_free(cfg);
}
void test_config_read__whitespace_not_required_around_assignment(void)
{
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config14")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "a.b"));
cl_assert_equal_s("c", git_buf_cstr(&buf));
git_buf_clear(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "d.e"));
cl_assert_equal_s("f", git_buf_cstr(&buf));
git_config_free(cfg);
}
void test_config_read__read_git_config_entry(void)
{
git_config *cfg;
git_config_entry *entry;
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
GIT_CONFIG_LEVEL_SYSTEM, NULL, 0));
cl_git_pass(git_config_get_entry(&entry, cfg, "core.dummy2"));
cl_assert_equal_s("core.dummy2", entry->name);
cl_assert_equal_s("42", entry->value);
cl_assert_equal_i(GIT_CONFIG_LEVEL_SYSTEM, entry->level);
git_config_entry_free(entry);
git_config_free(cfg);
}
/*
* At the beginning of the test:
* - config9 has: core.dummy2=42
* - config15 has: core.dummy2=7
* - config16 has: core.dummy2=28
*/
void test_config_read__local_config_overrides_global_config_overrides_system_config(void)
{
git_config *cfg;
int32_t i;
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
GIT_CONFIG_LEVEL_SYSTEM, NULL, 0));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config16"),
GIT_CONFIG_LEVEL_LOCAL, NULL, 0));
cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2"));
cl_assert_equal_i(28, i);
git_config_free(cfg);
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
GIT_CONFIG_LEVEL_SYSTEM, NULL, 0));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2"));
cl_assert_equal_i(7, i);
git_config_free(cfg);
}
/*
* At the beginning of the test:
* - config9 has: core.global does not exist
* - config15 has: core.global=17
* - config16 has: core.global=29
*
* And also:
* - config9 has: core.system does not exist
* - config15 has: core.system does not exist
* - config16 has: core.system=11
*/
void test_config_read__fallback_from_local_to_global_and_from_global_to_system(void)
{
git_config *cfg;
int32_t i;
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
GIT_CONFIG_LEVEL_SYSTEM, NULL, 0));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config16"),
GIT_CONFIG_LEVEL_LOCAL, NULL, 0));
cl_git_pass(git_config_get_int32(&i, cfg, "core.global"));
cl_assert_equal_i(17, i);
cl_git_pass(git_config_get_int32(&i, cfg, "core.system"));
cl_assert_equal_i(11, i);
git_config_free(cfg);
}
void test_config_read__parent_dir_is_file(void)
{
git_config *cfg;
int count;
cl_git_pass(git_config_new(&cfg));
/*
* Verify we can add non-existing files when the parent directory is not
* a directory.
*/
cl_git_pass(git_config_add_file_ondisk(cfg, "/dev/null/.gitconfig",
GIT_CONFIG_LEVEL_SYSTEM, NULL, 0));
count = 0;
cl_git_pass(git_config_foreach(cfg, count_cfg_entries_and_compare_levels, &count));
cl_assert_equal_i(0, count);
git_config_free(cfg);
}
/*
* At the beginning of the test, config18 has:
* int32global = 28
* int64global = 9223372036854775803
* boolglobal = true
* stringglobal = I'm a global config value!
*
* And config19 has:
* int32global = -1
* int64global = -2
* boolglobal = false
* stringglobal = don't find me!
*
*/
void test_config_read__simple_read_from_specific_level(void)
{
git_config *cfg, *cfg_specific;
int i;
int64_t l, expected = +9223372036854775803;
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"),
GIT_CONFIG_LEVEL_SYSTEM, NULL, 0));
cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL));
cl_git_pass(git_config_get_int32(&i, cfg_specific, "core.int32global"));
cl_assert_equal_i(28, i);
cl_git_pass(git_config_get_int64(&l, cfg_specific, "core.int64global"));
cl_assert(l == expected);
cl_git_pass(git_config_get_bool(&i, cfg_specific, "core.boolglobal"));
cl_assert_equal_b(true, i);
cl_git_pass(git_config_get_string_buf(&buf, cfg_specific, "core.stringglobal"));
cl_assert_equal_s("I'm a global config value!", git_buf_cstr(&buf));
git_config_free(cfg_specific);
git_config_free(cfg);
}
void test_config_read__can_load_and_parse_an_empty_config_file(void)
{
git_config *cfg;
int i;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_assert_equal_i(GIT_ENOTFOUND, git_config_get_int32(&i, cfg, "nope.neither"));
git_config_free(cfg);
}
void test_config_read__corrupt_header(void)
{
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[sneaky ] \"quoted closing quote mark\\\"");
cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig"));
git_config_free(cfg);
}
void test_config_read__corrupt_header2(void)
{
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[unclosed \"bracket\"\n lib = git2\n");
cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig"));
git_config_free(cfg);
}
void test_config_read__corrupt_header3(void)
{
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[unclosed \"slash\\\"]\n lib = git2\n");
cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig"));
git_config_free(cfg);
}
void test_config_read__invalid_key_chars(void)
{
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[foo]\n has_underscore = git2\n");
cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_rewritefile("./testconfig", "[foo]\n has/slash = git2\n");
cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_rewritefile("./testconfig", "[foo]\n has+plus = git2\n");
cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_rewritefile("./testconfig", "[no_key]\n = git2\n");
cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig"));
git_config_free(cfg);
}
void test_config_read__lone_variable_with_trailing_whitespace(void)
{
git_config *cfg;
int b;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[foo]\n lonevariable \n");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_bool(&b, cfg, "foo.lonevariable"));
cl_assert_equal_b(true, b);
git_config_free(cfg);
}
void test_config_read__override_variable(void)
{
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[some] var = one\nvar = two");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
cl_assert_equal_s("two", git_buf_cstr(&buf));
git_config_free(cfg);
}
void test_config_read__path(void)
{
git_config *cfg;
git_buf path = GIT_BUF_INIT;
git_buf old_path = GIT_BUF_INIT;
git_buf home_path = GIT_BUF_INIT;
git_buf expected_path = GIT_BUF_INIT;
cl_git_pass(p_mkdir("fakehome", 0777));
cl_git_pass(git_path_prettify(&home_path, "fakehome", NULL));
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &old_path));
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, home_path.ptr));
cl_git_mkfile("./testconfig", "[some]\n path = ~/somefile");
cl_git_pass(git_path_join_unrooted(&expected_path, "somefile", home_path.ptr, NULL));
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_path(&path, cfg, "some.path"));
cl_assert_equal_s(expected_path.ptr, path.ptr);
git_buf_dispose(&path);
cl_git_mkfile("./testconfig", "[some]\n path = ~/");
cl_git_pass(git_path_join_unrooted(&expected_path, "", home_path.ptr, NULL));
cl_git_pass(git_config_get_path(&path, cfg, "some.path"));
cl_assert_equal_s(expected_path.ptr, path.ptr);
git_buf_dispose(&path);
cl_git_mkfile("./testconfig", "[some]\n path = ~");
cl_git_pass(git_buf_sets(&expected_path, home_path.ptr));
cl_git_pass(git_config_get_path(&path, cfg, "some.path"));
cl_assert_equal_s(expected_path.ptr, path.ptr);
git_buf_dispose(&path);
cl_git_mkfile("./testconfig", "[some]\n path = ~user/foo");
cl_git_fail(git_config_get_path(&path, cfg, "some.path"));
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, old_path.ptr));
git_buf_dispose(&old_path);
git_buf_dispose(&home_path);
git_buf_dispose(&expected_path);
git_config_free(cfg);
}
void test_config_read__crlf_style_line_endings(void)
{
git_buf buf = GIT_BUF_INIT;
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[some]\r\n var = value\r\n");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
cl_assert_equal_s(buf.ptr, "value");
git_config_free(cfg);
git_buf_dispose(&buf);
}
void test_config_read__trailing_crlf(void)
{
git_buf buf = GIT_BUF_INIT;
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[some]\r\n var = value\r\n\r\n");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
cl_assert_equal_s(buf.ptr, "value");
git_config_free(cfg);
git_buf_dispose(&buf);
}
void test_config_read__bom(void)
{
git_buf buf = GIT_BUF_INIT;
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "\xEF\xBB\xBF[some]\n var = value\n");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
cl_assert_equal_s(buf.ptr, "value");
git_config_free(cfg);
git_buf_dispose(&buf);
}
void test_config_read__arbitrary_whitespace_before_subsection(void)
{
git_buf buf = GIT_BUF_INIT;
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[some \t \"subsection\"]\n var = value\n");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.subsection.var"));
cl_assert_equal_s(buf.ptr, "value");
git_config_free(cfg);
git_buf_dispose(&buf);
}
void test_config_read__no_whitespace_after_subsection(void)
{
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[some \"subsection\" ]\n var = value\n");
cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig"));
git_config_free(cfg);
}
void test_config_read__invalid_space_section(void)
{
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "\xEF\xBB\xBF[some section]\n var = value\n");
cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig"));
git_config_free(cfg);
}
void test_config_read__invalid_quoted_first_section(void)
{
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "\xEF\xBB\xBF[\"some\"]\n var = value\n");
cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig"));
git_config_free(cfg);
}
void test_config_read__invalid_unquoted_subsection(void)
{
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "\xEF\xBB\xBF[some sub section]\n var = value\n");
cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig"));
git_config_free(cfg);
}
void test_config_read__invalid_quoted_third_section(void)
{
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "\xEF\xBB\xBF[some sub \"section\"]\n var = value\n");
cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig"));
git_config_free(cfg);
}
void test_config_read__unreadable_file_ignored(void)
{
git_buf buf = GIT_BUF_INIT;
git_config *cfg;
int ret;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[some] var = value\n[some \"OtheR\"] var = value");
cl_git_pass(p_chmod("./testconfig", 0));
ret = git_config_open_ondisk(&cfg, "./test/config");
cl_assert(ret == 0 || ret == GIT_ENOTFOUND);
git_config_free(cfg);
git_buf_dispose(&buf);
}
void test_config_read__single_line(void)
{
git_buf buf = GIT_BUF_INIT;
git_config *cfg;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[some] var = value\n[some \"OtheR\"] var = value");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
cl_assert_equal_s(buf.ptr, "value");
git_buf_clear(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.OtheR.var"));
cl_assert_equal_s(buf.ptr, "value");
git_config_free(cfg);
cl_git_mkfile("./testconfig", "[some] var = value\n[some \"OtheR\"]var = value");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
git_buf_clear(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.var"));
cl_assert_equal_s(buf.ptr, "value");
git_buf_clear(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "some.OtheR.var"));
cl_assert_equal_s(buf.ptr, "value");
git_config_free(cfg);
git_buf_dispose(&buf);
}
static int read_nosection_cb(const git_config_entry *entry, void *payload) {
int *seen = (int*)payload;
if (strcmp(entry->name, "key") == 0) {
(*seen)++;
}
return 0;
}
/* This would ideally issue a warning, if we had a way to do so. */
void test_config_read__nosection(void)
{
git_config *cfg;
git_buf buf = GIT_BUF_INIT;
int seen = 0;
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config-nosection")));
/*
* Given a key with no section, we do not allow reading it,
* but we do include it in an iteration over the config
* store. This appears to match how git's own APIs (and
* git-config(1)) behave.
*/
cl_git_fail_with(git_config_get_string_buf(&buf, cfg, "key"), GIT_EINVALIDSPEC);
cl_git_pass(git_config_foreach(cfg, read_nosection_cb, &seen));
cl_assert_equal_i(seen, 1);
git_buf_dispose(&buf);
git_config_free(cfg);
}
enum {
MAP_TRUE = 0,
MAP_FALSE = 1,
MAP_ALWAYS = 2
};
static git_configmap _test_map1[] = {
{GIT_CONFIGMAP_STRING, "always", MAP_ALWAYS},
{GIT_CONFIGMAP_FALSE, NULL, MAP_FALSE},
{GIT_CONFIGMAP_TRUE, NULL, MAP_TRUE},
};
static git_configmap _test_map2[] = {
{GIT_CONFIGMAP_INT32, NULL, 0},
};
void test_config_read__get_mapped(void)
{
git_config *cfg;
int val;
int known_good;
cl_set_cleanup(&clean_test_config, NULL);
cl_git_mkfile("./testconfig", "[header]\n"
" key1 = 1\n"
" key2 = true\n"
" key3\n"
" key4 = always\n"
" key5 = false\n"
" key6 = 0\n"
" key7 = never\n"
" key8 = On\n"
" key9 = off\n");
cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));
/* check parsing bool and string */
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key1", _test_map1, ARRAY_SIZE(_test_map1)));
cl_assert_equal_i(val, MAP_TRUE);
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key2", _test_map1, ARRAY_SIZE(_test_map1)));
cl_assert_equal_i(val, MAP_TRUE);
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key3", _test_map1, ARRAY_SIZE(_test_map1)));
cl_assert_equal_i(val, MAP_TRUE);
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key8", _test_map1, ARRAY_SIZE(_test_map1)));
cl_assert_equal_i(val, MAP_TRUE);
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key4", _test_map1, ARRAY_SIZE(_test_map1)));
cl_assert_equal_i(val, MAP_ALWAYS);
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key5", _test_map1, ARRAY_SIZE(_test_map1)));
cl_assert_equal_i(val, MAP_FALSE);
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key6", _test_map1, ARRAY_SIZE(_test_map1)));
cl_assert_equal_i(val, MAP_FALSE);
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key9", _test_map1, ARRAY_SIZE(_test_map1)));
cl_assert_equal_i(val, MAP_FALSE);
cl_git_fail(git_config_get_mapped(&val, cfg, "header.key7", _test_map1, ARRAY_SIZE(_test_map1)));
/* check parsing int values */
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key1", _test_map2, ARRAY_SIZE(_test_map2)));
cl_git_pass(git_config_get_int32(&known_good, cfg, "header.key1"));
cl_assert_equal_i(val, known_good);
cl_git_pass(git_config_get_mapped(&val, cfg, "header.key6", _test_map2, ARRAY_SIZE(_test_map2)));
cl_git_pass(git_config_get_int32(&known_good, cfg, "header.key6"));
cl_assert_equal_i(val, known_good);
cl_git_fail(git_config_get_mapped(&val, cfg, "header.key2", _test_map2, ARRAY_SIZE(_test_map2)));
cl_git_fail(git_config_get_mapped(&val, cfg, "header.key3", _test_map2, ARRAY_SIZE(_test_map2)));
cl_git_fail(git_config_get_mapped(&val, cfg, "header.key4", _test_map2, ARRAY_SIZE(_test_map2)));
cl_git_fail(git_config_get_mapped(&val, cfg, "header.key5", _test_map2, ARRAY_SIZE(_test_map2)));
cl_git_fail(git_config_get_mapped(&val, cfg, "header.key7", _test_map2, ARRAY_SIZE(_test_map2)));
cl_git_fail(git_config_get_mapped(&val, cfg, "header.key8", _test_map2, ARRAY_SIZE(_test_map2)));
cl_git_fail(git_config_get_mapped(&val, cfg, "header.key9", _test_map2, ARRAY_SIZE(_test_map2)));
git_config_free(cfg);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/conditionals.c
|
#include "clar_libgit2.h"
#include "buffer.h"
#include "futils.h"
#include "repository.h"
#ifdef GIT_WIN32
# define ROOT_PREFIX "C:"
#else
# define ROOT_PREFIX
#endif
static git_repository *_repo;
void test_config_conditionals__initialize(void)
{
_repo = cl_git_sandbox_init("empty_standard_repo");
}
void test_config_conditionals__cleanup(void)
{
cl_git_sandbox_cleanup();
}
static void assert_condition_includes(const char *keyword, const char *path, bool expected)
{
git_buf buf = GIT_BUF_INIT;
git_config *cfg;
cl_git_pass(git_buf_printf(&buf, "[includeIf \"%s:%s\"]\n", keyword, path));
cl_git_pass(git_buf_puts(&buf, "path = other\n"));
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();
cl_git_pass(git_repository_config(&cfg, _repo));
if (expected) {
git_buf_clear(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
cl_assert_equal_s("baz", git_buf_cstr(&buf));
} else {
cl_git_fail_with(GIT_ENOTFOUND,
git_config_get_string_buf(&buf, cfg, "foo.bar"));
}
git_buf_dispose(&buf);
git_config_free(cfg);
}
static char *sandbox_path(git_buf *buf, const char *suffix)
{
char *path = p_realpath(clar_sandbox_path(), NULL);
cl_assert(path);
cl_git_pass(git_buf_attach(buf, path, 0));
cl_git_pass(git_buf_joinpath(buf, buf->ptr, suffix));
return buf->ptr;
}
void test_config_conditionals__gitdir(void)
{
git_buf path = GIT_BUF_INIT;
assert_condition_includes("gitdir", ROOT_PREFIX "/", true);
assert_condition_includes("gitdir", "empty_stand", false);
assert_condition_includes("gitdir", "empty_stand/", false);
assert_condition_includes("gitdir", "empty_stand/.git", false);
assert_condition_includes("gitdir", "empty_stand/.git/", false);
assert_condition_includes("gitdir", "empty_stand*/", true);
assert_condition_includes("gitdir", "empty_stand*/.git", true);
assert_condition_includes("gitdir", "empty_stand*/.git/", false);
assert_condition_includes("gitdir", "empty_standard_repo", false);
assert_condition_includes("gitdir", "empty_standard_repo/", true);
assert_condition_includes("gitdir", "empty_standard_repo/.git", true);
assert_condition_includes("gitdir", "empty_standard_repo/.git/", false);
assert_condition_includes("gitdir", "./", false);
assert_condition_includes("gitdir", ROOT_PREFIX "/nonexistent", false);
assert_condition_includes("gitdir", ROOT_PREFIX "/empty_standard_repo", false);
assert_condition_includes("gitdir", "~/empty_standard_repo", false);
assert_condition_includes("gitdir", sandbox_path(&path, "/"), true);
assert_condition_includes("gitdir", sandbox_path(&path, "/*"), false);
assert_condition_includes("gitdir", sandbox_path(&path, "/**"), true);
assert_condition_includes("gitdir", sandbox_path(&path, "empty_standard_repo"), false);
assert_condition_includes("gitdir", sandbox_path(&path, "empty_standard_repo/"), true);
assert_condition_includes("gitdir", sandbox_path(&path, "empty_standard_repo/"), true);
assert_condition_includes("gitdir", sandbox_path(&path, "Empty_Standard_Repo"), false);
assert_condition_includes("gitdir", sandbox_path(&path, "Empty_Standard_Repo/"), false);
git_buf_dispose(&path);
}
void test_config_conditionals__gitdir_i(void)
{
git_buf path = GIT_BUF_INIT;
assert_condition_includes("gitdir/i", sandbox_path(&path, "empty_standard_repo/"), true);
assert_condition_includes("gitdir/i", sandbox_path(&path, "EMPTY_STANDARD_REPO/"), true);
git_buf_dispose(&path);
}
void test_config_conditionals__invalid_conditional_fails(void)
{
assert_condition_includes("foobar", ".git", false);
}
static void set_head(git_repository *repo, const char *name)
{
cl_git_pass(git_repository_create_head(git_repository_path(repo), name));
}
void test_config_conditionals__onbranch(void)
{
assert_condition_includes("onbranch", "master", true);
assert_condition_includes("onbranch", "m*", true);
assert_condition_includes("onbranch", "*", true);
assert_condition_includes("onbranch", "master/", false);
assert_condition_includes("onbranch", "foo", false);
set_head(_repo, "foo");
assert_condition_includes("onbranch", "master", false);
assert_condition_includes("onbranch", "foo", true);
assert_condition_includes("onbranch", "f*o", true);
set_head(_repo, "dir/ref");
assert_condition_includes("onbranch", "dir/ref", true);
assert_condition_includes("onbranch", "dir/", true);
assert_condition_includes("onbranch", "dir/*", true);
assert_condition_includes("onbranch", "dir/**", true);
assert_condition_includes("onbranch", "**", true);
assert_condition_includes("onbranch", "dir", false);
assert_condition_includes("onbranch", "dir*", false);
set_head(_repo, "dir/subdir/ref");
assert_condition_includes("onbranch", "dir/subdir/", true);
assert_condition_includes("onbranch", "dir/subdir/*", true);
assert_condition_includes("onbranch", "dir/subdir/ref", true);
assert_condition_includes("onbranch", "dir/", true);
assert_condition_includes("onbranch", "dir/**", true);
assert_condition_includes("onbranch", "**", true);
assert_condition_includes("onbranch", "dir", false);
assert_condition_includes("onbranch", "dir*", false);
assert_condition_includes("onbranch", "dir/*", false);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/config_helpers.h
|
extern void assert_config_entry_existence(
git_repository *repo,
const char *name,
bool is_supposed_to_exist);
extern void assert_config_entry_value(
git_repository *repo,
const char *name,
const char *expected_value);
extern int count_config_entries_match(
git_repository *repo,
const char *pattern);
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/configlevel.c
|
#include "clar_libgit2.h"
void test_config_configlevel__adding_the_same_level_twice_returns_EEXISTS(void)
{
int error;
git_config *cfg;
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
GIT_CONFIG_LEVEL_LOCAL, NULL, 0));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
error = git_config_add_file_ondisk(cfg, cl_fixture("config/config16"),
GIT_CONFIG_LEVEL_GLOBAL, NULL, 0);
cl_git_fail(error);
cl_assert_equal_i(GIT_EEXISTS, error);
git_config_free(cfg);
}
void test_config_configlevel__can_replace_a_config_file_at_an_existing_level(void)
{
git_config *cfg;
git_buf buf = {0};
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
GIT_CONFIG_LEVEL_LOCAL, NULL, 1));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"),
GIT_CONFIG_LEVEL_LOCAL, NULL, 1));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.stringglobal"));
cl_assert_equal_s("don't find me!", buf.ptr);
git_buf_dispose(&buf);
git_config_free(cfg);
}
void test_config_configlevel__can_read_from_a_single_level_focused_file_after_parent_config_has_been_freed(void)
{
git_config *cfg;
git_config *single_level_cfg;
git_buf buf = {0};
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"),
GIT_CONFIG_LEVEL_LOCAL, NULL, 0));
cl_git_pass(git_config_open_level(&single_level_cfg, cfg, GIT_CONFIG_LEVEL_LOCAL));
git_config_free(cfg);
cl_git_pass(git_config_get_string_buf(&buf, single_level_cfg, "core.stringglobal"));
cl_assert_equal_s("don't find me!", buf.ptr);
git_buf_dispose(&buf);
git_config_free(single_level_cfg);
}
void test_config_configlevel__fetching_a_level_from_an_empty_compound_config_returns_ENOTFOUND(void)
{
git_config *cfg;
git_config *local_cfg;
cl_git_pass(git_config_new(&cfg));
cl_assert_equal_i(GIT_ENOTFOUND, git_config_open_level(&local_cfg, cfg, GIT_CONFIG_LEVEL_LOCAL));
git_config_free(cfg);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/stress.c
|
#include "clar_libgit2.h"
#include "filebuf.h"
#include "futils.h"
#include "posix.h"
#define TEST_CONFIG "git-test-config"
static git_buf buf = GIT_BUF_INIT;
void test_config_stress__initialize(void)
{
git_filebuf file = GIT_FILEBUF_INIT;
cl_git_pass(git_filebuf_open(&file, TEST_CONFIG, 0, 0666));
git_filebuf_printf(&file, "[color]\n\tui = auto\n");
git_filebuf_printf(&file, "[core]\n\teditor = \n");
cl_git_pass(git_filebuf_commit(&file));
}
void test_config_stress__cleanup(void)
{
git_buf_dispose(&buf);
p_unlink(TEST_CONFIG);
}
void test_config_stress__dont_break_on_invalid_input(void)
{
git_config *config;
cl_assert(git_path_exists(TEST_CONFIG));
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
cl_git_pass(git_config_get_string_buf(&buf, config, "color.ui"));
cl_git_pass(git_config_get_string_buf(&buf, config, "core.editor"));
git_config_free(config);
}
void assert_config_value(git_config *config, const char *key, const char *value)
{
git_buf_clear(&buf);
cl_git_pass(git_config_get_string_buf(&buf, config, key));
cl_assert_equal_s(value, git_buf_cstr(&buf));
}
void test_config_stress__comments(void)
{
git_config *config;
cl_git_pass(git_config_open_ondisk(&config, cl_fixture("config/config12")));
assert_config_value(config, "some.section.test2", "hello");
assert_config_value(config, "some.section.test3", "welcome");
assert_config_value(config, "some.section.other", "hello! \" ; ; ; ");
assert_config_value(config, "some.section.other2", "cool! \" # # # ");
assert_config_value(config, "some.section.multi", "hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#");
assert_config_value(config, "some.section.multi2", "good, this is a ; multiline comment # with ;\n special chars and other stuff !@#");
assert_config_value(config, "some.section.back", "this is \ba phrase");
assert_config_value(config, "some.section.dollar", "some $sign");
assert_config_value(config, "some.section.multiquotes", "!ls x ls # comment2 $HOME");
assert_config_value(config, "some.section.multiquotes2", "!ls x ls \"# comment2 $HOME\"");
assert_config_value(config, "some.section.multiquotes3", "hi # ho there are # more quotes");
assert_config_value(config, "some.section.quotecomment", "hi # ho there are # more");
git_config_free(config);
}
void test_config_stress__escape_subsection_names(void)
{
git_config *config;
cl_assert(git_path_exists("git-test-config"));
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
cl_git_pass(git_config_set_string(config, "some.sec\\tion.other", "foo"));
git_config_free(config);
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
assert_config_value(config, "some.sec\\tion.other", "foo");
git_config_free(config);
}
void test_config_stress__trailing_backslash(void)
{
git_config *config;
const char *path = "C:\\iam\\some\\windows\\path\\";
cl_assert(git_path_exists("git-test-config"));
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
cl_git_pass(git_config_set_string(config, "windows.path", path));
git_config_free(config);
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
assert_config_value(config, "windows.path", path);
git_config_free(config);
}
void test_config_stress__complex(void)
{
git_config *config;
const char *path = "./config-immediate-multiline";
cl_git_mkfile(path, "[imm]\n multi = \"\\\nfoo\"");
cl_git_pass(git_config_open_ondisk(&config, path));
assert_config_value(config, "imm.multi", "foo");
git_config_free(config);
}
void test_config_stress__quick_write(void)
{
git_config *config_w, *config_r;
const char *path = "./config-quick-write";
const char *key = "quick.write";
int32_t i;
/* Create an external writer for one instance with the other one */
cl_git_pass(git_config_open_ondisk(&config_w, path));
cl_git_pass(git_config_open_ondisk(&config_r, path));
/* Write and read in the same second (repeat to increase the chance of it happening) */
for (i = 0; i < 10; i++) {
int32_t val;
cl_git_pass(git_config_set_int32(config_w, key, i));
cl_msleep(1);
cl_git_pass(git_config_get_int32(&val, config_r, key));
cl_assert_equal_i(i, val);
}
git_config_free(config_r);
git_config_free(config_w);
}
static int foreach_cb(const git_config_entry *entry, void *payload)
{
if (!strcmp(entry->name, "key.value")) {
*(char **)payload = git__strdup(entry->value);
return 0;
}
return -1;
}
void test_config_stress__foreach_refreshes(void)
{
git_config *config_w, *config_r;
char *value = NULL;
cl_git_pass(git_config_open_ondisk(&config_w, "./cfg"));
cl_git_pass(git_config_open_ondisk(&config_r, "./cfg"));
cl_git_pass(git_config_set_string(config_w, "key.value", "1"));
cl_git_pass(git_config_foreach_match(config_r, "key.value", foreach_cb, &value));
cl_assert_equal_s(value, "1");
git_config_free(config_r);
git_config_free(config_w);
git__free(value);
}
void test_config_stress__foreach_refreshes_snapshot(void)
{
git_config *config, *snapshot;
char *value = NULL;
cl_git_pass(git_config_open_ondisk(&config, "./cfg"));
cl_git_pass(git_config_set_string(config, "key.value", "1"));
cl_git_pass(git_config_snapshot(&snapshot, config));
cl_git_pass(git_config_foreach_match(snapshot, "key.value", foreach_cb, &value));
cl_assert_equal_s(value, "1");
git_config_free(snapshot);
git_config_free(config);
git__free(value);
}
void test_config_stress__huge_section_with_many_values(void)
{
git_config *config;
if (!cl_is_env_set("GITTEST_INVASIVE_SPEED"))
cl_skip();
/*
* The config file is structured in such a way that is
* has a section header that is approximately 500kb of
* size followed by 40k entries. While the resulting
* configuration file itself is roughly 650kb in size and
* thus considered to be rather small, in the past we'd
* balloon to more than 20GB of memory (20000x500kb)
* while parsing the file. It thus was a trivial way to
* cause an out-of-memory situation and thus cause denial
* of service, e.g. via gitmodules.
*/
cl_git_pass(git_config_open_ondisk(&config, cl_fixture("config/config-oom")));
git_config_free(config);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/validkeyname.c
|
#include "clar_libgit2.h"
#include "config.h"
static git_config *cfg;
void test_config_validkeyname__initialize(void)
{
cl_fixture_sandbox("config/config10");
cl_git_pass(git_config_open_ondisk(&cfg, "config10"));
}
void test_config_validkeyname__cleanup(void)
{
git_config_free(cfg);
cfg = NULL;
cl_fixture_cleanup("config10");
}
static void assert_invalid_config_key_name(const char *name)
{
git_buf buf = GIT_BUF_INIT;
cl_git_fail_with(git_config_get_string_buf(&buf, cfg, name),
GIT_EINVALIDSPEC);
cl_git_fail_with(git_config_set_string(cfg, name, "42"),
GIT_EINVALIDSPEC);
cl_git_fail_with(git_config_delete_entry(cfg, name),
GIT_EINVALIDSPEC);
cl_git_fail_with(git_config_get_multivar_foreach(cfg, name, "*", NULL, NULL),
GIT_EINVALIDSPEC);
cl_git_fail_with(git_config_set_multivar(cfg, name, "*", "42"),
GIT_EINVALIDSPEC);
}
void test_config_validkeyname__accessing_requires_a_valid_name(void)
{
assert_invalid_config_key_name("");
assert_invalid_config_key_name(".");
assert_invalid_config_key_name("..");
assert_invalid_config_key_name("core.");
assert_invalid_config_key_name("d#ff.dirstat.lines");
assert_invalid_config_key_name("diff.dirstat.lines#");
assert_invalid_config_key_name("dif\nf.dirstat.lines");
assert_invalid_config_key_name("dif.dir\nstat.lines");
assert_invalid_config_key_name("dif.dirstat.li\nes");
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/config_helpers.c
|
#include "clar_libgit2.h"
#include "config_helpers.h"
#include "repository.h"
#include "buffer.h"
void assert_config_entry_existence(
git_repository *repo,
const char *name,
bool is_supposed_to_exist)
{
git_config *config;
git_config_entry *entry = NULL;
int result;
cl_git_pass(git_repository_config__weakptr(&config, repo));
result = git_config_get_entry(&entry, config, name);
git_config_entry_free(entry);
if (is_supposed_to_exist)
cl_git_pass(result);
else
cl_assert_equal_i(GIT_ENOTFOUND, result);
}
void assert_config_entry_value(
git_repository *repo,
const char *name,
const char *expected_value)
{
git_config *config;
git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_repository_config__weakptr(&config, repo));
cl_git_pass(git_config_get_string_buf(&buf, config, name));
cl_assert_equal_s(expected_value, git_buf_cstr(&buf));
git_buf_dispose(&buf);
}
static int count_config_entries_cb(
const git_config_entry *entry,
void *payload)
{
int *how_many = (int *)payload;
GIT_UNUSED(entry);
(*how_many)++;
return 0;
}
int count_config_entries_match(git_repository *repo, const char *pattern)
{
git_config *config;
int how_many = 0;
cl_git_pass(git_repository_config(&config, repo));
cl_assert_equal_i(0, git_config_foreach_match(
config, pattern, count_config_entries_cb, &how_many));
git_config_free(config);
return how_many;
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/snapshot.c
|
#include "clar_libgit2.h"
#include "config_backend.h"
static git_config *cfg;
static git_config *snapshot;
void test_config_snapshot__cleanup(void)
{
git_config_free(cfg);
cfg = NULL;
git_config_free(snapshot);
snapshot = NULL;
}
void test_config_snapshot__create_snapshot(void)
{
int32_t i;
cl_git_mkfile("config", "[old]\nvalue = 5\n");
cl_git_pass(git_config_open_ondisk(&cfg, "config"));
cl_git_pass(git_config_get_int32(&i, cfg, "old.value"));
cl_assert_equal_i(5, i);
cl_git_pass(git_config_snapshot(&snapshot, cfg));
/* Change the value on the file itself (simulate external process) */
cl_git_mkfile("config", "[old]\nvalue = 56\n");
cl_git_pass(git_config_get_int32(&i, cfg, "old.value"));
cl_assert_equal_i(56, i);
cl_git_pass(git_config_get_int32(&i, snapshot, "old.value"));
cl_assert_equal_i(5, i);
/* Change the value on the file itself (simulate external process) */
cl_git_mkfile("config", "[old]\nvalue = 999\n");
/* Old snapshot should still have the old value */
cl_git_pass(git_config_get_int32(&i, snapshot, "old.value"));
cl_assert_equal_i(5, i);
/* New snapshot should see new value */
git_config_free(snapshot);
cl_git_pass(git_config_snapshot(&snapshot, cfg));
cl_git_pass(git_config_get_int32(&i, snapshot, "old.value"));
cl_assert_equal_i(999, i);
cl_git_pass(p_unlink("config"));
}
static int count_me(const git_config_entry *entry, void *payload)
{
int *n = (int *) payload;
GIT_UNUSED(entry);
(*n)++;
return 0;
}
void test_config_snapshot__multivar(void)
{
int count;
count = 0;
cl_git_mkfile("config", "[old]\nvalue = 5\nvalue = 6\n");
cl_git_pass(git_config_open_ondisk(&cfg, "config"));
cl_git_pass(git_config_get_multivar_foreach(cfg, "old.value", NULL, count_me, &count));
cl_assert_equal_i(2, count);
count = 0;
cl_git_pass(git_config_snapshot(&snapshot, cfg));
cl_git_pass(git_config_get_multivar_foreach(snapshot, "old.value", NULL, count_me, &count));
cl_assert_equal_i(2, count);
cl_git_pass(p_unlink("config"));
}
void test_config_snapshot__includes(void)
{
int i;
cl_git_mkfile("including", "[include]\npath = included");
cl_git_mkfile("included", "[section]\nkey = 1\n");
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
cl_git_pass(git_config_snapshot(&snapshot, cfg));
cl_git_pass(git_config_get_int32(&i, snapshot, "section.key"));
cl_assert_equal_i(i, 1);
/* Rewrite "included" config */
cl_git_mkfile("included", "[section]\nkey = 11\n");
/* Assert that the live config changed, but snapshot remained the same */
cl_git_pass(git_config_get_int32(&i, cfg, "section.key"));
cl_assert_equal_i(i, 11);
cl_git_pass(git_config_get_int32(&i, snapshot, "section.key"));
cl_assert_equal_i(i, 1);
cl_git_pass(p_unlink("including"));
cl_git_pass(p_unlink("included"));
}
void test_config_snapshot__snapshot(void)
{
git_config *snapshot_snapshot;
int i;
cl_git_mkfile("configfile", "[section]\nkey = 1\n");
cl_git_pass(git_config_open_ondisk(&cfg, "configfile"));
cl_git_pass(git_config_snapshot(&snapshot, cfg));
cl_git_pass(git_config_snapshot(&snapshot_snapshot, snapshot));
cl_git_pass(git_config_get_int32(&i, snapshot_snapshot, "section.key"));
cl_assert_equal_i(i, 1);
git_config_free(snapshot_snapshot);
cl_git_pass(p_unlink("configfile"));
}
void test_config_snapshot__snapshot_from_in_memony(void)
{
const char *configuration = "[section]\nkey = 1\n";
git_config_backend *backend;
int i;
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_backend_from_string(&backend, configuration, strlen(configuration)));
cl_git_pass(git_config_add_backend(cfg, backend, 0, NULL, 0));
cl_git_pass(git_config_snapshot(&snapshot, cfg));
cl_git_pass(git_config_get_int32(&i, snapshot, "section.key"));
cl_assert_equal_i(i, 1);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/global.c
|
#include "clar_libgit2.h"
#include "buffer.h"
#include "futils.h"
void test_config_global__initialize(void)
{
git_buf path = GIT_BUF_INIT;
cl_git_pass(git_futils_mkdir_r("home", 0777));
cl_git_pass(git_path_prettify(&path, "home", NULL));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
cl_git_pass(git_futils_mkdir_r("xdg/git", 0777));
cl_git_pass(git_path_prettify(&path, "xdg/git", NULL));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr));
cl_git_pass(git_futils_mkdir_r("etc", 0777));
cl_git_pass(git_path_prettify(&path, "etc", NULL));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr));
git_buf_dispose(&path);
}
void test_config_global__cleanup(void)
{
cl_sandbox_set_search_path_defaults();
cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES));
cl_git_pass(git_futils_rmdir_r("xdg", NULL, GIT_RMDIR_REMOVE_FILES));
cl_git_pass(git_futils_rmdir_r("etc", NULL, GIT_RMDIR_REMOVE_FILES));
}
void test_config_global__open_global(void)
{
git_config *cfg, *global, *selected, *dummy;
int32_t value;
cl_git_mkfile("home/.gitconfig", "[global]\n test = 4567\n");
cl_git_pass(git_config_open_default(&cfg));
cl_git_pass(git_config_get_int32(&value, cfg, "global.test"));
cl_assert_equal_i(4567, value);
cl_git_pass(git_config_open_level(&global, cfg, GIT_CONFIG_LEVEL_GLOBAL));
cl_git_pass(git_config_get_int32(&value, global, "global.test"));
cl_assert_equal_i(4567, value);
cl_git_fail(git_config_open_level(&dummy, cfg, GIT_CONFIG_LEVEL_XDG));
cl_git_pass(git_config_open_global(&selected, cfg));
cl_git_pass(git_config_get_int32(&value, selected, "global.test"));
cl_assert_equal_i(4567, value);
git_config_free(selected);
git_config_free(global);
git_config_free(cfg);
}
void test_config_global__open_symlinked_global(void)
{
#ifndef GIT_WIN32
git_config *cfg;
int32_t value;
cl_git_mkfile("home/.gitconfig.linked", "[global]\n test = 4567\n");
cl_must_pass(symlink(".gitconfig.linked", "home/.gitconfig"));
cl_git_pass(git_config_open_default(&cfg));
cl_git_pass(git_config_get_int32(&value, cfg, "global.test"));
cl_assert_equal_i(4567, value);
git_config_free(cfg);
#endif
}
void test_config_global__lock_missing_global_config(void)
{
git_config *cfg;
git_config_entry *entry;
git_transaction *transaction;
(void)p_unlink("home/.gitconfig"); /* No global config */
cl_git_pass(git_config_open_default(&cfg));
cl_git_pass(git_config_lock(&transaction, cfg));
cl_git_pass(git_config_set_string(cfg, "assertion.fail", "boom"));
cl_git_pass(git_transaction_commit(transaction));
git_transaction_free(transaction);
/* cfg is updated */
cl_git_pass(git_config_get_entry(&entry, cfg, "assertion.fail"));
cl_assert_equal_s("boom", entry->value);
git_config_entry_free(entry);
git_config_free(cfg);
/* We can reread the new value from the global config */
cl_git_pass(git_config_open_default(&cfg));
cl_git_pass(git_config_get_entry(&entry, cfg, "assertion.fail"));
cl_assert_equal_s("boom", entry->value);
git_config_entry_free(entry);
git_config_free(cfg);
}
void test_config_global__open_xdg(void)
{
git_config *cfg, *xdg, *selected;
const char *str = "teststring";
const char *key = "this.variable";
git_buf buf = {0};
cl_git_mkfile("xdg/git/config", "# XDG config\n[core]\n test = 1\n");
cl_git_pass(git_config_open_default(&cfg));
cl_git_pass(git_config_open_level(&xdg, cfg, GIT_CONFIG_LEVEL_XDG));
cl_git_pass(git_config_open_global(&selected, cfg));
cl_git_pass(git_config_set_string(xdg, key, str));
cl_git_pass(git_config_get_string_buf(&buf, selected, key));
cl_assert_equal_s(str, buf.ptr);
git_buf_dispose(&buf);
git_config_free(selected);
git_config_free(xdg);
git_config_free(cfg);
}
void test_config_global__open_programdata(void)
{
git_config *cfg;
git_repository *repo;
git_buf config_path = GIT_BUF_INIT;
git_buf var_contents = GIT_BUF_INIT;
if (cl_is_env_set("GITTEST_INVASIVE_FS_STRUCTURE"))
cl_skip();
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH,
GIT_CONFIG_LEVEL_PROGRAMDATA, &config_path));
if (!git_path_isdir(config_path.ptr))
cl_git_pass(p_mkdir(config_path.ptr, 0777));
cl_git_pass(git_buf_puts(&config_path, "/config"));
cl_git_pass(git_config_open_ondisk(&cfg, config_path.ptr));
cl_git_pass(git_config_set_string(cfg, "programdata.var", "even higher level"));
git_buf_dispose(&config_path);
git_config_free(cfg);
git_config_open_default(&cfg);
cl_git_pass(git_config_get_string_buf(&var_contents, cfg, "programdata.var"));
cl_assert_equal_s("even higher level", var_contents.ptr);
git_config_free(cfg);
git_buf_dispose(&var_contents);
cl_git_pass(git_repository_init(&repo, "./foo.git", true));
cl_git_pass(git_repository_config(&cfg, repo));
cl_git_pass(git_config_get_string_buf(&var_contents, cfg, "programdata.var"));
cl_assert_equal_s("even higher level", var_contents.ptr);
git_config_free(cfg);
git_buf_dispose(&var_contents);
git_repository_free(repo);
cl_fixture_cleanup("./foo.git");
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/write.c
|
#include "clar_libgit2.h"
#include "buffer.h"
#include "futils.h"
#include "git2/sys/config.h"
#include "config.h"
void test_config_write__initialize(void)
{
cl_fixture_sandbox("config/config9");
cl_fixture_sandbox("config/config15");
cl_fixture_sandbox("config/config17");
}
void test_config_write__cleanup(void)
{
cl_fixture_cleanup("config9");
cl_fixture_cleanup("config15");
cl_fixture_cleanup("config17");
}
void test_config_write__replace_value(void)
{
git_config *cfg;
int i;
int64_t l, expected = +9223372036854775803;
/* By freeing the config, we make sure we flush the values */
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_int32(cfg, "core.dummy", 5));
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy"));
cl_assert(i == 5);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_int32(cfg, "core.dummy", 1));
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_int64(cfg, "core.verylong", expected));
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_get_int64(&l, cfg, "core.verylong"));
cl_assert(l == expected);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_must_fail(git_config_get_int32(&i, cfg, "core.verylong"));
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_int64(cfg, "core.verylong", 1));
git_config_free(cfg);
}
void test_config_write__delete_value(void)
{
git_config *cfg;
int32_t i;
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_int32(cfg, "core.dummy", 5));
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_delete_entry(cfg, "core.dummy"));
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_assert(git_config_get_int32(&i, cfg, "core.dummy") == GIT_ENOTFOUND);
cl_git_pass(git_config_set_int32(cfg, "core.dummy", 1));
git_config_free(cfg);
}
/*
* At the beginning of the test:
* - config9 has: core.dummy2=42
* - config15 has: core.dummy2=7
*/
void test_config_write__delete_value_at_specific_level(void)
{
git_config *cfg, *cfg_specific;
int32_t i;
cl_git_pass(git_config_open_ondisk(&cfg, "config15"));
cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2"));
cl_assert(i == 7);
git_config_free(cfg);
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, "config9",
GIT_CONFIG_LEVEL_LOCAL, NULL, 0));
cl_git_pass(git_config_add_file_ondisk(cfg, "config15",
GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL));
cl_git_pass(git_config_delete_entry(cfg_specific, "core.dummy2"));
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config15"));
cl_assert(git_config_get_int32(&i, cfg, "core.dummy2") == GIT_ENOTFOUND);
cl_git_pass(git_config_set_int32(cfg, "core.dummy2", 7));
git_config_free(cfg_specific);
git_config_free(cfg);
}
/*
* This test exposes a bug where duplicate empty section headers could prevent
* deletion of config entries.
*/
void test_config_write__delete_value_with_duplicate_header(void)
{
const char *file_name = "config-duplicate-header";
const char *entry_name = "remote.origin.url";
git_config *cfg;
git_config_entry *entry;
/* This config can occur after removing and re-adding the origin remote */
const char *file_content =
"[remote \"origin\"]\n" \
"[branch \"master\"]\n" \
" remote = \"origin\"\n" \
"[remote \"origin\"]\n" \
" url = \"foo\"\n";
/* Write the test config and make sure the expected entry exists */
cl_git_mkfile(file_name, file_content);
cl_git_pass(git_config_open_ondisk(&cfg, file_name));
cl_git_pass(git_config_get_entry(&entry, cfg, entry_name));
/* Delete that entry */
cl_git_pass(git_config_delete_entry(cfg, entry_name));
/* Reopen the file and make sure the entry no longer exists */
git_config_entry_free(entry);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, file_name));
cl_git_fail(git_config_get_entry(&entry, cfg, entry_name));
/* Cleanup */
git_config_entry_free(entry);
git_config_free(cfg);
}
/*
* This test exposes a bug where duplicate section headers could cause
* config_write to add a new entry when one already exists.
*/
void test_config_write__add_value_with_duplicate_header(void)
{
const char *file_name = "config-duplicate-insert";
const char *entry_name = "foo.c";
const char *old_val = "old";
const char *new_val = "new";
const char *str;
git_config *cfg, *snapshot;
/* c = old should be replaced by c = new.
* The bug causes c = new to be inserted under the first 'foo' header.
*/
const char *file_content =
"[foo]\n" \
" a = b\n" \
"[other]\n" \
" a = b\n" \
"[foo]\n" \
" c = old\n";
/* Write the test config */
cl_git_mkfile(file_name, file_content);
cl_git_pass(git_config_open_ondisk(&cfg, file_name));
/* make sure the expected entry (foo.c) exists */
cl_git_pass(git_config_snapshot(&snapshot, cfg));
cl_git_pass(git_config_get_string(&str, snapshot, entry_name));
cl_assert_equal_s(old_val, str);
git_config_free(snapshot);
/* Try setting foo.c to something else */
cl_git_pass(git_config_set_string(cfg, entry_name, new_val));
git_config_free(cfg);
/* Reopen the file and make sure the new value was set */
cl_git_pass(git_config_open_ondisk(&cfg, file_name));
cl_git_pass(git_config_snapshot(&snapshot, cfg));
cl_git_pass(git_config_get_string(&str, snapshot, entry_name));
cl_assert_equal_s(new_val, str);
/* Cleanup */
git_config_free(snapshot);
git_config_free(cfg);
}
void test_config_write__overwrite_value_with_duplicate_header(void)
{
const char *file_name = "config-duplicate-header";
const char *entry_name = "remote.origin.url";
git_config *cfg;
git_config_entry *entry;
/* This config can occur after removing and re-adding the origin remote */
const char *file_content =
"[remote \"origin\"]\n" \
"[branch \"master\"]\n" \
" remote = \"origin\"\n" \
"[remote \"origin\"]\n" \
" url = \"foo\"\n";
/* Write the test config and make sure the expected entry exists */
cl_git_mkfile(file_name, file_content);
cl_git_pass(git_config_open_ondisk(&cfg, file_name));
cl_git_pass(git_config_get_entry(&entry, cfg, entry_name));
/* Update that entry */
cl_git_pass(git_config_set_string(cfg, entry_name, "newurl"));
/* Reopen the file and make sure the entry was updated */
git_config_entry_free(entry);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, file_name));
cl_git_pass(git_config_get_entry(&entry, cfg, entry_name));
cl_assert_equal_s("newurl", entry->value);
/* Cleanup */
git_config_entry_free(entry);
git_config_free(cfg);
}
static int multivar_cb(const git_config_entry *entry, void *data)
{
int *n = (int *)data;
cl_assert_equal_s(entry->value, "newurl");
(*n)++;
return 0;
}
void test_config_write__overwrite_multivar_within_duplicate_header(void)
{
const char *file_name = "config-duplicate-header";
const char *entry_name = "remote.origin.url";
git_config *cfg;
git_config_entry *entry;
int n = 0;
/* This config can occur after removing and re-adding the origin remote */
const char *file_content =
"[remote \"origin\"]\n" \
" url = \"bar\"\n" \
"[branch \"master\"]\n" \
" remote = \"origin\"\n" \
"[remote \"origin\"]\n" \
" url = \"foo\"\n";
/* Write the test config and make sure the expected entry exists */
cl_git_mkfile(file_name, file_content);
cl_git_pass(git_config_open_ondisk(&cfg, file_name));
cl_git_pass(git_config_get_entry(&entry, cfg, entry_name));
/* Update that entry */
cl_git_pass(git_config_set_multivar(cfg, entry_name, ".*", "newurl"));
git_config_entry_free(entry);
git_config_free(cfg);
/* Reopen the file and make sure the entry was updated */
cl_git_pass(git_config_open_ondisk(&cfg, file_name));
cl_git_pass(git_config_get_multivar_foreach(cfg, entry_name, NULL, multivar_cb, &n));
cl_assert_equal_i(2, n);
/* Cleanup */
git_config_free(cfg);
}
void test_config_write__write_subsection(void)
{
git_config *cfg;
git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "my.own.var", "works"));
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "my.own.var"));
cl_assert_equal_s("works", git_buf_cstr(&buf));
git_buf_dispose(&buf);
git_config_free(cfg);
}
void test_config_write__delete_inexistent(void)
{
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_assert(git_config_delete_entry(cfg, "core.imaginary") == GIT_ENOTFOUND);
git_config_free(cfg);
}
void test_config_write__value_containing_quotes(void)
{
git_config *cfg;
git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "core.somevar", "this \"has\" quotes"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
cl_assert_equal_s("this \"has\" quotes", git_buf_cstr(&buf));
git_buf_clear(&buf);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
cl_assert_equal_s("this \"has\" quotes", git_buf_cstr(&buf));
git_buf_clear(&buf);
git_config_free(cfg);
/* The code path for values that already exist is different, check that one as well */
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "core.somevar", "this also \"has\" quotes"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
cl_assert_equal_s("this also \"has\" quotes", git_buf_cstr(&buf));
git_buf_clear(&buf);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
cl_assert_equal_s("this also \"has\" quotes", git_buf_cstr(&buf));
git_buf_dispose(&buf);
git_config_free(cfg);
}
void test_config_write__escape_value(void)
{
git_config *cfg;
git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_set_string(cfg, "core.somevar", "this \"has\" quotes and \t"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
cl_assert_equal_s("this \"has\" quotes and \t", git_buf_cstr(&buf));
git_buf_clear(&buf);
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.somevar"));
cl_assert_equal_s("this \"has\" quotes and \t", git_buf_cstr(&buf));
git_buf_dispose(&buf);
git_config_free(cfg);
}
void test_config_write__add_value_at_specific_level(void)
{
git_config *cfg, *cfg_specific;
int i;
int64_t l, expected = +9223372036854775803;
git_buf buf = GIT_BUF_INIT;
/* open config15 as global level config file */
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, "config9",
GIT_CONFIG_LEVEL_LOCAL, NULL, 0));
cl_git_pass(git_config_add_file_ondisk(cfg, "config15",
GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL));
cl_git_pass(git_config_set_int32(cfg_specific, "core.int32global", 28));
cl_git_pass(git_config_set_int64(cfg_specific, "core.int64global", expected));
cl_git_pass(git_config_set_bool(cfg_specific, "core.boolglobal", true));
cl_git_pass(git_config_set_string(cfg_specific, "core.stringglobal", "I'm a global config value!"));
git_config_free(cfg_specific);
git_config_free(cfg);
/* open config15 as local level config file */
cl_git_pass(git_config_open_ondisk(&cfg, "config15"));
cl_git_pass(git_config_get_int32(&i, cfg, "core.int32global"));
cl_assert_equal_i(28, i);
cl_git_pass(git_config_get_int64(&l, cfg, "core.int64global"));
cl_assert(l == expected);
cl_git_pass(git_config_get_bool(&i, cfg, "core.boolglobal"));
cl_assert_equal_b(true, i);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.stringglobal"));
cl_assert_equal_s("I'm a global config value!", git_buf_cstr(&buf));
git_buf_dispose(&buf);
git_config_free(cfg);
}
void test_config_write__add_value_at_file_with_no_clrf_at_the_end(void)
{
git_config *cfg;
int i;
cl_git_pass(git_config_open_ondisk(&cfg, "config17"));
cl_git_pass(git_config_set_int32(cfg, "core.newline", 7));
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config17"));
cl_git_pass(git_config_get_int32(&i, cfg, "core.newline"));
cl_assert_equal_i(7, i);
git_config_free(cfg);
}
void test_config_write__add_section_at_file_with_no_clrf_at_the_end(void)
{
git_config *cfg;
int i;
cl_git_pass(git_config_open_ondisk(&cfg, "config17"));
cl_git_pass(git_config_set_int32(cfg, "diff.context", 10));
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, "config17"));
cl_git_pass(git_config_get_int32(&i, cfg, "diff.context"));
cl_assert_equal_i(10, i);
git_config_free(cfg);
}
void test_config_write__add_value_which_needs_quotes(void)
{
git_config *cfg, *base;
const char* str1;
const char* str2;
const char* str3;
const char* str4;
const char* str5;
cl_git_pass(git_config_open_ondisk(&cfg, "config17"));
cl_git_pass(git_config_set_string(cfg, "core.startwithspace", " Something"));
cl_git_pass(git_config_set_string(cfg, "core.endwithspace", "Something "));
cl_git_pass(git_config_set_string(cfg, "core.containscommentchar1", "some#thing"));
cl_git_pass(git_config_set_string(cfg, "core.containscommentchar2", "some;thing"));
cl_git_pass(git_config_set_string(cfg, "core.startwhithsapceandcontainsdoublequote", " some\"thing"));
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&base, "config17"));
cl_git_pass(git_config_snapshot(&cfg, base));
cl_git_pass(git_config_get_string(&str1, cfg, "core.startwithspace"));
cl_assert_equal_s(" Something", str1);
cl_git_pass(git_config_get_string(&str2, cfg, "core.endwithspace"));
cl_assert_equal_s("Something ", str2);
cl_git_pass(git_config_get_string(&str3, cfg, "core.containscommentchar1"));
cl_assert_equal_s("some#thing", str3);
cl_git_pass(git_config_get_string(&str4, cfg, "core.containscommentchar2"));
cl_assert_equal_s("some;thing", str4);
cl_git_pass(git_config_get_string(&str5, cfg, "core.startwhithsapceandcontainsdoublequote"));
cl_assert_equal_s(" some\"thing", str5);
git_config_free(cfg);
git_config_free(base);
}
void test_config_write__can_set_a_value_to_NULL(void)
{
git_repository *repository;
git_config *config;
repository = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_repository_config(&config, repository));
cl_git_fail(git_config_set_string(config, "a.b.c", NULL));
git_config_free(config);
cl_git_sandbox_cleanup();
}
void test_config_write__can_set_an_empty_value(void)
{
git_repository *repository;
git_config *config;
git_buf buf = {0};
repository = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_repository_config(&config, repository));
cl_git_pass(git_config_set_string(config, "core.somevar", ""));
cl_git_pass(git_config_get_string_buf(&buf, config, "core.somevar"));
cl_assert_equal_s("", buf.ptr);
git_buf_dispose(&buf);
git_config_free(config);
cl_git_sandbox_cleanup();
}
void test_config_write__updating_a_locked_config_file_returns_ELOCKED(void)
{
git_config *cfg;
cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
cl_git_mkfile("config9.lock", "[core]\n");
cl_git_fail_with(git_config_set_string(cfg, "core.dump", "boom"), GIT_ELOCKED);
git_config_free(cfg);
}
void test_config_write__outside_change(void)
{
int32_t tmp;
git_config *cfg;
const char *filename = "config-ext-change";
cl_git_mkfile(filename, "[old]\nvalue = 5\n");
cl_git_pass(git_config_open_ondisk(&cfg, filename));
cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value"));
/* Change the value on the file itself (simulate external process) */
cl_git_mkfile(filename, "[old]\nvalue = 6\n");
cl_git_pass(git_config_set_int32(cfg, "new.value", 7));
cl_git_pass(git_config_get_int32(&tmp, cfg, "old.value"));
cl_assert_equal_i(6, tmp);
git_config_free(cfg);
}
#define FOO_COMMENT \
"; another comment!\n"
#define SECTION_FOO \
"\n" \
" \n" \
" [section \"foo\"] \n" \
" # here's a comment\n" \
"\tname = \"value\"\n" \
" name2 = \"value2\"\n" \
#define SECTION_FOO_WITH_COMMENT SECTION_FOO FOO_COMMENT
#define SECTION_BAR \
"[section \"bar\"]\t\n" \
"\t \n" \
" barname=\"value\"\n"
void test_config_write__preserves_whitespace_and_comments(void)
{
const char *file_name = "config-duplicate-header";
const char *n;
git_config *cfg;
git_buf newfile = GIT_BUF_INIT;
/* This config can occur after removing and re-adding the origin remote */
const char *file_content = SECTION_FOO_WITH_COMMENT SECTION_BAR;
/* Write the test config and make sure the expected entry exists */
cl_git_mkfile(file_name, file_content);
cl_git_pass(git_config_open_ondisk(&cfg, file_name));
cl_git_pass(git_config_set_string(cfg, "section.foo.other", "otherval"));
cl_git_pass(git_config_set_string(cfg, "newsection.newname", "new_value"));
/* Ensure that we didn't needlessly mangle the config file */
cl_git_pass(git_futils_readbuffer(&newfile, file_name));
n = newfile.ptr;
cl_assert_equal_strn(SECTION_FOO, n, strlen(SECTION_FOO));
n += strlen(SECTION_FOO);
cl_assert_equal_strn("\tother = otherval\n", n, strlen("\tother = otherval\n"));
n += strlen("\tother = otherval\n");
cl_assert_equal_strn(FOO_COMMENT, n, strlen(FOO_COMMENT));
n += strlen(FOO_COMMENT);
cl_assert_equal_strn(SECTION_BAR, n, strlen(SECTION_BAR));
n += strlen(SECTION_BAR);
cl_assert_equal_s("[newsection]\n\tnewname = new_value\n", n);
git_buf_dispose(&newfile);
git_config_free(cfg);
}
void test_config_write__preserves_entry_with_name_only(void)
{
const char *file_name = "config-empty-value";
git_config *cfg;
git_buf newfile = GIT_BUF_INIT;
/* Write the test config and make sure the expected entry exists */
cl_git_mkfile(file_name, "[section \"foo\"]\n\tname\n");
cl_git_pass(git_config_open_ondisk(&cfg, file_name));
cl_git_pass(git_config_set_string(cfg, "newsection.newname", "new_value"));
cl_git_pass(git_config_set_string(cfg, "section.foo.other", "otherval"));
cl_git_pass(git_futils_readbuffer(&newfile, file_name));
cl_assert_equal_s("[section \"foo\"]\n\tname\n\tother = otherval\n[newsection]\n\tnewname = new_value\n", newfile.ptr);
git_buf_dispose(&newfile);
git_config_free(cfg);
}
void test_config_write__to_empty_file(void)
{
git_config *cfg;
const char *filename = "config-file";
git_buf result = GIT_BUF_INIT;
cl_git_mkfile(filename, "");
cl_git_pass(git_config_open_ondisk(&cfg, filename));
cl_git_pass(git_config_set_string(cfg, "section.name", "value"));
git_config_free(cfg);
cl_git_pass(git_futils_readbuffer(&result, "config-file"));
cl_assert_equal_s("[section]\n\tname = value\n", result.ptr);
git_buf_dispose(&result);
}
void test_config_write__to_file_with_only_comment(void)
{
git_config *cfg;
const char *filename = "config-file";
git_buf result = GIT_BUF_INIT;
cl_git_mkfile(filename, "\n\n");
cl_git_pass(git_config_open_ondisk(&cfg, filename));
cl_git_pass(git_config_set_string(cfg, "section.name", "value"));
git_config_free(cfg);
cl_git_pass(git_futils_readbuffer(&result, "config-file"));
cl_assert_equal_s("\n\n[section]\n\tname = value\n", result.ptr);
git_buf_dispose(&result);
}
void test_config_write__locking(void)
{
git_config *cfg, *cfg2;
git_config_entry *entry;
git_transaction *tx;
const char *filename = "locked-file";
/* Open the config and lock it */
cl_git_mkfile(filename, "[section]\n\tname = value\n");
cl_git_pass(git_config_open_ondisk(&cfg, filename));
cl_git_pass(git_config_get_entry(&entry, cfg, "section.name"));
cl_assert_equal_s("value", entry->value);
git_config_entry_free(entry);
cl_git_pass(git_config_lock(&tx, cfg));
/* Change entries in the locked backend */
cl_git_pass(git_config_set_string(cfg, "section.name", "other value"));
cl_git_pass(git_config_set_string(cfg, "section2.name3", "more value"));
/* We can see that the file we read from hasn't changed */
cl_git_pass(git_config_open_ondisk(&cfg2, filename));
cl_git_pass(git_config_get_entry(&entry, cfg2, "section.name"));
cl_assert_equal_s("value", entry->value);
git_config_entry_free(entry);
cl_git_fail_with(GIT_ENOTFOUND, git_config_get_entry(&entry, cfg2, "section2.name3"));
git_config_free(cfg2);
/* And we also get the old view when we read from the locked config */
cl_git_pass(git_config_get_entry(&entry, cfg, "section.name"));
cl_assert_equal_s("value", entry->value);
git_config_entry_free(entry);
cl_git_fail_with(GIT_ENOTFOUND, git_config_get_entry(&entry, cfg, "section2.name3"));
cl_git_pass(git_transaction_commit(tx));
git_transaction_free(tx);
/* Now that we've unlocked it, we should see both updates */
cl_git_pass(git_config_get_entry(&entry, cfg, "section.name"));
cl_assert_equal_s("other value", entry->value);
git_config_entry_free(entry);
cl_git_pass(git_config_get_entry(&entry, cfg, "section2.name3"));
cl_assert_equal_s("more value", entry->value);
git_config_entry_free(entry);
git_config_free(cfg);
/* We should also see the changes after reopening the config */
cl_git_pass(git_config_open_ondisk(&cfg, filename));
cl_git_pass(git_config_get_entry(&entry, cfg, "section.name"));
cl_assert_equal_s("other value", entry->value);
git_config_entry_free(entry);
cl_git_pass(git_config_get_entry(&entry, cfg, "section2.name3"));
cl_assert_equal_s("more value", entry->value);
git_config_entry_free(entry);
git_config_free(cfg);
}
void test_config_write__repeated(void)
{
const char *filename = "config-repeated";
git_config *cfg;
git_buf result = GIT_BUF_INIT;
const char *expected = "[sample \"prefix\"]\n\
\tsetting1 = someValue1\n\
\tsetting2 = someValue2\n\
\tsetting3 = someValue3\n\
\tsetting4 = someValue4\n\
";
cl_git_pass(git_config_open_ondisk(&cfg, filename));
cl_git_pass(git_config_set_string(cfg, "sample.prefix.setting1", "someValue1"));
cl_git_pass(git_config_set_string(cfg, "sample.prefix.setting2", "someValue2"));
cl_git_pass(git_config_set_string(cfg, "sample.prefix.setting3", "someValue3"));
cl_git_pass(git_config_set_string(cfg, "sample.prefix.setting4", "someValue4"));
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, filename));
cl_git_pass(git_futils_readbuffer(&result, filename));
cl_assert_equal_s(expected, result.ptr);
git_buf_dispose(&result);
git_config_free(cfg);
}
void test_config_write__preserve_case(void)
{
const char *filename = "config-preserve-case";
git_config *cfg;
git_buf result = GIT_BUF_INIT;
const char *expected = "[sOMe]\n" \
"\tThInG = foo\n" \
"\tOtheR = thing\n";
cl_git_pass(git_config_open_ondisk(&cfg, filename));
cl_git_pass(git_config_set_string(cfg, "sOMe.ThInG", "foo"));
cl_git_pass(git_config_set_string(cfg, "SomE.OtheR", "thing"));
git_config_free(cfg);
cl_git_pass(git_config_open_ondisk(&cfg, filename));
cl_git_pass(git_futils_readbuffer(&result, filename));
cl_assert_equal_s(expected, result.ptr);
git_buf_dispose(&result);
git_config_free(cfg);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/include.c
|
#include "clar_libgit2.h"
#include "buffer.h"
#include "futils.h"
static git_config *cfg;
static git_buf buf;
void test_config_include__initialize(void)
{
cfg = NULL;
git_buf_init(&buf, 0);
}
void test_config_include__cleanup(void)
{
git_config_free(cfg);
git_buf_dispose(&buf);
}
void test_config_include__relative(void)
{
cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config-include")));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
}
void test_config_include__absolute(void)
{
cl_git_pass(git_buf_printf(&buf, "[include]\npath = %s/config-included", cl_fixture("config")));
cl_git_mkfile("config-include-absolute", git_buf_cstr(&buf));
git_buf_dispose(&buf);
cl_git_pass(git_config_open_ondisk(&cfg, "config-include-absolute"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
cl_git_pass(p_unlink("config-include-absolute"));
}
void test_config_include__homedir(void)
{
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, cl_fixture("config")));
cl_git_mkfile("config-include-homedir", "[include]\npath = ~/config-included");
cl_git_pass(git_config_open_ondisk(&cfg, "config-include-homedir"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
cl_sandbox_set_search_path_defaults();
cl_git_pass(p_unlink("config-include-homedir"));
}
/* We need to pretend that the variables were defined where the file was included */
void test_config_include__ordering(void)
{
cl_git_mkfile("included", "[foo \"bar\"]\nbaz = hurrah\nfrotz = hiya");
cl_git_mkfile("including",
"[foo \"bar\"]\nfrotz = hello\n"
"[include]\npath = included\n"
"[foo \"bar\"]\nbaz = huzzah\n");
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.frotz"));
cl_assert_equal_s("hiya", git_buf_cstr(&buf));
git_buf_clear(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz"));
cl_assert_equal_s("huzzah", git_buf_cstr(&buf));
cl_git_pass(p_unlink("included"));
cl_git_pass(p_unlink("including"));
}
/* We need to pretend that the variables were defined where the file was included */
void test_config_include__depth(void)
{
cl_git_mkfile("a", "[include]\npath = b");
cl_git_mkfile("b", "[include]\npath = a");
cl_git_fail(git_config_open_ondisk(&cfg, "a"));
cl_git_pass(p_unlink("a"));
cl_git_pass(p_unlink("b"));
}
void test_config_include__empty_path_sanely_handled(void)
{
cl_git_mkfile("a", "[include]\npath");
cl_git_pass(git_config_open_ondisk(&cfg, "a"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "include.path"));
cl_assert_equal_s("", git_buf_cstr(&buf));
cl_git_pass(p_unlink("a"));
}
void test_config_include__missing(void)
{
cl_git_mkfile("including", "[include]\npath = nonexistentfile\n[foo]\nbar = baz");
git_error_clear();
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
cl_assert(git_error_last() == NULL);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
cl_assert_equal_s("baz", git_buf_cstr(&buf));
cl_git_pass(p_unlink("including"));
}
void test_config_include__missing_homedir(void)
{
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, cl_fixture("config")));
cl_git_mkfile("including", "[include]\npath = ~/.nonexistentfile\n[foo]\nbar = baz");
git_error_clear();
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
cl_assert(git_error_last() == NULL);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
cl_assert_equal_s("baz", git_buf_cstr(&buf));
cl_sandbox_set_search_path_defaults();
cl_git_pass(p_unlink("including"));
}
#define replicate10(s) s s s s s s s s s s
void test_config_include__depth2(void)
{
const char *content = "[include]\n" replicate10(replicate10("path=bottom\n"));
cl_git_mkfile("top-level", "[include]\npath = middle\n[foo]\nbar = baz");
cl_git_mkfile("middle", content);
cl_git_mkfile("bottom", "[foo]\nbar2 = baz2");
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
cl_assert_equal_s("baz", git_buf_cstr(&buf));
git_buf_clear(&buf);
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar2"));
cl_assert_equal_s("baz2", git_buf_cstr(&buf));
cl_git_pass(p_unlink("top-level"));
cl_git_pass(p_unlink("middle"));
cl_git_pass(p_unlink("bottom"));
}
void test_config_include__removing_include_removes_values(void)
{
cl_git_mkfile("top-level", "[include]\npath = included");
cl_git_mkfile("included", "[foo]\nbar = value");
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
cl_git_mkfile("top-level", "");
cl_git_fail(git_config_get_string_buf(&buf, cfg, "foo.bar"));
cl_git_pass(p_unlink("top-level"));
cl_git_pass(p_unlink("included"));
}
void test_config_include__rewriting_include_refreshes_values(void)
{
cl_git_mkfile("top-level", "[include]\npath = first\n[include]\npath = second");
cl_git_mkfile("first", "[first]\nfoo = bar");
cl_git_mkfile("second", "[second]\nfoo = bar");
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
cl_git_mkfile("first", "[first]\nother = value");
cl_git_fail(git_config_get_string_buf(&buf, cfg, "foo.bar"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "first.other"));
cl_assert_equal_s(buf.ptr, "value");
cl_git_pass(p_unlink("top-level"));
cl_git_pass(p_unlink("first"));
cl_git_pass(p_unlink("second"));
}
void test_config_include__rewriting_include_twice_refreshes_values(void)
{
cl_git_mkfile("top-level", "[include]\npath = included");
cl_git_mkfile("included", "[foo]\nbar = first-value");
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar"));
git_buf_clear(&buf);
cl_git_mkfile("included", "[foo]\nother = value2");
cl_git_fail(git_config_get_string_buf(&buf, cfg, "foo.bar"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.other"));
cl_assert_equal_s(buf.ptr, "value2");
git_buf_clear(&buf);
cl_git_mkfile("included", "[foo]\nanother = bar");
cl_git_fail(git_config_get_string_buf(&buf, cfg, "foo.other"));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.another"));
cl_assert_equal_s(buf.ptr, "bar");
cl_git_pass(p_unlink("top-level"));
cl_git_pass(p_unlink("included"));
}
void test_config_include__included_variables_cannot_be_deleted(void)
{
cl_git_mkfile("top-level", "[include]\npath = included\n");
cl_git_mkfile("included", "[foo]\nbar = value");
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
cl_git_fail(git_config_delete_entry(cfg, "foo.bar"));
cl_git_pass(p_unlink("top-level"));
cl_git_pass(p_unlink("included"));
}
void test_config_include__included_variables_cannot_be_modified(void)
{
cl_git_mkfile("top-level", "[include]\npath = included\n");
cl_git_mkfile("included", "[foo]\nbar = value");
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
cl_git_fail(git_config_set_string(cfg, "foo.bar", "other-value"));
cl_git_pass(p_unlink("top-level"));
cl_git_pass(p_unlink("included"));
}
void test_config_include__variables_in_included_override_including(void)
{
int i;
cl_git_mkfile("top-level", "[foo]\nbar = 1\n[include]\npath = included");
cl_git_mkfile("included", "[foo]\nbar = 2");
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
cl_git_pass(git_config_get_int32(&i, cfg, "foo.bar"));
cl_assert_equal_i(i, 2);
cl_git_pass(p_unlink("top-level"));
cl_git_pass(p_unlink("included"));
}
void test_config_include__variables_in_including_override_included(void)
{
int i;
cl_git_mkfile("top-level", "[include]\npath = included\n[foo]\nbar = 1");
cl_git_mkfile("included", "[foo]\nbar = 2");
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
cl_git_pass(git_config_get_int32(&i, cfg, "foo.bar"));
cl_assert_equal_i(i, 1);
cl_git_pass(p_unlink("top-level"));
cl_git_pass(p_unlink("included"));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/new.c
|
#include "clar_libgit2.h"
#include "filebuf.h"
#include "futils.h"
#include "posix.h"
#define TEST_CONFIG "git-new-config"
void test_config_new__write_new_config(void)
{
git_config *config;
git_buf buf = GIT_BUF_INIT;
cl_git_mkfile(TEST_CONFIG, "");
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
cl_git_pass(git_config_set_string(config, "color.ui", "auto"));
cl_git_pass(git_config_set_string(config, "core.editor", "ed"));
git_config_free(config);
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
cl_git_pass(git_config_get_string_buf(&buf, config, "color.ui"));
cl_assert_equal_s("auto", git_buf_cstr(&buf));
git_buf_clear(&buf);
cl_git_pass(git_config_get_string_buf(&buf, config, "core.editor"));
cl_assert_equal_s("ed", git_buf_cstr(&buf));
git_buf_dispose(&buf);
git_config_free(config);
cl_must_pass(p_unlink(TEST_CONFIG));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/backend.c
|
#include "clar_libgit2.h"
#include "git2/sys/config.h"
void test_config_backend__checks_version(void)
{
git_config *cfg;
git_config_backend backend = GIT_CONFIG_BACKEND_INIT;
const git_error *err;
backend.version = 1024;
cl_git_pass(git_config_new(&cfg));
cl_git_fail(git_config_add_backend(cfg, &backend, 0, NULL, false));
err = git_error_last();
cl_assert_equal_i(GIT_ERROR_INVALID, err->klass);
git_error_clear();
backend.version = 1024;
cl_git_fail(git_config_add_backend(cfg, &backend, 0, NULL, false));
err = git_error_last();
cl_assert_equal_i(GIT_ERROR_INVALID, err->klass);
git_config_free(cfg);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/rename.c
|
#include "clar_libgit2.h"
#include "config.h"
static git_repository *g_repo = NULL;
static git_config *g_config = NULL;
void test_config_rename__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_repository_config(&g_config, g_repo));
}
void test_config_rename__cleanup(void)
{
git_config_free(g_config);
g_config = NULL;
cl_git_sandbox_cleanup();
g_repo = NULL;
}
void test_config_rename__can_rename(void)
{
git_config_entry *ce;
cl_git_pass(git_config_get_entry(
&ce, g_config, "branch.track-local.remote"));
cl_assert_equal_s(".", ce->value);
git_config_entry_free(ce);
cl_git_fail(git_config_get_entry(
&ce, g_config, "branch.local-track.remote"));
cl_git_pass(git_config_rename_section(
g_repo, "branch.track-local", "branch.local-track"));
cl_git_pass(git_config_get_entry(
&ce, g_config, "branch.local-track.remote"));
cl_assert_equal_s(".", ce->value);
git_config_entry_free(ce);
cl_git_fail(git_config_get_entry(
&ce, g_config, "branch.track-local.remote"));
}
void test_config_rename__prevent_overwrite(void)
{
git_config_entry *ce;
cl_git_pass(git_config_set_string(
g_config, "branch.local-track.remote", "yellow"));
cl_git_pass(git_config_get_entry(
&ce, g_config, "branch.local-track.remote"));
cl_assert_equal_s("yellow", ce->value);
git_config_entry_free(ce);
cl_git_pass(git_config_rename_section(
g_repo, "branch.track-local", "branch.local-track"));
cl_git_pass(git_config_get_entry(
&ce, g_config, "branch.local-track.remote"));
cl_assert_equal_s(".", ce->value);
git_config_entry_free(ce);
/* so, we don't currently prevent overwrite... */
/* {
const git_error *err;
cl_assert((err = git_error_last()) != NULL);
cl_assert(err->message != NULL);
} */
}
static void assert_invalid_config_section_name(
git_repository *repo, const char *name)
{
cl_git_fail_with(
git_config_rename_section(repo, "branch.remoteless", name),
GIT_EINVALIDSPEC);
}
void test_config_rename__require_a_valid_new_name(void)
{
assert_invalid_config_section_name(g_repo, "");
assert_invalid_config_section_name(g_repo, "bra\nch");
assert_invalid_config_section_name(g_repo, "branc#");
assert_invalid_config_section_name(g_repo, "bra\nch.duh");
assert_invalid_config_section_name(g_repo, "branc#.duh");
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/add.c
|
#include "clar_libgit2.h"
void test_config_add__initialize(void)
{
cl_fixture_sandbox("config/config10");
}
void test_config_add__cleanup(void)
{
cl_fixture_cleanup("config10");
}
void test_config_add__to_existing_section(void)
{
git_config *cfg;
int32_t i;
cl_git_pass(git_config_open_ondisk(&cfg, "config10"));
cl_git_pass(git_config_set_int32(cfg, "empty.tmp", 5));
cl_git_pass(git_config_get_int32(&i, cfg, "empty.tmp"));
cl_assert(i == 5);
cl_git_pass(git_config_delete_entry(cfg, "empty.tmp"));
git_config_free(cfg);
}
void test_config_add__to_new_section(void)
{
git_config *cfg;
int32_t i;
cl_git_pass(git_config_open_ondisk(&cfg, "config10"));
cl_git_pass(git_config_set_int32(cfg, "section.tmp", 5));
cl_git_pass(git_config_get_int32(&i, cfg, "section.tmp"));
cl_assert(i == 5);
cl_git_pass(git_config_delete_entry(cfg, "section.tmp"));
git_config_free(cfg);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/config/memory.c
|
#include "clar_libgit2.h"
#include "config_backend.h"
static git_config_backend *backend;
void test_config_memory__initialize(void)
{
backend = NULL;
}
void test_config_memory__cleanup(void)
{
git_config_backend_free(backend);
}
static void assert_config_contains(git_config_backend *backend,
const char *name, const char *value)
{
git_config_entry *entry;
cl_git_pass(git_config_backend_get_string(&entry, backend, name));
cl_assert_equal_s(entry->value, value);
}
struct expected_entry {
const char *name;
const char *value;
int seen;
};
static int contains_all_cb(const git_config_entry *entry, void *payload)
{
struct expected_entry *entries = (struct expected_entry *) payload;
int i;
for (i = 0; entries[i].name; i++) {
if (strcmp(entries[i].name, entry->name) ||
strcmp(entries[i].value , entry->value))
continue;
if (entries[i].seen)
cl_fail("Entry seen more than once");
entries[i].seen = 1;
return 0;
}
cl_fail("Unexpected entry");
return -1;
}
static void assert_config_contains_all(git_config_backend *backend,
struct expected_entry *entries)
{
int i;
cl_git_pass(git_config_backend_foreach(backend, contains_all_cb, entries));
for (i = 0; entries[i].name; i++)
cl_assert(entries[i].seen);
}
static void setup_backend(const char *cfg)
{
cl_git_pass(git_config_backend_from_string(&backend, cfg, strlen(cfg)));
cl_git_pass(git_config_backend_open(backend, 0, NULL));
}
void test_config_memory__write_operations_fail(void)
{
setup_backend("");
cl_git_fail(git_config_backend_set_string(backend, "general.foo", "var"));
cl_git_fail(git_config_backend_delete(backend, "general.foo"));
cl_git_fail(git_config_backend_lock(backend));
cl_git_fail(git_config_backend_unlock(backend, 0));
}
void test_config_memory__simple(void)
{
setup_backend(
"[general]\n"
"foo=bar\n");
assert_config_contains(backend, "general.foo", "bar");
}
void test_config_memory__malformed_fails_to_open(void)
{
const char *cfg =
"[general\n"
"foo=bar\n";
cl_git_pass(git_config_backend_from_string(&backend, cfg, strlen(cfg)));
cl_git_fail(git_config_backend_open(backend, 0, NULL));
}
void test_config_memory__multiple_vars(void)
{
setup_backend(
"[general]\n"
"foo=bar\n"
"key=value\n");
assert_config_contains(backend, "general.foo", "bar");
assert_config_contains(backend, "general.key", "value");
}
void test_config_memory__multiple_sections(void)
{
setup_backend(
"[general]\n"
"foo=bar\n"
"\n"
"[other]\n"
"key=value\n");
assert_config_contains(backend, "general.foo", "bar");
assert_config_contains(backend, "other.key", "value");
}
void test_config_memory__multivar_gets_correct_string(void)
{
setup_backend(
"[general]\n"
"foo=bar1\n"
"foo=bar2\n");
assert_config_contains(backend, "general.foo", "bar2");
}
void test_config_memory__foreach_sees_multivar(void)
{
struct expected_entry entries[] = {
{ "general.foo", "bar1", 0 },
{ "general.foo", "bar2", 0 },
{ NULL, NULL, 0 },
};
setup_backend(
"[general]\n"
"foo=bar1\n"
"foo=bar2\n");
assert_config_contains_all(backend, entries);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/path/dotgit.c
|
#include "clar_libgit2.h"
#include "path.h"
static char *gitmodules_altnames[] = {
".gitmodules",
/*
* Equivalent to the ".git\u200cmodules" string from git but hard-coded
* as a UTF-8 sequence
*/
".git\xe2\x80\x8cmodules",
".Gitmodules",
".gitmoduleS",
".gitmodules ",
".gitmodules.",
".gitmodules ",
".gitmodules. ",
".gitmodules .",
".gitmodules..",
".gitmodules ",
".gitmodules. ",
".gitmodules . ",
".gitmodules .",
".Gitmodules ",
".Gitmodules.",
".Gitmodules ",
".Gitmodules. ",
".Gitmodules .",
".Gitmodules..",
".Gitmodules ",
".Gitmodules. ",
".Gitmodules . ",
".Gitmodules .",
"GITMOD~1",
"gitmod~1",
"GITMOD~2",
"gitmod~3",
"GITMOD~4",
"GITMOD~1 ",
"gitmod~2.",
"GITMOD~3 ",
"gitmod~4. ",
"GITMOD~1 .",
"gitmod~2 ",
"GITMOD~3. ",
"gitmod~4 . ",
"GI7EBA~1",
"gi7eba~9",
"GI7EB~10",
"GI7EB~11",
"GI7EB~99",
"GI7EB~10",
"GI7E~100",
"GI7E~101",
"GI7E~999",
"~1000000",
"~9999999",
};
static char *gitmodules_not_altnames[] = {
".gitmodules x",
".gitmodules .x",
" .gitmodules",
"..gitmodules",
"gitmodules",
".gitmodule",
".gitmodules x ",
".gitmodules .x",
"GI7EBA~",
"GI7EBA~0",
"GI7EBA~~1",
"GI7EBA~X",
"Gx7EBA~1",
"GI7EBX~1",
"GI7EB~1",
"GI7EB~01",
"GI7EB~1",
};
void test_path_dotgit__dotgit_modules(void)
{
size_t i;
cl_assert_equal_i(1, git_path_is_gitfile(".gitmodules", strlen(".gitmodules"), GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_GENERIC));
cl_assert_equal_i(1, git_path_is_gitfile(".git\xe2\x80\x8cmodules", strlen(".git\xe2\x80\x8cmodules"), GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_GENERIC));
for (i = 0; i < ARRAY_SIZE(gitmodules_altnames); i++) {
const char *name = gitmodules_altnames[i];
if (!git_path_is_gitfile(name, strlen(name), GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_GENERIC))
cl_fail(name);
}
for (i = 0; i < ARRAY_SIZE(gitmodules_not_altnames); i++) {
const char *name = gitmodules_not_altnames[i];
if (git_path_is_gitfile(name, strlen(name), GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_GENERIC))
cl_fail(name);
}
}
void test_path_dotgit__dotgit_modules_symlink(void)
{
cl_assert_equal_b(true, git_path_validate(NULL, ".gitmodules", 0, GIT_PATH_REJECT_DOT_GIT_HFS|GIT_PATH_REJECT_DOT_GIT_NTFS));
cl_assert_equal_b(false, git_path_validate(NULL, ".gitmodules", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(false, git_path_validate(NULL, ".gitmodules", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS));
cl_assert_equal_b(false, git_path_validate(NULL, ".gitmodules . .::$DATA", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/path/win32.c
|
#include "clar_libgit2.h"
#include "path.h"
#ifdef GIT_WIN32
#include "win32/path_w32.h"
#endif
void test_utf8_to_utf16(const char *utf8_in, const wchar_t *utf16_expected)
{
#ifdef GIT_WIN32
git_win32_path path_utf16;
int path_utf16len;
cl_assert((path_utf16len = git_win32_path_from_utf8(path_utf16, utf8_in)) >= 0);
cl_assert_equal_wcs(utf16_expected, path_utf16);
cl_assert_equal_i(wcslen(utf16_expected), path_utf16len);
#else
GIT_UNUSED(utf8_in);
GIT_UNUSED(utf16_expected);
#endif
}
void test_utf8_to_utf16_relative(const char* utf8_in, const wchar_t* utf16_expected)
{
#ifdef GIT_WIN32
git_win32_path path_utf16;
int path_utf16len;
cl_assert((path_utf16len = git_win32_path_relative_from_utf8(path_utf16, utf8_in)) >= 0);
cl_assert_equal_wcs(utf16_expected, path_utf16);
cl_assert_equal_i(wcslen(utf16_expected), path_utf16len);
#else
GIT_UNUSED(utf8_in);
GIT_UNUSED(utf16_expected);
#endif
}
void test_path_win32__utf8_to_utf16(void)
{
#ifdef GIT_WIN32
test_utf8_to_utf16("C:\\", L"\\\\?\\C:\\");
test_utf8_to_utf16("c:\\", L"\\\\?\\c:\\");
test_utf8_to_utf16("C:/", L"\\\\?\\C:\\");
test_utf8_to_utf16("c:/", L"\\\\?\\c:\\");
#endif
}
void test_path_win32__removes_trailing_slash(void)
{
#ifdef GIT_WIN32
test_utf8_to_utf16("C:\\Foo\\", L"\\\\?\\C:\\Foo");
test_utf8_to_utf16("C:\\Foo\\\\", L"\\\\?\\C:\\Foo");
test_utf8_to_utf16("C:\\Foo\\\\", L"\\\\?\\C:\\Foo");
test_utf8_to_utf16("C:/Foo/", L"\\\\?\\C:\\Foo");
test_utf8_to_utf16("C:/Foo///", L"\\\\?\\C:\\Foo");
#endif
}
void test_path_win32__squashes_multiple_slashes(void)
{
#ifdef GIT_WIN32
test_utf8_to_utf16("C:\\\\Foo\\Bar\\\\Foobar", L"\\\\?\\C:\\Foo\\Bar\\Foobar");
test_utf8_to_utf16("C://Foo/Bar///Foobar", L"\\\\?\\C:\\Foo\\Bar\\Foobar");
#endif
}
void test_path_win32__unc(void)
{
#ifdef GIT_WIN32
test_utf8_to_utf16("\\\\server\\c$\\unc\\path", L"\\\\?\\UNC\\server\\c$\\unc\\path");
test_utf8_to_utf16("//server/git/style/unc/path", L"\\\\?\\UNC\\server\\git\\style\\unc\\path");
#endif
}
void test_path_win32__honors_max_path(void)
{
#ifdef GIT_WIN32
git_win32_path path_utf16;
test_utf8_to_utf16("C:\\This path is 261 characters which is fine for our path handling functions which cope with paths longer than MAX_PATH\\0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghijk",
L"\\\\?\\C:\\This path is 261 characters which is fine for our path handling functions which cope with paths longer than MAX_PATH\\0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghijk");
cl_check_fail(git_win32_path_from_utf8(path_utf16, "C:\\This path is 4097 chars and exceeds our maximum path length on Windows which is limited to 4096 characters\\alas\\0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij01"));
#endif
}
void test_path_win32__dot_and_dotdot(void)
{
#ifdef GIT_WIN32
test_utf8_to_utf16("C:\\Foo\\..\\Foobar", L"\\\\?\\C:\\Foobar");
test_utf8_to_utf16("C:\\Foo\\Bar\\..\\Foobar", L"\\\\?\\C:\\Foo\\Foobar");
test_utf8_to_utf16("C:\\Foo\\Bar\\..\\Foobar\\..", L"\\\\?\\C:\\Foo");
test_utf8_to_utf16("C:\\Foobar\\..", L"\\\\?\\C:\\");
test_utf8_to_utf16("C:/Foo/Bar/../Foobar", L"\\\\?\\C:\\Foo\\Foobar");
test_utf8_to_utf16("C:/Foo/Bar/../Foobar/../Asdf/", L"\\\\?\\C:\\Foo\\Asdf");
test_utf8_to_utf16("C:/Foo/Bar/../Foobar/..", L"\\\\?\\C:\\Foo");
test_utf8_to_utf16("C:/Foo/..", L"\\\\?\\C:\\");
test_utf8_to_utf16("C:\\Foo\\Bar\\.\\Foobar", L"\\\\?\\C:\\Foo\\Bar\\Foobar");
test_utf8_to_utf16("C:\\.\\Foo\\.\\Bar\\.\\Foobar\\.\\", L"\\\\?\\C:\\Foo\\Bar\\Foobar");
test_utf8_to_utf16("C:/Foo/Bar/./Foobar", L"\\\\?\\C:\\Foo\\Bar\\Foobar");
test_utf8_to_utf16("C:/Foo/../Bar/./Foobar/../", L"\\\\?\\C:\\Bar");
test_utf8_to_utf16("C:\\Foo\\..\\..\\Bar", L"\\\\?\\C:\\Bar");
#endif
}
void test_path_win32__absolute_from_no_drive_letter(void)
{
#ifdef GIT_WIN32
test_utf8_to_utf16("\\Foo", L"\\\\?\\C:\\Foo");
test_utf8_to_utf16("\\Foo\\Bar", L"\\\\?\\C:\\Foo\\Bar");
test_utf8_to_utf16("/Foo/Bar", L"\\\\?\\C:\\Foo\\Bar");
#endif
}
void test_path_win32__absolute_from_relative(void)
{
#ifdef GIT_WIN32
char cwd_backup[MAX_PATH];
cl_must_pass(p_getcwd(cwd_backup, MAX_PATH));
cl_must_pass(p_chdir("C:/"));
test_utf8_to_utf16("Foo", L"\\\\?\\C:\\Foo");
test_utf8_to_utf16("..\\..\\Foo", L"\\\\?\\C:\\Foo");
test_utf8_to_utf16("Foo\\..", L"\\\\?\\C:\\");
test_utf8_to_utf16("Foo\\..\\..", L"\\\\?\\C:\\");
test_utf8_to_utf16("", L"\\\\?\\C:\\");
cl_must_pass(p_chdir("C:/Windows"));
test_utf8_to_utf16("Foo", L"\\\\?\\C:\\Windows\\Foo");
test_utf8_to_utf16("Foo\\Bar", L"\\\\?\\C:\\Windows\\Foo\\Bar");
test_utf8_to_utf16("..\\Foo", L"\\\\?\\C:\\Foo");
test_utf8_to_utf16("Foo\\..\\Bar", L"\\\\?\\C:\\Windows\\Bar");
test_utf8_to_utf16("", L"\\\\?\\C:\\Windows");
cl_must_pass(p_chdir(cwd_backup));
#endif
}
void test_path_win32__keeps_relative(void)
{
#ifdef GIT_WIN32
/* Relative paths stay relative */
test_utf8_to_utf16_relative("Foo", L"Foo");
test_utf8_to_utf16_relative("..\\..\\Foo", L"..\\..\\Foo");
test_utf8_to_utf16_relative("Foo\\..", L"Foo\\..");
test_utf8_to_utf16_relative("Foo\\..\\..", L"Foo\\..\\..");
test_utf8_to_utf16_relative("Foo\\Bar", L"Foo\\Bar");
test_utf8_to_utf16_relative("Foo\\..\\Bar", L"Foo\\..\\Bar");
test_utf8_to_utf16_relative("../../Foo", L"..\\..\\Foo");
test_utf8_to_utf16_relative("Foo/..", L"Foo\\..");
test_utf8_to_utf16_relative("Foo/../..", L"Foo\\..\\..");
test_utf8_to_utf16_relative("Foo/Bar", L"Foo\\Bar");
test_utf8_to_utf16_relative("Foo/../Bar", L"Foo\\..\\Bar");
test_utf8_to_utf16_relative("Foo/../Bar/", L"Foo\\..\\Bar\\");
test_utf8_to_utf16_relative("", L"");
/* Absolute paths are canonicalized */
test_utf8_to_utf16_relative("\\Foo", L"\\\\?\\C:\\Foo");
test_utf8_to_utf16_relative("/Foo/Bar/", L"\\\\?\\C:\\Foo\\Bar");
test_utf8_to_utf16_relative("\\\\server\\c$\\unc\\path", L"\\\\?\\UNC\\server\\c$\\unc\\path");
#endif
}
#ifdef GIT_WIN32
static void test_canonicalize(const wchar_t *in, const wchar_t *expected)
{
git_win32_path canonical;
cl_assert(wcslen(in) < MAX_PATH);
wcscpy(canonical, in);
cl_must_pass(git_win32_path_canonicalize(canonical));
cl_assert_equal_wcs(expected, canonical);
}
#endif
static void test_remove_namespace(const wchar_t *in, const wchar_t *expected)
{
#ifdef GIT_WIN32
git_win32_path canonical;
cl_assert(wcslen(in) < MAX_PATH);
wcscpy(canonical, in);
git_win32_path_remove_namespace(canonical, wcslen(in));
cl_assert_equal_wcs(expected, canonical);
#else
GIT_UNUSED(in);
GIT_UNUSED(expected);
#endif
}
void test_path_win32__remove_namespace(void)
{
test_remove_namespace(L"\\\\?\\C:\\Temp\\Foo", L"C:\\Temp\\Foo");
test_remove_namespace(L"\\\\?\\C:\\", L"C:\\");
test_remove_namespace(L"\\\\?\\", L"");
test_remove_namespace(L"\\??\\C:\\Temp\\Foo", L"C:\\Temp\\Foo");
test_remove_namespace(L"\\??\\C:\\", L"C:\\");
test_remove_namespace(L"\\??\\", L"");
test_remove_namespace(L"\\\\?\\UNC\\server\\C$\\folder", L"\\\\server\\C$\\folder");
test_remove_namespace(L"\\\\?\\UNC\\server\\C$\\folder", L"\\\\server\\C$\\folder");
test_remove_namespace(L"\\\\?\\UNC\\server\\C$", L"\\\\server\\C$");
test_remove_namespace(L"\\\\?\\UNC\\server\\", L"\\\\server");
test_remove_namespace(L"\\\\?\\UNC\\server", L"\\\\server");
test_remove_namespace(L"\\??\\UNC\\server\\C$\\folder", L"\\\\server\\C$\\folder");
test_remove_namespace(L"\\??\\UNC\\server\\C$\\folder", L"\\\\server\\C$\\folder");
test_remove_namespace(L"\\??\\UNC\\server\\C$", L"\\\\server\\C$");
test_remove_namespace(L"\\??\\UNC\\server\\", L"\\\\server");
test_remove_namespace(L"\\??\\UNC\\server", L"\\\\server");
test_remove_namespace(L"\\\\server\\C$\\folder", L"\\\\server\\C$\\folder");
test_remove_namespace(L"\\\\server\\C$", L"\\\\server\\C$");
test_remove_namespace(L"\\\\server\\", L"\\\\server");
test_remove_namespace(L"\\\\server", L"\\\\server");
test_remove_namespace(L"C:\\Foo\\Bar", L"C:\\Foo\\Bar");
test_remove_namespace(L"C:\\", L"C:\\");
test_remove_namespace(L"", L"");
}
void test_path_win32__canonicalize(void)
{
#ifdef GIT_WIN32
test_canonicalize(L"C:\\Foo\\Bar", L"C:\\Foo\\Bar");
test_canonicalize(L"C:\\Foo\\", L"C:\\Foo");
test_canonicalize(L"C:\\Foo\\\\", L"C:\\Foo");
test_canonicalize(L"C:\\Foo\\..\\Bar", L"C:\\Bar");
test_canonicalize(L"C:\\Foo\\..\\..\\Bar", L"C:\\Bar");
test_canonicalize(L"C:\\Foo\\..\\..\\..\\..\\", L"C:\\");
test_canonicalize(L"C:/Foo/Bar", L"C:\\Foo\\Bar");
test_canonicalize(L"C:/", L"C:\\");
test_canonicalize(L"\\\\?\\C:\\Foo\\Bar", L"\\\\?\\C:\\Foo\\Bar");
test_canonicalize(L"\\\\?\\C:\\Foo\\Bar\\", L"\\\\?\\C:\\Foo\\Bar");
test_canonicalize(L"\\\\?\\C:\\\\Foo\\.\\Bar\\\\..\\", L"\\\\?\\C:\\Foo");
test_canonicalize(L"\\\\?\\C:\\\\", L"\\\\?\\C:\\");
test_canonicalize(L"//?/C:/", L"\\\\?\\C:\\");
test_canonicalize(L"//?/C:/../../Foo/", L"\\\\?\\C:\\Foo");
test_canonicalize(L"//?/C:/Foo/../../", L"\\\\?\\C:\\");
test_canonicalize(L"\\\\?\\UNC\\server\\C$\\folder", L"\\\\?\\UNC\\server\\C$\\folder");
test_canonicalize(L"\\\\?\\UNC\\server\\C$\\folder\\", L"\\\\?\\UNC\\server\\C$\\folder");
test_canonicalize(L"\\\\?\\UNC\\server\\C$\\folder\\", L"\\\\?\\UNC\\server\\C$\\folder");
test_canonicalize(L"\\\\?\\UNC\\server\\C$\\folder\\..\\..\\..\\..\\share\\", L"\\\\?\\UNC\\server\\share");
test_canonicalize(L"\\\\server\\share", L"\\\\server\\share");
test_canonicalize(L"\\\\server\\share\\", L"\\\\server\\share");
test_canonicalize(L"\\\\server\\share\\\\foo\\\\bar", L"\\\\server\\share\\foo\\bar");
test_canonicalize(L"\\\\server\\\\share\\\\foo\\\\bar", L"\\\\server\\share\\foo\\bar");
test_canonicalize(L"\\\\server\\share\\..\\foo", L"\\\\server\\foo");
test_canonicalize(L"\\\\server\\..\\..\\share\\.\\foo", L"\\\\server\\share\\foo");
#endif
}
void test_path_win32__8dot3_name(void)
{
#ifdef GIT_WIN32
char *shortname;
if (!cl_sandbox_supports_8dot3())
clar__skip();
/* Some guaranteed short names */
cl_assert_equal_s("PROGRA~1", (shortname = git_win32_path_8dot3_name("C:\\Program Files")));
git__free(shortname);
cl_assert_equal_s("WINDOWS", (shortname = git_win32_path_8dot3_name("C:\\WINDOWS")));
git__free(shortname);
/* Create some predictible short names */
cl_must_pass(p_mkdir(".foo", 0777));
cl_assert_equal_s("FOO~1", (shortname = git_win32_path_8dot3_name(".foo")));
git__free(shortname);
cl_git_write2file("bar~1", "foobar\n", 7, O_RDWR|O_CREAT, 0666);
cl_must_pass(p_mkdir(".bar", 0777));
cl_assert_equal_s("BAR~2", (shortname = git_win32_path_8dot3_name(".bar")));
git__free(shortname);
#endif
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/path/core.c
|
#include "clar_libgit2.h"
#include "path.h"
void test_path_core__cleanup(void)
{
cl_git_sandbox_cleanup();
}
static void test_make_relative(
const char *expected_path,
const char *path,
const char *parent,
int expected_status)
{
git_buf buf = GIT_BUF_INIT;
git_buf_puts(&buf, path);
cl_assert_equal_i(expected_status, git_path_make_relative(&buf, parent));
cl_assert_equal_s(expected_path, buf.ptr);
git_buf_dispose(&buf);
}
void test_path_core__make_relative(void)
{
test_make_relative("foo.c", "/path/to/foo.c", "/path/to", 0);
test_make_relative("bar/foo.c", "/path/to/bar/foo.c", "/path/to", 0);
test_make_relative("foo.c", "/path/to/foo.c", "/path/to/", 0);
test_make_relative("", "/path/to", "/path/to", 0);
test_make_relative("", "/path/to", "/path/to/", 0);
test_make_relative("../", "/path/to", "/path/to/foo", 0);
test_make_relative("../foo.c", "/path/to/foo.c", "/path/to/bar", 0);
test_make_relative("../bar/foo.c", "/path/to/bar/foo.c", "/path/to/baz", 0);
test_make_relative("../../foo.c", "/path/to/foo.c", "/path/to/foo/bar", 0);
test_make_relative("../../foo/bar.c", "/path/to/foo/bar.c", "/path/to/bar/foo", 0);
test_make_relative("../../foo.c", "/foo.c", "/bar/foo", 0);
test_make_relative("foo.c", "/path/to/foo.c", "/path/to/", 0);
test_make_relative("../foo.c", "/path/to/foo.c", "/path/to/bar/", 0);
test_make_relative("foo.c", "d:/path/to/foo.c", "d:/path/to", 0);
test_make_relative("../foo", "/foo", "/bar", 0);
test_make_relative("path/to/foo.c", "/path/to/foo.c", "/", 0);
test_make_relative("../foo", "path/to/foo", "path/to/bar", 0);
test_make_relative("/path/to/foo.c", "/path/to/foo.c", "d:/path/to", GIT_ENOTFOUND);
test_make_relative("d:/path/to/foo.c", "d:/path/to/foo.c", "/path/to", GIT_ENOTFOUND);
test_make_relative("/path/to/foo.c", "/path/to/foo.c", "not-a-rooted-path", GIT_ENOTFOUND);
test_make_relative("not-a-rooted-path", "not-a-rooted-path", "/path/to", GIT_ENOTFOUND);
test_make_relative("/path", "/path", "pathtofoo", GIT_ENOTFOUND);
test_make_relative("path", "path", "pathtofoo", GIT_ENOTFOUND);
}
void test_path_core__isvalid_standard(void)
{
cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar/file.txt", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar/.file", 0, 0));
}
void test_path_core__isvalid_empty_dir_component(void)
{
cl_assert_equal_b(false, git_path_validate(NULL, "foo//bar", 0, 0));
/* leading slash */
cl_assert_equal_b(false, git_path_validate(NULL, "/", 0, 0));
cl_assert_equal_b(false, git_path_validate(NULL, "/foo", 0, 0));
cl_assert_equal_b(false, git_path_validate(NULL, "/foo/bar", 0, 0));
/* trailing slash */
cl_assert_equal_b(false, git_path_validate(NULL, "foo/", 0, 0));
cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar/", 0, 0));
}
void test_path_core__isvalid_dot_and_dotdot(void)
{
cl_assert_equal_b(true, git_path_validate(NULL, ".", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "./foo", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo/.", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "./foo", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "..", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "../foo", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo/..", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "../foo", 0, 0));
cl_assert_equal_b(false, git_path_validate(NULL, ".", 0, GIT_PATH_REJECT_TRAVERSAL));
cl_assert_equal_b(false, git_path_validate(NULL, "./foo", 0, GIT_PATH_REJECT_TRAVERSAL));
cl_assert_equal_b(false, git_path_validate(NULL, "foo/.", 0, GIT_PATH_REJECT_TRAVERSAL));
cl_assert_equal_b(false, git_path_validate(NULL, "./foo", 0, GIT_PATH_REJECT_TRAVERSAL));
cl_assert_equal_b(false, git_path_validate(NULL, "..", 0, GIT_PATH_REJECT_TRAVERSAL));
cl_assert_equal_b(false, git_path_validate(NULL, "../foo", 0, GIT_PATH_REJECT_TRAVERSAL));
cl_assert_equal_b(false, git_path_validate(NULL, "foo/..", 0, GIT_PATH_REJECT_TRAVERSAL));
cl_assert_equal_b(false, git_path_validate(NULL, "../foo", 0, GIT_PATH_REJECT_TRAVERSAL));
}
void test_path_core__isvalid_dot_git(void)
{
cl_assert_equal_b(true, git_path_validate(NULL, ".git", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, ".git/foo", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo/.git", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo/.git/bar", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo/.GIT/bar", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar/.Git", 0, 0));
cl_assert_equal_b(false, git_path_validate(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
cl_assert_equal_b(false, git_path_validate(NULL, ".git/foo", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
cl_assert_equal_b(false, git_path_validate(NULL, "foo/.git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
cl_assert_equal_b(false, git_path_validate(NULL, "foo/.git/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
cl_assert_equal_b(false, git_path_validate(NULL, "foo/.GIT/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar/.Git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL));
cl_assert_equal_b(true, git_path_validate(NULL, "!git", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo/!git", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "!git/bar", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, ".tig", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo/.tig", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, ".tig/bar", 0, 0));
}
void test_path_core__isvalid_backslash(void)
{
cl_assert_equal_b(true, git_path_validate(NULL, "foo\\file.txt", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar\\file.txt", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar\\", 0, 0));
cl_assert_equal_b(false, git_path_validate(NULL, "foo\\file.txt", 0, GIT_PATH_REJECT_BACKSLASH));
cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar\\file.txt", 0, GIT_PATH_REJECT_BACKSLASH));
cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar\\", 0, GIT_PATH_REJECT_BACKSLASH));
}
void test_path_core__isvalid_trailing_dot(void)
{
cl_assert_equal_b(true, git_path_validate(NULL, "foo.", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo...", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar.", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo./bar", 0, 0));
cl_assert_equal_b(false, git_path_validate(NULL, "foo.", 0, GIT_PATH_REJECT_TRAILING_DOT));
cl_assert_equal_b(false, git_path_validate(NULL, "foo...", 0, GIT_PATH_REJECT_TRAILING_DOT));
cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar.", 0, GIT_PATH_REJECT_TRAILING_DOT));
cl_assert_equal_b(false, git_path_validate(NULL, "foo./bar", 0, GIT_PATH_REJECT_TRAILING_DOT));
}
void test_path_core__isvalid_trailing_space(void)
{
cl_assert_equal_b(true, git_path_validate(NULL, "foo ", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo ", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar ", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, " ", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo /bar", 0, 0));
cl_assert_equal_b(false, git_path_validate(NULL, "foo ", 0, GIT_PATH_REJECT_TRAILING_SPACE));
cl_assert_equal_b(false, git_path_validate(NULL, "foo ", 0, GIT_PATH_REJECT_TRAILING_SPACE));
cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar ", 0, GIT_PATH_REJECT_TRAILING_SPACE));
cl_assert_equal_b(false, git_path_validate(NULL, " ", 0, GIT_PATH_REJECT_TRAILING_SPACE));
cl_assert_equal_b(false, git_path_validate(NULL, "foo /bar", 0, GIT_PATH_REJECT_TRAILING_SPACE));
}
void test_path_core__isvalid_trailing_colon(void)
{
cl_assert_equal_b(true, git_path_validate(NULL, "foo:", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar:", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, ":", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "foo:/bar", 0, 0));
cl_assert_equal_b(false, git_path_validate(NULL, "foo:", 0, GIT_PATH_REJECT_TRAILING_COLON));
cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar:", 0, GIT_PATH_REJECT_TRAILING_COLON));
cl_assert_equal_b(false, git_path_validate(NULL, ":", 0, GIT_PATH_REJECT_TRAILING_COLON));
cl_assert_equal_b(false, git_path_validate(NULL, "foo:/bar", 0, GIT_PATH_REJECT_TRAILING_COLON));
}
void test_path_core__isvalid_dotgit_ntfs(void)
{
cl_assert_equal_b(true, git_path_validate(NULL, ".git", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, ".git ", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, ".git.", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, ".git.. .", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "git~1", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "git~1 ", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "git~1.", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "git~1.. .", 0, 0));
cl_assert_equal_b(false, git_path_validate(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
cl_assert_equal_b(false, git_path_validate(NULL, ".git ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
cl_assert_equal_b(false, git_path_validate(NULL, ".git.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
cl_assert_equal_b(false, git_path_validate(NULL, ".git.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
cl_assert_equal_b(false, git_path_validate(NULL, "git~1", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
cl_assert_equal_b(false, git_path_validate(NULL, "git~1 ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
cl_assert_equal_b(false, git_path_validate(NULL, "git~1.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
cl_assert_equal_b(false, git_path_validate(NULL, "git~1.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS));
}
void test_path_core__isvalid_dos_paths(void)
{
cl_assert_equal_b(true, git_path_validate(NULL, "aux", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "aux.", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "aux:", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "aux.asdf", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "aux.asdf\\zippy", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "aux:asdf\\foobar", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "con", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "prn", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "nul", 0, 0));
cl_assert_equal_b(false, git_path_validate(NULL, "aux", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_validate(NULL, "aux.", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_validate(NULL, "aux:", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_validate(NULL, "aux.asdf", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_validate(NULL, "aux.asdf\\zippy", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_validate(NULL, "aux:asdf\\foobar", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_validate(NULL, "con", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_validate(NULL, "prn", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_validate(NULL, "nul", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(true, git_path_validate(NULL, "aux1", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "aux1", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(true, git_path_validate(NULL, "auxn", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(true, git_path_validate(NULL, "aux\\foo", 0, GIT_PATH_REJECT_DOS_PATHS));
}
void test_path_core__isvalid_dos_paths_withnum(void)
{
cl_assert_equal_b(true, git_path_validate(NULL, "com1", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "com1.", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "com1:", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "com1.asdf", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "com1.asdf\\zippy", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "com1:asdf\\foobar", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "com1\\foo", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "lpt1", 0, 0));
cl_assert_equal_b(false, git_path_validate(NULL, "com1", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_validate(NULL, "com1.", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_validate(NULL, "com1:", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_validate(NULL, "com1.asdf", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_validate(NULL, "com1.asdf\\zippy", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_validate(NULL, "com1:asdf\\foobar", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_validate(NULL, "com1/foo", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(false, git_path_validate(NULL, "lpt1", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(true, git_path_validate(NULL, "com0", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "com0", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(true, git_path_validate(NULL, "com10", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "com10", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(true, git_path_validate(NULL, "comn", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(true, git_path_validate(NULL, "com1\\foo", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(true, git_path_validate(NULL, "lpt0", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(true, git_path_validate(NULL, "lpt10", 0, GIT_PATH_REJECT_DOS_PATHS));
cl_assert_equal_b(true, git_path_validate(NULL, "lptn", 0, GIT_PATH_REJECT_DOS_PATHS));
}
void test_path_core__isvalid_nt_chars(void)
{
cl_assert_equal_b(true, git_path_validate(NULL, "asdf\001foo", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "asdf\037bar", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "asdf<bar", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "asdf>foo", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "asdf:foo", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "asdf\"bar", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "asdf|foo", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "asdf?bar", 0, 0));
cl_assert_equal_b(true, git_path_validate(NULL, "asdf*bar", 0, 0));
cl_assert_equal_b(false, git_path_validate(NULL, "asdf\001foo", 0, GIT_PATH_REJECT_NT_CHARS));
cl_assert_equal_b(false, git_path_validate(NULL, "asdf\037bar", 0, GIT_PATH_REJECT_NT_CHARS));
cl_assert_equal_b(false, git_path_validate(NULL, "asdf<bar", 0, GIT_PATH_REJECT_NT_CHARS));
cl_assert_equal_b(false, git_path_validate(NULL, "asdf>foo", 0, GIT_PATH_REJECT_NT_CHARS));
cl_assert_equal_b(false, git_path_validate(NULL, "asdf:foo", 0, GIT_PATH_REJECT_NT_CHARS));
cl_assert_equal_b(false, git_path_validate(NULL, "asdf\"bar", 0, GIT_PATH_REJECT_NT_CHARS));
cl_assert_equal_b(false, git_path_validate(NULL, "asdf|foo", 0, GIT_PATH_REJECT_NT_CHARS));
cl_assert_equal_b(false, git_path_validate(NULL, "asdf?bar", 0, GIT_PATH_REJECT_NT_CHARS));
cl_assert_equal_b(false, git_path_validate(NULL, "asdf*bar", 0, GIT_PATH_REJECT_NT_CHARS));
}
void test_path_core__isvalid_dotgit_with_hfs_ignorables(void)
{
cl_assert_equal_b(false, git_path_validate(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(false, git_path_validate(NULL, ".git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(false, git_path_validate(NULL, ".gi\xe2\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(false, git_path_validate(NULL, ".g\xe2\x80\x8eIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(false, git_path_validate(NULL, ".\xe2\x80\x8fgIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x80\xaa.gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x80\xab.\xe2\x80\xacG\xe2\x80\xadI\xe2\x80\xaet", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x81\xab.\xe2\x80\xaaG\xe2\x81\xabI\xe2\x80\xact", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x81\xad.\xe2\x80\xaeG\xef\xbb\xbfIT", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(true, git_path_validate(NULL, ".", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(true, git_path_validate(NULL, ".g", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(true, git_path_validate(NULL, ".gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(true, git_path_validate(NULL, " .git", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(true, git_path_validate(NULL, "..git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(true, git_path_validate(NULL, ".gi\xe2\x80\x8dT.", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(true, git_path_validate(NULL, ".g\xe2\x80It", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(true, git_path_validate(NULL, ".\xe2gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(true, git_path_validate(NULL, "\xe2\x80\xaa.gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(true, git_path_validate(NULL, ".gi\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(true, git_path_validate(NULL, ".gi\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(true, git_path_validate(NULL, ".g\xe2i\x80T\x8e", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(true, git_path_validate(NULL, ".git\xe2\x80\xbf", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
cl_assert_equal_b(true, git_path_validate(NULL, ".git\xe2\xab\x81", 0, GIT_PATH_REJECT_DOT_GIT_HFS));
}
void test_path_core__validate_workdir(void)
{
cl_must_pass(git_path_validate_workdir(NULL, "/foo/bar"));
cl_must_pass(git_path_validate_workdir(NULL, "C:\\Foo\\Bar"));
cl_must_pass(git_path_validate_workdir(NULL, "\\\\?\\C:\\Foo\\Bar"));
cl_must_pass(git_path_validate_workdir(NULL, "\\\\?\\C:\\Foo\\Bar"));
cl_must_pass(git_path_validate_workdir(NULL, "\\\\?\\UNC\\server\\C$\\folder"));
#ifdef GIT_WIN32
/*
* In the absense of a repo configuration, 259 character paths
* succeed. >= 260 character paths fail.
*/
cl_must_pass(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\ok.txt"));
cl_must_pass(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\260.txt"));
cl_must_fail(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\longer_than_260.txt"));
/* count characters, not bytes */
cl_must_pass(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt"));
cl_must_fail(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt"));
#else
cl_must_pass(git_path_validate_workdir(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/ok.txt"));
cl_must_pass(git_path_validate_workdir(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/260.txt"));
cl_must_pass(git_path_validate_workdir(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt"));
cl_must_pass(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt"));
cl_must_pass(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt"));
#endif
}
void test_path_core__validate_workdir_with_core_longpath(void)
{
#ifdef GIT_WIN32
git_repository *repo;
git_config *config;
repo = cl_git_sandbox_init("empty_bare.git");
cl_git_pass(git_repository_open(&repo, "empty_bare.git"));
cl_git_pass(git_repository_config(&config, repo));
/* fail by default */
cl_must_fail(git_path_validate_workdir(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt"));
/* set core.longpaths explicitly on */
cl_git_pass(git_config_set_bool(config, "core.longpaths", 1));
cl_must_pass(git_path_validate_workdir(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt"));
/* set core.longpaths explicitly off */
cl_git_pass(git_config_set_bool(config, "core.longpaths", 0));
cl_must_fail(git_path_validate_workdir(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt"));
git_config_free(config);
git_repository_free(repo);
#endif
}
static void test_join_unrooted(
const char *expected_result,
ssize_t expected_rootlen,
const char *path,
const char *base)
{
git_buf result = GIT_BUF_INIT;
ssize_t root_at;
cl_git_pass(git_path_join_unrooted(&result, path, base, &root_at));
cl_assert_equal_s(expected_result, result.ptr);
cl_assert_equal_i(expected_rootlen, root_at);
git_buf_dispose(&result);
}
void test_path_core__join_unrooted(void)
{
git_buf out = GIT_BUF_INIT;
test_join_unrooted("foo", 0, "foo", NULL);
test_join_unrooted("foo/bar", 0, "foo/bar", NULL);
/* Relative paths have base prepended */
test_join_unrooted("/foo/bar", 4, "bar", "/foo");
test_join_unrooted("/foo/bar/foobar", 4, "bar/foobar", "/foo");
test_join_unrooted("c:/foo/bar/foobar", 6, "bar/foobar", "c:/foo");
test_join_unrooted("c:/foo/bar/foobar", 10, "foobar", "c:/foo/bar");
/* Absolute paths are not prepended with base */
test_join_unrooted("/foo", 0, "/foo", "/asdf");
test_join_unrooted("/foo/bar", 0, "/foo/bar", "/asdf");
/* Drive letter is given as root length on Windows */
test_join_unrooted("c:/foo", 2, "c:/foo", "c:/asdf");
test_join_unrooted("c:/foo/bar", 2, "c:/foo/bar", "c:/asdf");
#ifdef GIT_WIN32
/* Paths starting with '\\' are absolute */
test_join_unrooted("\\bar", 0, "\\bar", "c:/foo/");
test_join_unrooted("\\\\network\\bar", 9, "\\\\network\\bar", "c:/foo/");
#else
/* Paths starting with '\\' are not absolute on non-Windows systems */
test_join_unrooted("/foo/\\bar", 4, "\\bar", "/foo");
test_join_unrooted("c:/foo/\\bar", 7, "\\bar", "c:/foo/");
#endif
/* Base is returned when it's provided and is the prefix */
test_join_unrooted("c:/foo/bar/foobar", 6, "c:/foo/bar/foobar", "c:/foo");
test_join_unrooted("c:/foo/bar/foobar", 10, "c:/foo/bar/foobar", "c:/foo/bar");
/* Trailing slash in the base is ignored */
test_join_unrooted("c:/foo/bar/foobar", 6, "c:/foo/bar/foobar", "c:/foo/");
git_buf_dispose(&out);
}
void test_path_core__join_unrooted_respects_funny_windows_roots(void)
{
test_join_unrooted("💩:/foo/bar/foobar", 9, "bar/foobar", "💩:/foo");
test_join_unrooted("💩:/foo/bar/foobar", 13, "foobar", "💩:/foo/bar");
test_join_unrooted("💩:/foo", 5, "💩:/foo", "💩:/asdf");
test_join_unrooted("💩:/foo/bar", 5, "💩:/foo/bar", "💩:/asdf");
test_join_unrooted("💩:/foo/bar/foobar", 9, "💩:/foo/bar/foobar", "💩:/foo");
test_join_unrooted("💩:/foo/bar/foobar", 13, "💩:/foo/bar/foobar", "💩:/foo/bar");
test_join_unrooted("💩:/foo/bar/foobar", 9, "💩:/foo/bar/foobar", "💩:/foo/");
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/notes/notes.c
|
#include "clar_libgit2.h"
#include "buffer.h"
static git_repository *_repo;
static git_signature *_sig;
void test_notes_notes__initialize(void)
{
_repo = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_signature_now(&_sig, "alice", "[email protected]"));
}
void test_notes_notes__cleanup(void)
{
git_signature_free(_sig);
_sig = NULL;
cl_git_sandbox_cleanup();
}
static void assert_note_equal(git_note *note, char *message, git_oid *note_oid) {
git_blob *blob;
cl_assert_equal_s(git_note_message(note), message);
cl_assert_equal_oid(git_note_id(note), note_oid);
cl_git_pass(git_blob_lookup(&blob, _repo, note_oid));
cl_assert_equal_s(git_note_message(note), (const char *)git_blob_rawcontent(blob));
git_blob_free(blob);
}
static void create_note(git_oid *note_oid, const char *canonical_namespace, const char *target_sha, const char *message)
{
git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, target_sha));
cl_git_pass(git_note_create(note_oid, _repo, canonical_namespace, _sig, _sig, &oid, message, 0));
}
static struct {
const char *note_sha;
const char *annotated_object_sha;
}
list_expectations[] = {
{ "1c73b1f51762155d357bcd1fd4f2c409ef80065b", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045" },
{ "1c73b1f51762155d357bcd1fd4f2c409ef80065b", "9fd738e8f7967c078dceed8190330fc8648ee56a" },
{ "257b43746b6b46caa4aa788376c647cce0a33e2b", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750" },
{ "1ec1c8e03f461f4f5d3f3702172483662e7223f3", "c47800c7266a2be04c571c04d5a6614691ea99bd" },
{ NULL, NULL }
};
#define EXPECTATIONS_COUNT (sizeof(list_expectations)/sizeof(list_expectations[0])) - 1
static int note_list_cb(
const git_oid *blob_id, const git_oid *annotated_obj_id, void *payload)
{
git_oid expected_note_oid, expected_target_oid;
unsigned int *count = (unsigned int *)payload;
cl_assert(*count < EXPECTATIONS_COUNT);
cl_git_pass(git_oid_fromstr(&expected_note_oid, list_expectations[*count].note_sha));
cl_assert_equal_oid(&expected_note_oid, blob_id);
cl_git_pass(git_oid_fromstr(&expected_target_oid, list_expectations[*count].annotated_object_sha));
cl_assert_equal_oid(&expected_target_oid, annotated_obj_id);
(*count)++;
return 0;
}
struct note_create_payload {
const char *note_oid;
const char *object_oid;
unsigned seen;
};
static int note_list_create_cb(
const git_oid *blob_oid, const git_oid *annotated_obj_id, void *payload)
{
git_oid expected_note_oid, expected_target_oid;
struct note_create_payload *notes = payload;
size_t i;
for (i = 0; notes[i].note_oid != NULL; i++) {
cl_git_pass(git_oid_fromstr(&expected_note_oid, notes[i].note_oid));
if (git_oid_cmp(&expected_note_oid, blob_oid) != 0)
continue;
cl_git_pass(git_oid_fromstr(&expected_target_oid, notes[i].object_oid));
if (git_oid_cmp(&expected_target_oid, annotated_obj_id) != 0)
continue;
notes[i].seen = 1;
return 0;
}
cl_fail("Did not see expected note");
return 0;
}
void assert_notes_seen(struct note_create_payload payload[], size_t n)
{
size_t seen = 0, i;
for (i = 0; payload[i].note_oid != NULL; i++) {
if (payload[i].seen)
seen++;
}
cl_assert_equal_i(seen, n);
}
void test_notes_notes__can_create_a_note(void)
{
git_oid note_oid;
static struct note_create_payload can_create_a_note[] = {
{ "1c9b1bc36730582a42d56eeee0dc58673d7ae869", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", 0 },
{ NULL, NULL, 0 }
};
create_note(¬e_oid, "refs/notes/i-can-see-dead-notes", can_create_a_note[0].object_oid, "I decorate 4a20\n");
cl_git_pass(git_note_foreach(_repo, "refs/notes/i-can-see-dead-notes", note_list_create_cb, &can_create_a_note));
assert_notes_seen(can_create_a_note, 1);
}
void test_notes_notes__can_create_a_note_from_commit(void)
{
git_oid oid;
git_oid notes_commit_out;
git_reference *ref;
static struct note_create_payload can_create_a_note_from_commit[] = {
{ "1c9b1bc36730582a42d56eeee0dc58673d7ae869", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", 0 },
{ NULL, NULL, 0 }
};
cl_git_pass(git_oid_fromstr(&oid, can_create_a_note_from_commit[0].object_oid));
cl_git_pass(git_note_commit_create(¬es_commit_out, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 1));
/* create_from_commit will not update any ref,
* so we must manually create the ref, that points to the commit */
cl_git_pass(git_reference_create(&ref, _repo, "refs/notes/i-can-see-dead-notes", ¬es_commit_out, 0, NULL));
cl_git_pass(git_note_foreach(_repo, "refs/notes/i-can-see-dead-notes", note_list_create_cb, &can_create_a_note_from_commit));
assert_notes_seen(can_create_a_note_from_commit, 1);
git_reference_free(ref);
}
/* Test that we can create a note from a commit, given an existing commit */
void test_notes_notes__can_create_a_note_from_commit_given_an_existing_commit(void)
{
git_oid oid;
git_oid notes_commit_out;
git_commit *existing_notes_commit = NULL;
git_reference *ref;
static struct note_create_payload can_create_a_note_from_commit_given_an_existing_commit[] = {
{ "1c9b1bc36730582a42d56eeee0dc58673d7ae869", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", 0 },
{ "1aaf94147c21f981e0a20bf57b89137c5a6aae52", "9fd738e8f7967c078dceed8190330fc8648ee56a", 0 },
{ NULL, NULL, 0 }
};
cl_git_pass(git_oid_fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"));
cl_git_pass(git_note_commit_create(¬es_commit_out, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 0));
cl_git_pass(git_oid_fromstr(&oid, "9fd738e8f7967c078dceed8190330fc8648ee56a"));
git_commit_lookup(&existing_notes_commit, _repo, ¬es_commit_out);
cl_assert(existing_notes_commit);
cl_git_pass(git_note_commit_create(¬es_commit_out, NULL, _repo, existing_notes_commit, _sig, _sig, &oid, "I decorate 9fd7\n", 0));
/* create_from_commit will not update any ref,
* so we must manually create the ref, that points to the commit */
cl_git_pass(git_reference_create(&ref, _repo, "refs/notes/i-can-see-dead-notes", ¬es_commit_out, 0, NULL));
cl_git_pass(git_note_foreach(_repo, "refs/notes/i-can-see-dead-notes", note_list_create_cb, &can_create_a_note_from_commit_given_an_existing_commit));
assert_notes_seen(can_create_a_note_from_commit_given_an_existing_commit, 2);
git_commit_free(existing_notes_commit);
git_reference_free(ref);
}
/*
* $ git notes --ref i-can-see-dead-notes add -m "I decorate a65f" a65fedf39aefe402d3bb6e24df4d4f5fe4547750
* $ git notes --ref i-can-see-dead-notes add -m "I decorate c478" c47800c7266a2be04c571c04d5a6614691ea99bd
* $ git notes --ref i-can-see-dead-notes add -m "I decorate 9fd7 and 4a20" 9fd738e8f7967c078dceed8190330fc8648ee56a
* $ git notes --ref i-can-see-dead-notes add -m "I decorate 9fd7 and 4a20" 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
*
* $ git notes --ref i-can-see-dead-notes list
* 1c73b1f51762155d357bcd1fd4f2c409ef80065b 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
* 1c73b1f51762155d357bcd1fd4f2c409ef80065b 9fd738e8f7967c078dceed8190330fc8648ee56a
* 257b43746b6b46caa4aa788376c647cce0a33e2b a65fedf39aefe402d3bb6e24df4d4f5fe4547750
* 1ec1c8e03f461f4f5d3f3702172483662e7223f3 c47800c7266a2be04c571c04d5a6614691ea99bd
*
* $ git ls-tree refs/notes/i-can-see-dead-notes
* 100644 blob 1c73b1f51762155d357bcd1fd4f2c409ef80065b 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
* 100644 blob 1c73b1f51762155d357bcd1fd4f2c409ef80065b 9fd738e8f7967c078dceed8190330fc8648ee56a
* 100644 blob 257b43746b6b46caa4aa788376c647cce0a33e2b a65fedf39aefe402d3bb6e24df4d4f5fe4547750
* 100644 blob 1ec1c8e03f461f4f5d3f3702172483662e7223f3 c47800c7266a2be04c571c04d5a6614691ea99bd
*/
void test_notes_notes__can_retrieve_a_list_of_notes_for_a_given_namespace(void)
{
git_oid note_oid1, note_oid2, note_oid3, note_oid4;
unsigned int retrieved_notes = 0;
create_note(¬e_oid1, "refs/notes/i-can-see-dead-notes", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "I decorate a65f\n");
create_note(¬e_oid2, "refs/notes/i-can-see-dead-notes", "c47800c7266a2be04c571c04d5a6614691ea99bd", "I decorate c478\n");
create_note(¬e_oid3, "refs/notes/i-can-see-dead-notes", "9fd738e8f7967c078dceed8190330fc8648ee56a", "I decorate 9fd7 and 4a20\n");
create_note(¬e_oid4, "refs/notes/i-can-see-dead-notes", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "I decorate 9fd7 and 4a20\n");
cl_git_pass(git_note_foreach
(_repo, "refs/notes/i-can-see-dead-notes", note_list_cb, &retrieved_notes));
cl_assert_equal_i(4, retrieved_notes);
}
static int note_cancel_cb(
const git_oid *blob_id, const git_oid *annotated_obj_id, void *payload)
{
unsigned int *count = (unsigned int *)payload;
GIT_UNUSED(blob_id);
GIT_UNUSED(annotated_obj_id);
(*count)++;
return (*count > 2);
}
void test_notes_notes__can_cancel_foreach(void)
{
git_oid note_oid1, note_oid2, note_oid3, note_oid4;
unsigned int retrieved_notes = 0;
create_note(¬e_oid1, "refs/notes/i-can-see-dead-notes", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "I decorate a65f\n");
create_note(¬e_oid2, "refs/notes/i-can-see-dead-notes", "c47800c7266a2be04c571c04d5a6614691ea99bd", "I decorate c478\n");
create_note(¬e_oid3, "refs/notes/i-can-see-dead-notes", "9fd738e8f7967c078dceed8190330fc8648ee56a", "I decorate 9fd7 and 4a20\n");
create_note(¬e_oid4, "refs/notes/i-can-see-dead-notes", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "I decorate 9fd7 and 4a20\n");
cl_assert_equal_i(
1,
git_note_foreach(_repo, "refs/notes/i-can-see-dead-notes",
note_cancel_cb, &retrieved_notes));
}
void test_notes_notes__retrieving_a_list_of_notes_for_an_unknown_namespace_returns_ENOTFOUND(void)
{
int error;
unsigned int retrieved_notes = 0;
error = git_note_foreach(_repo, "refs/notes/i-am-not", note_list_cb, &retrieved_notes);
cl_git_fail(error);
cl_assert_equal_i(GIT_ENOTFOUND, error);
cl_assert_equal_i(0, retrieved_notes);
}
void test_notes_notes__inserting_a_note_without_passing_a_namespace_uses_the_default_namespace(void)
{
git_oid note_oid, target_oid;
git_note *note, *default_namespace_note;
git_buf default_ref = GIT_BUF_INIT;
cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125"));
cl_git_pass(git_note_default_ref(&default_ref, _repo));
create_note(¬e_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n");
cl_git_pass(git_note_read(¬e, _repo, NULL, &target_oid));
cl_git_pass(git_note_read(&default_namespace_note, _repo, git_buf_cstr(&default_ref), &target_oid));
assert_note_equal(note, "hello world\n", ¬e_oid);
assert_note_equal(default_namespace_note, "hello world\n", ¬e_oid);
git_buf_dispose(&default_ref);
git_note_free(note);
git_note_free(default_namespace_note);
}
void test_notes_notes__can_insert_a_note_with_a_custom_namespace(void)
{
git_oid note_oid, target_oid;
git_note *note;
cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125"));
create_note(¬e_oid, "refs/notes/some/namespace", "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world on a custom namespace\n");
cl_git_pass(git_note_read(¬e, _repo, "refs/notes/some/namespace", &target_oid));
assert_note_equal(note, "hello world on a custom namespace\n", ¬e_oid);
git_note_free(note);
}
/*
* $ git notes --ref fanout list 8496071c1b46c854b31185ea97743be6a8774479
* 08b041783f40edfe12bb406c9c9a8a040177c125
*/
void test_notes_notes__creating_a_note_on_a_target_which_already_has_one_returns_EEXISTS(void)
{
int error;
git_oid note_oid, target_oid;
cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125"));
create_note(¬e_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n");
error = git_note_create(¬e_oid, _repo, NULL, _sig, _sig, &target_oid, "hello world\n", 0);
cl_git_fail(error);
cl_assert_equal_i(GIT_EEXISTS, error);
create_note(¬e_oid, "refs/notes/some/namespace", "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n");
error = git_note_create(¬e_oid, _repo, "refs/notes/some/namespace", _sig, _sig, &target_oid, "hello world\n", 0);
cl_git_fail(error);
cl_assert_equal_i(GIT_EEXISTS, error);
}
void test_notes_notes__creating_a_note_on_a_target_can_overwrite_existing_note(void)
{
git_oid note_oid, target_oid;
git_note *note, *namespace_note;
cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125"));
create_note(¬e_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello old world\n");
cl_git_pass(git_note_create(¬e_oid, _repo, NULL, _sig, _sig, &target_oid, "hello new world\n", 1));
cl_git_pass(git_note_read(¬e, _repo, NULL, &target_oid));
assert_note_equal(note, "hello new world\n", ¬e_oid);
create_note(¬e_oid, "refs/notes/some/namespace", "08b041783f40edfe12bb406c9c9a8a040177c125", "hello old world\n");
cl_git_pass(git_note_create(¬e_oid, _repo, "refs/notes/some/namespace", _sig, _sig, &target_oid, "hello new ref world\n", 1));
cl_git_pass(git_note_read(&namespace_note, _repo, "refs/notes/some/namespace", &target_oid));
assert_note_equal(namespace_note, "hello new ref world\n", ¬e_oid);
git_note_free(note);
git_note_free(namespace_note);
}
static char *messages[] = {
"08c041783f40edfe12bb406c9c9a8a040177c125",
"96c45fbe09ab7445fc7c60fd8d17f32494399343",
"48cc7e38dcfc1ec87e70ec03e08c3e83d7a16aa1",
"24c3eaafb681c3df668f9df96f58e7b8c756eb04",
"96ca1b6ccc7858ae94684777f85ac0e7447f7040",
"7ac2db4378a08bb244a427c357e0082ee0d57ac6",
"e6cba23dbf4ef84fe35e884f017f4e24dc228572",
"c8cf3462c7d8feba716deeb2ebe6583bd54589e2",
"39c16b9834c2d665ac5f68ad91dc5b933bad8549",
"f3c582b1397df6a664224ebbaf9d4cc952706597",
"29cec67037fe8e89977474988219016ae7f342a6",
"36c4cd238bf8e82e27b740e0741b025f2e8c79ab",
"f1c45a47c02e01d5a9a326f1d9f7f756373387f8",
"4aca84406f5daee34ab513a60717c8d7b1763ead",
"84ce167da452552f63ed8407b55d5ece4901845f",
NULL
};
#define MESSAGES_COUNT (sizeof(messages)/sizeof(messages[0])) - 1
/* Test that we can read a note */
void test_notes_notes__can_read_a_note(void)
{
git_oid note_oid, target_oid;
git_note *note;
create_note(¬e_oid, "refs/notes/i-can-see-dead-notes", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "I decorate 4a20\n");
cl_git_pass(git_oid_fromstr(&target_oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"));
cl_git_pass(git_note_read(¬e, _repo, "refs/notes/i-can-see-dead-notes", &target_oid));
cl_assert_equal_s(git_note_message(note), "I decorate 4a20\n");
git_note_free(note);
}
/* Test that we can read a note with from commit api */
void test_notes_notes__can_read_a_note_from_a_commit(void)
{
git_oid oid, notes_commit_oid;
git_commit *notes_commit;
git_note *note;
cl_git_pass(git_oid_fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"));
cl_git_pass(git_note_commit_create(¬es_commit_oid, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 1));
cl_git_pass(git_commit_lookup(¬es_commit, _repo, ¬es_commit_oid));
cl_assert(notes_commit);
cl_git_pass(git_note_commit_read(¬e, _repo, notes_commit, &oid));
cl_assert_equal_s(git_note_message(note), "I decorate 4a20\n");
git_commit_free(notes_commit);
git_note_free(note);
}
/* Test that we can read a commit with no note fails */
void test_notes_notes__attempt_to_read_a_note_from_a_commit_with_no_note_fails(void)
{
git_oid oid, notes_commit_oid;
git_commit *notes_commit;
git_note *note;
cl_git_pass(git_oid_fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"));
cl_git_pass(git_note_commit_create(¬es_commit_oid, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 1));
git_commit_lookup(¬es_commit, _repo, ¬es_commit_oid);
cl_git_pass(git_note_commit_remove(¬es_commit_oid, _repo, notes_commit, _sig, _sig, &oid));
git_commit_free(notes_commit);
git_commit_lookup(¬es_commit, _repo, ¬es_commit_oid);
cl_assert(notes_commit);
cl_git_fail_with(GIT_ENOTFOUND, git_note_commit_read(¬e, _repo, notes_commit, &oid));
git_commit_free(notes_commit);
}
/*
* $ git ls-tree refs/notes/fanout
* 040000 tree 4b22b35d44b5a4f589edf3dc89196399771796ea 84
*
* $ git ls-tree 4b22b35
* 040000 tree d71aab4f9b04b45ce09bcaa636a9be6231474759 96
*
* $ git ls-tree d71aab4
* 100644 blob 08b041783f40edfe12bb406c9c9a8a040177c125 071c1b46c854b31185ea97743be6a8774479
*/
void test_notes_notes__can_insert_a_note_in_an_existing_fanout(void)
{
size_t i;
git_oid note_oid, target_oid;
git_note *_note;
cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125"));
for (i = 0; i < MESSAGES_COUNT; i++) {
cl_git_pass(git_note_create(¬e_oid, _repo, "refs/notes/fanout", _sig, _sig, &target_oid, messages[i], 0));
cl_git_pass(git_note_read(&_note, _repo, "refs/notes/fanout", &target_oid));
git_note_free(_note);
git_oid_cpy(&target_oid, ¬e_oid);
}
}
/*
* $ git notes --ref fanout list 8496071c1b46c854b31185ea97743be6a8774479
* 08b041783f40edfe12bb406c9c9a8a040177c125
*/
void test_notes_notes__can_read_a_note_in_an_existing_fanout(void)
{
git_oid note_oid, target_oid;
git_note *note;
cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479"));
cl_git_pass(git_note_read(¬e, _repo, "refs/notes/fanout", &target_oid));
cl_git_pass(git_oid_fromstr(¬e_oid, "08b041783f40edfe12bb406c9c9a8a040177c125"));
cl_assert_equal_oid(git_note_id(note), ¬e_oid);
git_note_free(note);
}
/* Can remove a note */
void test_notes_notes__can_remove_a_note(void)
{
git_oid note_oid, target_oid;
git_note *note;
create_note(¬e_oid, "refs/notes/i-can-see-dead-notes", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "I decorate 4a20\n");
cl_git_pass(git_oid_fromstr(&target_oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"));
cl_git_pass(git_note_remove(_repo, "refs/notes/i-can-see-dead-notes", _sig, _sig, &target_oid));
cl_git_fail(git_note_read(¬e, _repo, "refs/notes/i-can-see-dead-notes", &target_oid));
}
/* Can remove a note from a commit */
void test_notes_notes__can_remove_a_note_from_commit(void)
{
git_oid oid, notes_commit_oid;
git_note *note = NULL;
git_commit *existing_notes_commit;
git_reference *ref;
cl_git_pass(git_oid_fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"));
cl_git_pass(git_note_commit_create(¬es_commit_oid, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 0));
cl_git_pass(git_commit_lookup(&existing_notes_commit, _repo, ¬es_commit_oid));
cl_assert(existing_notes_commit);
cl_git_pass(git_note_commit_remove(¬es_commit_oid, _repo, existing_notes_commit, _sig, _sig, &oid));
/* remove_from_commit will not update any ref,
* so we must manually create the ref, that points to the commit */
cl_git_pass(git_reference_create(&ref, _repo, "refs/notes/i-can-see-dead-notes", ¬es_commit_oid, 0, NULL));
cl_git_fail(git_note_read(¬e, _repo, "refs/notes/i-can-see-dead-notes", &oid));
git_commit_free(existing_notes_commit);
git_reference_free(ref);
git_note_free(note);
}
void test_notes_notes__can_remove_a_note_in_an_existing_fanout(void)
{
git_oid target_oid;
git_note *note;
cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479"));
cl_git_pass(git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid));
cl_git_fail(git_note_read(¬e, _repo, "refs/notes/fanout", &target_oid));
}
void test_notes_notes__removing_a_note_which_doesnt_exists_returns_ENOTFOUND(void)
{
int error;
git_oid target_oid;
cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479"));
cl_git_pass(git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid));
error = git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid);
cl_git_fail(error);
cl_assert_equal_i(GIT_ENOTFOUND, error);
}
void test_notes_notes__can_iterate_default_namespace(void)
{
git_note_iterator *iter;
git_note *note;
git_oid note_id, annotated_id;
git_oid note_created[2];
const char* note_message[] = {
"I decorate a65f\n",
"I decorate c478\n"
};
int i, err;
create_note(¬e_created[0], "refs/notes/commits",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", note_message[0]);
create_note(¬e_created[1], "refs/notes/commits",
"c47800c7266a2be04c571c04d5a6614691ea99bd", note_message[1]);
cl_git_pass(git_note_iterator_new(&iter, _repo, NULL));
for (i = 0; (err = git_note_next(¬e_id, &annotated_id, iter)) >= 0; ++i) {
cl_git_pass(git_note_read(¬e, _repo, NULL, &annotated_id));
cl_assert_equal_s(git_note_message(note), note_message[i]);
git_note_free(note);
}
cl_assert_equal_i(GIT_ITEROVER, err);
cl_assert_equal_i(2, i);
git_note_iterator_free(iter);
}
void test_notes_notes__can_iterate_custom_namespace(void)
{
git_note_iterator *iter;
git_note *note;
git_oid note_id, annotated_id;
git_oid note_created[2];
const char* note_message[] = {
"I decorate a65f\n",
"I decorate c478\n"
};
int i, err;
create_note(¬e_created[0], "refs/notes/beer",
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", note_message[0]);
create_note(¬e_created[1], "refs/notes/beer",
"c47800c7266a2be04c571c04d5a6614691ea99bd", note_message[1]);
cl_git_pass(git_note_iterator_new(&iter, _repo, "refs/notes/beer"));
for (i = 0; (err = git_note_next(¬e_id, &annotated_id, iter)) >= 0; ++i) {
cl_git_pass(git_note_read(¬e, _repo, "refs/notes/beer", &annotated_id));
cl_assert_equal_s(git_note_message(note), note_message[i]);
git_note_free(note);
}
cl_assert_equal_i(GIT_ITEROVER, err);
cl_assert_equal_i(2, i);
git_note_iterator_free(iter);
}
void test_notes_notes__empty_iterate(void)
{
git_note_iterator *iter;
cl_git_fail(git_note_iterator_new(&iter, _repo, "refs/notes/commits"));
}
void test_notes_notes__iterate_from_commit(void)
{
git_note_iterator *iter;
git_note *note;
git_oid note_id, annotated_id;
git_oid oids[2];
git_oid notes_commit_oids[2];
git_commit *notes_commits[2];
const char* note_message[] = {
"I decorate a65f\n",
"I decorate c478\n"
};
int i, err;
cl_git_pass(git_oid_fromstr(&(oids[0]), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"));
cl_git_pass(git_oid_fromstr(&(oids[1]), "c47800c7266a2be04c571c04d5a6614691ea99bd"));
cl_git_pass(git_note_commit_create(¬es_commit_oids[0], NULL, _repo, NULL, _sig, _sig, &(oids[0]), note_message[0], 0));
git_commit_lookup(¬es_commits[0], _repo, ¬es_commit_oids[0]);
cl_assert(notes_commits[0]);
cl_git_pass(git_note_commit_create(¬es_commit_oids[1], NULL, _repo, notes_commits[0], _sig, _sig, &(oids[1]), note_message[1], 0));
git_commit_lookup(¬es_commits[1], _repo, ¬es_commit_oids[1]);
cl_assert(notes_commits[1]);
cl_git_pass(git_note_commit_iterator_new(&iter, notes_commits[1]));
for (i = 0; (err = git_note_next(¬e_id, &annotated_id, iter)) >= 0; ++i) {
cl_git_pass(git_note_commit_read(¬e, _repo, notes_commits[1], &annotated_id));
cl_assert_equal_s(git_note_message(note), note_message[i]);
git_note_free(note);
}
cl_assert_equal_i(GIT_ITEROVER, err);
cl_assert_equal_i(2, i);
git_note_iterator_free(iter);
git_commit_free(notes_commits[0]);
git_commit_free(notes_commits[1]);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/notes/notesref.c
|
#include "clar_libgit2.h"
#include "notes.h"
#include "buffer.h"
static git_repository *_repo;
static git_note *_note;
static git_signature *_sig;
static git_config *_cfg;
void test_notes_notesref__initialize(void)
{
cl_fixture_sandbox("testrepo.git");
cl_git_pass(git_repository_open(&_repo, "testrepo.git"));
}
void test_notes_notesref__cleanup(void)
{
git_note_free(_note);
_note = NULL;
git_signature_free(_sig);
_sig = NULL;
git_config_free(_cfg);
_cfg = NULL;
git_repository_free(_repo);
_repo = NULL;
cl_fixture_cleanup("testrepo.git");
}
void test_notes_notesref__config_corenotesref(void)
{
git_oid oid, note_oid;
git_buf default_ref = GIT_BUF_INIT;
cl_git_pass(git_signature_now(&_sig, "alice", "[email protected]"));
cl_git_pass(git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479"));
cl_git_pass(git_repository_config(&_cfg, _repo));
cl_git_pass(git_config_set_string(_cfg, "core.notesRef", "refs/notes/mydefaultnotesref"));
cl_git_pass(git_note_create(¬e_oid, _repo, NULL, _sig, _sig, &oid, "test123test\n", 0));
cl_git_pass(git_note_read(&_note, _repo, NULL, &oid));
cl_assert_equal_s("test123test\n", git_note_message(_note));
cl_assert_equal_oid(git_note_id(_note), ¬e_oid);
git_note_free(_note);
cl_git_pass(git_note_read(&_note, _repo, "refs/notes/mydefaultnotesref", &oid));
cl_assert_equal_s("test123test\n", git_note_message(_note));
cl_assert_equal_oid(git_note_id(_note), ¬e_oid);
cl_git_pass(git_note_default_ref(&default_ref, _repo));
cl_assert_equal_s("refs/notes/mydefaultnotesref", default_ref.ptr);
git_buf_clear(&default_ref);
cl_git_pass(git_config_delete_entry(_cfg, "core.notesRef"));
cl_git_pass(git_note_default_ref(&default_ref, _repo));
cl_assert_equal_s(GIT_NOTES_DEFAULT_REF, default_ref.ptr);
git_buf_dispose(&default_ref);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/graph/descendant_of.c
|
#include "clar_libgit2.h"
static git_repository *_repo;
static git_commit *commit;
void test_graph_descendant_of__initialize(void)
{
git_oid oid;
cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
git_oid_fromstr(&oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
cl_git_pass(git_commit_lookup(&commit, _repo, &oid));
}
void test_graph_descendant_of__cleanup(void)
{
git_commit_free(commit);
commit = NULL;
git_repository_free(_repo);
_repo = NULL;
}
void test_graph_descendant_of__returns_correct_result(void)
{
git_commit *other;
cl_assert_equal_i(0, git_graph_descendant_of(_repo, git_commit_id(commit), git_commit_id(commit)));
cl_git_pass(git_commit_nth_gen_ancestor(&other, commit, 1));
cl_assert_equal_i(1, git_graph_descendant_of(_repo, git_commit_id(commit), git_commit_id(other)));
cl_assert_equal_i(0, git_graph_descendant_of(_repo, git_commit_id(other), git_commit_id(commit)));
git_commit_free(other);
cl_git_pass(git_commit_nth_gen_ancestor(&other, commit, 3));
cl_assert_equal_i(1, git_graph_descendant_of(_repo, git_commit_id(commit), git_commit_id(other)));
cl_assert_equal_i(0, git_graph_descendant_of(_repo, git_commit_id(other), git_commit_id(commit)));
git_commit_free(other);
}
void test_graph_descendant_of__nopath(void)
{
git_oid oid;
git_oid_fromstr(&oid, "e90810b8df3e80c413d903f631643c716887138d");
cl_assert_equal_i(0, git_graph_descendant_of(_repo, git_commit_id(commit), &oid));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/graph/commit_graph.c
|
#include "clar_libgit2.h"
#include <git2.h>
#include <git2/sys/commit_graph.h>
#include "commit_graph.h"
#include "futils.h"
void test_graph_commit_graph__parse(void)
{
git_repository *repo;
struct git_commit_graph_file *file;
struct git_commit_graph_entry e, parent;
git_oid id;
git_buf commit_graph_path = GIT_BUF_INIT;
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_buf_joinpath(&commit_graph_path, git_repository_path(repo), "objects/info/commit-graph"));
cl_git_pass(git_commit_graph_file_open(&file, git_buf_cstr(&commit_graph_path)));
cl_assert_equal_i(git_commit_graph_file_needs_refresh(file, git_buf_cstr(&commit_graph_path)), 0);
cl_git_pass(git_oid_fromstr(&id, "5001298e0c09ad9c34e4249bc5801c75e9754fa5"));
cl_git_pass(git_commit_graph_entry_find(&e, file, &id, GIT_OID_HEXSZ));
cl_assert_equal_oid(&e.sha1, &id);
cl_git_pass(git_oid_fromstr(&id, "418382dff1ffb8bdfba833f4d8bbcde58b1e7f47"));
cl_assert_equal_oid(&e.tree_oid, &id);
cl_assert_equal_i(e.generation, 1);
cl_assert_equal_i(e.commit_time, UINT64_C(1273610423));
cl_assert_equal_i(e.parent_count, 0);
cl_git_pass(git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
cl_git_pass(git_commit_graph_entry_find(&e, file, &id, GIT_OID_HEXSZ));
cl_assert_equal_oid(&e.sha1, &id);
cl_assert_equal_i(e.generation, 5);
cl_assert_equal_i(e.commit_time, UINT64_C(1274813907));
cl_assert_equal_i(e.parent_count, 2);
cl_git_pass(git_oid_fromstr(&id, "9fd738e8f7967c078dceed8190330fc8648ee56a"));
cl_git_pass(git_commit_graph_entry_parent(&parent, file, &e, 0));
cl_assert_equal_oid(&parent.sha1, &id);
cl_assert_equal_i(parent.generation, 4);
cl_git_pass(git_oid_fromstr(&id, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
cl_git_pass(git_commit_graph_entry_parent(&parent, file, &e, 1));
cl_assert_equal_oid(&parent.sha1, &id);
cl_assert_equal_i(parent.generation, 3);
git_commit_graph_file_free(file);
git_repository_free(repo);
git_buf_dispose(&commit_graph_path);
}
void test_graph_commit_graph__parse_octopus_merge(void)
{
git_repository *repo;
struct git_commit_graph_file *file;
struct git_commit_graph_entry e, parent;
git_oid id;
git_buf commit_graph_path = GIT_BUF_INIT;
cl_git_pass(git_repository_open(&repo, cl_fixture("merge-recursive/.gitted")));
cl_git_pass(git_buf_joinpath(&commit_graph_path, git_repository_path(repo), "objects/info/commit-graph"));
cl_git_pass(git_commit_graph_file_open(&file, git_buf_cstr(&commit_graph_path)));
cl_git_pass(git_oid_fromstr(&id, "d71c24b3b113fd1d1909998c5bfe33b86a65ee03"));
cl_git_pass(git_commit_graph_entry_find(&e, file, &id, GIT_OID_HEXSZ));
cl_assert_equal_oid(&e.sha1, &id);
cl_git_pass(git_oid_fromstr(&id, "348f16ffaeb73f319a75cec5b16a0a47d2d5e27c"));
cl_assert_equal_oid(&e.tree_oid, &id);
cl_assert_equal_i(e.generation, 7);
cl_assert_equal_i(e.commit_time, UINT64_C(1447083009));
cl_assert_equal_i(e.parent_count, 3);
cl_git_pass(git_oid_fromstr(&id, "ad2ace9e15f66b3d1138922e6ffdc3ea3f967fa6"));
cl_git_pass(git_commit_graph_entry_parent(&parent, file, &e, 0));
cl_assert_equal_oid(&parent.sha1, &id);
cl_assert_equal_i(parent.generation, 6);
cl_git_pass(git_oid_fromstr(&id, "483065df53c0f4a02cdc6b2910b05d388fc17ffb"));
cl_git_pass(git_commit_graph_entry_parent(&parent, file, &e, 1));
cl_assert_equal_oid(&parent.sha1, &id);
cl_assert_equal_i(parent.generation, 2);
cl_git_pass(git_oid_fromstr(&id, "815b5a1c80ca749d705c7aa0cb294a00cbedd340"));
cl_git_pass(git_commit_graph_entry_parent(&parent, file, &e, 2));
cl_assert_equal_oid(&parent.sha1, &id);
cl_assert_equal_i(parent.generation, 6);
git_commit_graph_file_free(file);
git_repository_free(repo);
git_buf_dispose(&commit_graph_path);
}
void test_graph_commit_graph__writer(void)
{
git_repository *repo;
git_commit_graph_writer *w = NULL;
git_revwalk *walk;
git_commit_graph_writer_options opts = GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT;
git_buf cgraph = GIT_BUF_INIT, expected_cgraph = GIT_BUF_INIT, path = GIT_BUF_INIT;
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "objects/info"));
cl_git_pass(git_commit_graph_writer_new(&w, git_buf_cstr(&path)));
/* This is equivalent to `git commit-graph write --reachable`. */
cl_git_pass(git_revwalk_new(&walk, repo));
cl_git_pass(git_revwalk_push_glob(walk, "refs/*"));
cl_git_pass(git_commit_graph_writer_add_revwalk(w, walk));
git_revwalk_free(walk);
cl_git_pass(git_commit_graph_writer_dump(&cgraph, w, &opts));
cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "objects/info/commit-graph"));
cl_git_pass(git_futils_readbuffer(&expected_cgraph, git_buf_cstr(&path)));
cl_assert_equal_i(git_buf_len(&cgraph), git_buf_len(&expected_cgraph));
cl_assert_equal_i(memcmp(git_buf_cstr(&cgraph), git_buf_cstr(&expected_cgraph), git_buf_len(&cgraph)), 0);
git_buf_dispose(&cgraph);
git_buf_dispose(&expected_cgraph);
git_buf_dispose(&path);
git_commit_graph_writer_free(w);
git_repository_free(repo);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/graph/ahead_behind.c
|
#include "clar_libgit2.h"
static git_repository *_repo;
static git_commit *commit;
static size_t ahead;
static size_t behind;
void test_graph_ahead_behind__initialize(void)
{
git_oid oid;
cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
cl_git_pass(git_oid_fromstr(&oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
cl_git_pass(git_commit_lookup(&commit, _repo, &oid));
}
void test_graph_ahead_behind__cleanup(void)
{
git_commit_free(commit);
commit = NULL;
git_repository_free(_repo);
_repo = NULL;
}
void test_graph_ahead_behind__returns_correct_result(void)
{
git_oid oid;
git_oid oid2;
git_commit *other;
cl_git_pass(git_oid_fromstr(&oid, "e90810b8df3e80c413d903f631643c716887138d"));
cl_git_pass(git_oid_fromstr(&oid2, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &oid, &oid2));
cl_assert_equal_sz(2, ahead);
cl_assert_equal_sz(6, behind);
cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(commit), git_commit_id(commit)));
cl_assert_equal_sz(ahead, behind);
cl_git_pass(git_commit_nth_gen_ancestor(&other, commit, 1));
cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(commit), git_commit_id(other)));
cl_assert_equal_sz(ahead, behind + 2);
cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(other), git_commit_id(commit)));
cl_assert_equal_sz(ahead + 2, behind);
git_commit_free(other);
cl_git_pass(git_commit_nth_gen_ancestor(&other, commit, 3));
cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(commit), git_commit_id(other)));
cl_assert_equal_sz(ahead, behind + 4);
cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(other), git_commit_id(commit)));
cl_assert_equal_sz(ahead + 4, behind);
git_commit_free(other);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/graph/reachable_from_any.c
|
#include "clar_libgit2.h"
#include <git2.h>
#include "commit_graph.h"
#include "bitvec.h"
#include "vector.h"
static git_repository *repo;
#define TEST_REPO_PATH "merge-recursive"
void test_graph_reachable_from_any__initialize(void)
{
git_oid oid;
git_commit *commit;
repo = cl_git_sandbox_init(TEST_REPO_PATH);
git_oid_fromstr(&oid, "539bd011c4822c560c1d17cab095006b7a10f707");
cl_git_pass(git_commit_lookup(&commit, repo, &oid));
cl_git_pass(git_reset(repo, (git_object *)commit, GIT_RESET_HARD, NULL));
git_commit_free(commit);
}
void test_graph_reachable_from_any__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_graph_reachable_from_any__returns_correct_result(void)
{
git_object *branchA1, *branchA2, *branchB1, *branchB2, *branchC1, *branchC2, *branchH1,
*branchH2;
git_oid descendants[7];
cl_git_pass(git_revparse_single(&branchA1, repo, "branchA-1"));
cl_git_pass(git_revparse_single(&branchA2, repo, "branchA-2"));
cl_git_pass(git_revparse_single(&branchB1, repo, "branchB-1"));
cl_git_pass(git_revparse_single(&branchB2, repo, "branchB-2"));
cl_git_pass(git_revparse_single(&branchC1, repo, "branchC-1"));
cl_git_pass(git_revparse_single(&branchC2, repo, "branchC-2"));
cl_git_pass(git_revparse_single(&branchH1, repo, "branchH-1"));
cl_git_pass(git_revparse_single(&branchH2, repo, "branchH-2"));
cl_assert_equal_i(
git_graph_reachable_from_any(
repo, git_object_id(branchH1), git_object_id(branchA1), 1),
0);
cl_assert_equal_i(
git_graph_reachable_from_any(
repo, git_object_id(branchH1), git_object_id(branchA2), 1),
0);
cl_git_pass(git_oid_cpy(&descendants[0], git_object_id(branchA1)));
cl_git_pass(git_oid_cpy(&descendants[1], git_object_id(branchA2)));
cl_git_pass(git_oid_cpy(&descendants[2], git_object_id(branchB1)));
cl_git_pass(git_oid_cpy(&descendants[3], git_object_id(branchB2)));
cl_git_pass(git_oid_cpy(&descendants[4], git_object_id(branchC1)));
cl_git_pass(git_oid_cpy(&descendants[5], git_object_id(branchC2)));
cl_git_pass(git_oid_cpy(&descendants[6], git_object_id(branchH2)));
cl_assert_equal_i(
git_graph_reachable_from_any(repo, git_object_id(branchH2), descendants, 6),
0);
cl_assert_equal_i(
git_graph_reachable_from_any(repo, git_object_id(branchH2), descendants, 7),
1);
git_object_free(branchA1);
git_object_free(branchA2);
git_object_free(branchB1);
git_object_free(branchB2);
git_object_free(branchC1);
git_object_free(branchC2);
git_object_free(branchH1);
git_object_free(branchH2);
}
struct exhaustive_state {
git_odb *db;
git_vector commits;
};
/** Get all commits from the repository. */
static int exhaustive_commits(const git_oid *id, void *payload)
{
struct exhaustive_state *mc = (struct exhaustive_state *)payload;
size_t header_len;
git_object_t header_type;
int error = 0;
error = git_odb_read_header(&header_len, &header_type, mc->db, id);
if (error < 0)
return error;
if (header_type == GIT_OBJECT_COMMIT) {
git_commit *commit = NULL;
cl_git_pass(git_commit_lookup(&commit, repo, id));
cl_git_pass(git_vector_insert(&mc->commits, commit));
}
return 0;
}
/** Compare the `git_oid`s of two `git_commit` objects. */
static int commit_id_cmp(const void *a, const void *b)
{
return git_oid_cmp(
git_commit_id((const git_commit *)a), git_commit_id((const git_commit *)b));
}
/** Find a `git_commit` whose ID matches the provided `git_oid` key. */
static int id_commit_id_cmp(const void *key, const void *commit)
{
return git_oid_cmp((const git_oid *)key, git_commit_id((const git_commit *)commit));
}
void test_graph_reachable_from_any__exhaustive(void)
{
struct exhaustive_state mc = {
.db = NULL,
.commits = GIT_VECTOR_INIT,
};
size_t child_idx, commit_count;
size_t n_descendants;
git_commit *child_commit;
git_bitvec reachable;
cl_git_pass(git_repository_odb(&mc.db, repo));
cl_git_pass(git_odb_foreach(mc.db, &exhaustive_commits, &mc));
git_vector_set_cmp(&mc.commits, commit_id_cmp);
git_vector_sort(&mc.commits);
cl_git_pass(git_bitvec_init(
&reachable,
git_vector_length(&mc.commits) * git_vector_length(&mc.commits)));
commit_count = git_vector_length(&mc.commits);
git_vector_foreach (&mc.commits, child_idx, child_commit) {
unsigned int parent_i;
/* We treat each commit as being able to reach itself. */
git_bitvec_set(&reachable, child_idx * commit_count + child_idx, true);
for (parent_i = 0; parent_i < git_commit_parentcount(child_commit); ++parent_i) {
size_t parent_idx = -1;
cl_git_pass(git_vector_bsearch2(
&parent_idx,
&mc.commits,
id_commit_id_cmp,
git_commit_parent_id(child_commit, parent_i)));
/* We have established that parent_idx is reachable from child_idx */
git_bitvec_set(&reachable, parent_idx * commit_count + child_idx, true);
}
}
/* Floyd-Warshall */
{
size_t i, j, k;
for (k = 0; k < commit_count; ++k) {
for (i = 0; i < commit_count; ++i) {
if (!git_bitvec_get(&reachable, i * commit_count + k))
continue;
for (j = 0; j < commit_count; ++j) {
if (!git_bitvec_get(&reachable, k * commit_count + j))
continue;
git_bitvec_set(&reachable, i * commit_count + j, true);
}
}
}
}
/* Try 1000 subsets of 1 through 10 entries each. */
srand(0x223ddc4b);
for (n_descendants = 1; n_descendants < 10; ++n_descendants) {
size_t test_iteration;
git_oid descendants[10];
for (test_iteration = 0; test_iteration < 1000; ++test_iteration) {
size_t descendant_i;
size_t child_idx, parent_idx;
int expected_reachable = false, actual_reachable;
git_commit *child_commit, *parent_commit;
parent_idx = rand() % commit_count;
parent_commit = (git_commit *)git_vector_get(&mc.commits, parent_idx);
for (descendant_i = 0; descendant_i < n_descendants; ++descendant_i) {
child_idx = rand() % commit_count;
child_commit = (git_commit *)git_vector_get(&mc.commits, child_idx);
expected_reachable |= git_bitvec_get(
&reachable, parent_idx * commit_count + child_idx);
git_oid_cpy(&descendants[descendant_i],
git_commit_id(child_commit));
}
actual_reachable = git_graph_reachable_from_any(
repo,
git_commit_id(parent_commit),
descendants,
n_descendants);
if (actual_reachable != expected_reachable) {
git_buf error_message_buf = GIT_BUF_INIT;
char parent_oidbuf[9] = {0}, child_oidbuf[9] = {0};
cl_git_pass(git_oid_nfmt(
parent_oidbuf, 8, git_commit_id(parent_commit)));
git_buf_printf(&error_message_buf,
"git_graph_reachable_from_any(\"%s\", %zu, "
"{",
parent_oidbuf,
n_descendants);
for (descendant_i = 0; descendant_i < n_descendants;
++descendant_i) {
cl_git_pass(
git_oid_nfmt(child_oidbuf,
8,
&descendants[descendant_i]));
git_buf_printf(&error_message_buf, " \"%s\"", child_oidbuf);
}
git_buf_printf(&error_message_buf,
" }) = %d, expected = %d",
actual_reachable,
expected_reachable);
cl_check_(actual_reachable == expected_reachable,
git_buf_cstr(&error_message_buf));
}
}
}
git_vector_foreach (&mc.commits, child_idx, child_commit)
git_commit_free(child_commit);
git_bitvec_free(&reachable);
git_vector_free(&mc.commits);
git_odb_free(mc.db);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/worktree/bare.c
|
#include "clar_libgit2.h"
#include "worktree_helpers.h"
#include "submodule/submodule_helpers.h"
#define COMMON_REPO "testrepo.git"
#define WORKTREE_REPO "worktree"
static git_repository *g_repo;
void test_worktree_bare__initialize(void)
{
g_repo = cl_git_sandbox_init(COMMON_REPO);
cl_assert_equal_i(1, git_repository_is_bare(g_repo));
cl_assert_equal_i(0, git_repository_is_worktree(g_repo));
}
void test_worktree_bare__cleanup(void)
{
cl_fixture_cleanup(WORKTREE_REPO);
cl_git_sandbox_cleanup();
}
void test_worktree_bare__list(void)
{
git_strarray wts;
cl_git_pass(git_worktree_list(&wts, g_repo));
cl_assert_equal_i(wts.count, 0);
git_strarray_dispose(&wts);
}
void test_worktree_bare__add(void)
{
git_worktree *wt;
git_repository *wtrepo;
git_strarray wts;
cl_git_pass(git_worktree_add(&wt, g_repo, "name", WORKTREE_REPO, NULL));
cl_git_pass(git_worktree_list(&wts, g_repo));
cl_assert_equal_i(wts.count, 1);
cl_git_pass(git_worktree_validate(wt));
cl_git_pass(git_repository_open(&wtrepo, WORKTREE_REPO));
cl_assert_equal_i(0, git_repository_is_bare(wtrepo));
cl_assert_equal_i(1, git_repository_is_worktree(wtrepo));
git_strarray_dispose(&wts);
git_worktree_free(wt);
git_repository_free(wtrepo);
}
void test_worktree_bare__repository_path(void)
{
git_worktree *wt;
git_repository *wtrepo;
cl_git_pass(git_worktree_add(&wt, g_repo, "name", WORKTREE_REPO, NULL));
cl_assert_equal_s(git_worktree_path(wt), cl_git_sandbox_path(0, WORKTREE_REPO, NULL));
cl_git_pass(git_repository_open(&wtrepo, WORKTREE_REPO));
cl_assert_equal_s(git_repository_path(wtrepo), cl_git_sandbox_path(1, COMMON_REPO, "worktrees", "name", NULL));
cl_assert_equal_s(git_repository_commondir(g_repo), git_repository_commondir(wtrepo));
cl_assert_equal_s(git_repository_workdir(wtrepo), cl_git_sandbox_path(1, WORKTREE_REPO, NULL));
git_repository_free(wtrepo);
git_worktree_free(wt);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/worktree/submodule.c
|
#include "clar_libgit2.h"
#include "repository.h"
#include "worktree.h"
#include "worktree_helpers.h"
#define WORKTREE_PARENT "submodules-worktree-parent"
#define WORKTREE_CHILD "submodules-worktree-child"
static worktree_fixture parent
= WORKTREE_FIXTURE_INIT("submodules", WORKTREE_PARENT);
static worktree_fixture child
= WORKTREE_FIXTURE_INIT(NULL, WORKTREE_CHILD);
void test_worktree_submodule__initialize(void)
{
setup_fixture_worktree(&parent);
cl_git_pass(p_rename(
"submodules/testrepo/.gitted",
"submodules/testrepo/.git"));
setup_fixture_worktree(&child);
}
void test_worktree_submodule__cleanup(void)
{
cleanup_fixture_worktree(&child);
cleanup_fixture_worktree(&parent);
}
void test_worktree_submodule__submodule_worktree_parent(void)
{
cl_assert(git_repository_path(parent.worktree) != NULL);
cl_assert(git_repository_workdir(parent.worktree) != NULL);
cl_assert(!parent.repo->is_worktree);
cl_assert(parent.worktree->is_worktree);
}
void test_worktree_submodule__submodule_worktree_child(void)
{
cl_assert(!parent.repo->is_worktree);
cl_assert(parent.worktree->is_worktree);
cl_assert(child.worktree->is_worktree);
}
void test_worktree_submodule__open_discovered_submodule_worktree(void)
{
git_buf path = GIT_BUF_INIT;
git_repository *repo;
cl_git_pass(git_repository_discover(&path,
git_repository_workdir(child.worktree), false, NULL));
cl_git_pass(git_repository_open(&repo, path.ptr));
cl_assert_equal_s(git_repository_workdir(child.worktree),
git_repository_workdir(repo));
git_buf_dispose(&path);
git_repository_free(repo);
}
void test_worktree_submodule__resolve_relative_url(void)
{
git_buf wt_path = GIT_BUF_INIT;
git_buf sm_relative_path = GIT_BUF_INIT, wt_relative_path = GIT_BUF_INIT;
git_repository *repo;
git_worktree *wt;
cl_git_pass(git_futils_mkdir("subdir", 0755, GIT_MKDIR_PATH));
cl_git_pass(git_path_prettify_dir(&wt_path, "subdir", NULL));
cl_git_pass(git_buf_joinpath(&wt_path, wt_path.ptr, "wt"));
/* Open child repository, which is a submodule */
cl_git_pass(git_repository_open(&child.repo, WORKTREE_CHILD));
/* Create worktree of submodule repository */
cl_git_pass(git_worktree_add(&wt, child.repo, "subdir", wt_path.ptr, NULL));
cl_git_pass(git_repository_open_from_worktree(&repo, wt));
cl_git_pass(git_submodule_resolve_url(&sm_relative_path, repo,
"../" WORKTREE_CHILD));
cl_git_pass(git_submodule_resolve_url(&wt_relative_path, child.repo,
"../" WORKTREE_CHILD));
cl_assert_equal_s(sm_relative_path.ptr, wt_relative_path.ptr);
git_worktree_free(wt);
git_repository_free(repo);
git_buf_dispose(&wt_path);
git_buf_dispose(&sm_relative_path);
git_buf_dispose(&wt_relative_path);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/worktree/worktree.c
|
#include "clar_libgit2.h"
#include "worktree_helpers.h"
#include "submodule/submodule_helpers.h"
#include "checkout.h"
#include "repository.h"
#include "worktree.h"
#define COMMON_REPO "testrepo"
#define WORKTREE_REPO "testrepo-worktree"
static worktree_fixture fixture =
WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO);
void test_worktree_worktree__initialize(void)
{
setup_fixture_worktree(&fixture);
}
void test_worktree_worktree__cleanup(void)
{
cleanup_fixture_worktree(&fixture);
}
void test_worktree_worktree__list(void)
{
git_strarray wts;
cl_git_pass(git_worktree_list(&wts, fixture.repo));
cl_assert_equal_i(wts.count, 1);
cl_assert_equal_s(wts.strings[0], "testrepo-worktree");
git_strarray_dispose(&wts);
}
void test_worktree_worktree__list_with_invalid_worktree_dirs(void)
{
const char *filesets[3][2] = {
{ "gitdir", "commondir" },
{ "gitdir", "HEAD" },
{ "HEAD", "commondir" },
};
git_buf path = GIT_BUF_INIT;
git_strarray wts;
size_t i, j, len;
cl_git_pass(git_buf_joinpath(&path,
fixture.repo->commondir,
"worktrees/invalid"));
cl_git_pass(p_mkdir(path.ptr, 0755));
len = path.size;
for (i = 0; i < ARRAY_SIZE(filesets); i++) {
for (j = 0; j < ARRAY_SIZE(filesets[i]); j++) {
git_buf_truncate(&path, len);
cl_git_pass(git_buf_joinpath(&path, path.ptr, filesets[i][j]));
cl_git_pass(p_close(p_creat(path.ptr, 0644)));
}
cl_git_pass(git_worktree_list(&wts, fixture.worktree));
cl_assert_equal_i(wts.count, 1);
cl_assert_equal_s(wts.strings[0], "testrepo-worktree");
git_strarray_dispose(&wts);
for (j = 0; j < ARRAY_SIZE(filesets[i]); j++) {
git_buf_truncate(&path, len);
cl_git_pass(git_buf_joinpath(&path, path.ptr, filesets[i][j]));
p_unlink(path.ptr);
}
}
git_buf_dispose(&path);
}
void test_worktree_worktree__list_in_worktree_repo(void)
{
git_strarray wts;
cl_git_pass(git_worktree_list(&wts, fixture.worktree));
cl_assert_equal_i(wts.count, 1);
cl_assert_equal_s(wts.strings[0], "testrepo-worktree");
git_strarray_dispose(&wts);
}
void test_worktree_worktree__list_without_worktrees(void)
{
git_repository *repo;
git_strarray wts;
repo = cl_git_sandbox_init("testrepo2");
cl_git_pass(git_worktree_list(&wts, repo));
cl_assert_equal_i(wts.count, 0);
git_repository_free(repo);
}
void test_worktree_worktree__lookup(void)
{
git_worktree *wt;
git_buf gitdir_path = GIT_BUF_INIT;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_pass(git_buf_joinpath(&gitdir_path, fixture.repo->commondir, "worktrees/testrepo-worktree/"));
cl_assert_equal_s(wt->gitdir_path, gitdir_path.ptr);
cl_assert_equal_s(wt->parent_path, fixture.repo->workdir);
cl_assert_equal_s(wt->gitlink_path, fixture.worktree->gitlink);
cl_assert_equal_s(wt->commondir_path, fixture.repo->gitdir);
cl_assert_equal_s(wt->commondir_path, fixture.repo->commondir);
git_buf_dispose(&gitdir_path);
git_worktree_free(wt);
}
void test_worktree_worktree__lookup_nonexistent_worktree(void)
{
git_worktree *wt;
cl_git_fail(git_worktree_lookup(&wt, fixture.repo, "nonexistent"));
cl_assert_equal_p(wt, NULL);
}
void test_worktree_worktree__open(void)
{
git_worktree *wt;
git_repository *repo;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_pass(git_repository_open_from_worktree(&repo, wt));
cl_assert_equal_s(git_repository_workdir(repo),
git_repository_workdir(fixture.worktree));
git_repository_free(repo);
git_worktree_free(wt);
}
void test_worktree_worktree__open_invalid_commondir(void)
{
git_worktree *wt;
git_repository *repo;
git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/commondir"));
cl_git_pass(git_buf_joinpath(&path,
fixture.repo->commondir,
"worktrees/testrepo-worktree/commondir"));
cl_git_pass(git_futils_writebuffer(&buf, path.ptr, O_RDWR, 0644));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_fail(git_repository_open_from_worktree(&repo, wt));
git_buf_dispose(&buf);
git_buf_dispose(&path);
git_worktree_free(wt);
}
void test_worktree_worktree__open_invalid_gitdir(void)
{
git_worktree *wt;
git_repository *repo;
git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/gitdir"));
cl_git_pass(git_buf_joinpath(&path,
fixture.repo->commondir,
"worktrees/testrepo-worktree/gitdir"));
cl_git_pass(git_futils_writebuffer(&buf, path.ptr, O_RDWR, 0644));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_fail(git_repository_open_from_worktree(&repo, wt));
git_buf_dispose(&buf);
git_buf_dispose(&path);
git_worktree_free(wt);
}
void test_worktree_worktree__open_invalid_parent(void)
{
git_worktree *wt;
git_repository *repo;
git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/gitdir"));
cl_git_pass(git_futils_writebuffer(&buf,
fixture.worktree->gitlink, O_RDWR, 0644));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_fail(git_repository_open_from_worktree(&repo, wt));
git_buf_dispose(&buf);
git_worktree_free(wt);
}
void test_worktree_worktree__init(void)
{
git_worktree *wt;
git_repository *repo;
git_reference *branch;
git_buf path = GIT_BUF_INIT;
cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
/* Open and verify created repo */
cl_git_pass(git_repository_open(&repo, path.ptr));
cl_assert(git__suffixcmp(git_repository_workdir(repo), "worktree-new/") == 0);
cl_git_pass(git_branch_lookup(&branch, repo, "worktree-new", GIT_BRANCH_LOCAL));
git_buf_dispose(&path);
git_worktree_free(wt);
git_reference_free(branch);
git_repository_free(repo);
}
void test_worktree_worktree__add_locked(void)
{
git_worktree *wt;
git_repository *repo;
git_reference *branch;
git_buf path = GIT_BUF_INIT;
git_worktree_add_options opts = GIT_WORKTREE_ADD_OPTIONS_INIT;
opts.lock = 1;
cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-locked"));
cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-locked", path.ptr, &opts));
/* Open and verify created repo */
cl_assert(git_worktree_is_locked(NULL, wt));
cl_git_pass(git_repository_open(&repo, path.ptr));
cl_assert(git__suffixcmp(git_repository_workdir(repo), "worktree-locked/") == 0);
cl_git_pass(git_branch_lookup(&branch, repo, "worktree-locked", GIT_BRANCH_LOCAL));
git_buf_dispose(&path);
git_worktree_free(wt);
git_reference_free(branch);
git_repository_free(repo);
}
void test_worktree_worktree__init_existing_branch(void)
{
git_reference *head, *branch;
git_commit *commit;
git_worktree *wt;
git_buf path = GIT_BUF_INIT;
cl_git_pass(git_repository_head(&head, fixture.repo));
cl_git_pass(git_commit_lookup(&commit, fixture.repo, &head->target.oid));
cl_git_pass(git_branch_create(&branch, fixture.repo, "worktree-new", commit, false));
cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
cl_git_fail(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
git_buf_dispose(&path);
git_commit_free(commit);
git_reference_free(head);
git_reference_free(branch);
}
void test_worktree_worktree__add_with_explicit_branch(void)
{
git_reference *head, *branch, *wthead;
git_commit *commit;
git_worktree *wt;
git_repository *wtrepo;
git_buf path = GIT_BUF_INIT;
git_worktree_add_options opts = GIT_WORKTREE_ADD_OPTIONS_INIT;
cl_git_pass(git_repository_head(&head, fixture.repo));
cl_git_pass(git_commit_lookup(&commit, fixture.repo, &head->target.oid));
cl_git_pass(git_branch_create(&branch, fixture.repo, "worktree-with-ref", commit, false));
opts.ref = branch;
cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-with-different-name"));
cl_git_pass(git_worktree_add(&wt, fixture.repo, "worktree-with-different-name", path.ptr, &opts));
cl_git_pass(git_repository_open_from_worktree(&wtrepo, wt));
cl_git_pass(git_repository_head(&wthead, wtrepo));
cl_assert_equal_s(git_reference_name(wthead), "refs/heads/worktree-with-ref");
git_buf_dispose(&path);
git_commit_free(commit);
git_reference_free(head);
git_reference_free(branch);
git_reference_free(wthead);
git_repository_free(wtrepo);
git_worktree_free(wt);
}
void test_worktree_worktree__init_existing_worktree(void)
{
git_worktree *wt;
git_buf path = GIT_BUF_INIT;
cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../worktree-new"));
cl_git_fail(git_worktree_add(&wt, fixture.repo, "testrepo-worktree", path.ptr, NULL));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_assert_equal_s(wt->gitlink_path, fixture.worktree->gitlink);
git_buf_dispose(&path);
git_worktree_free(wt);
}
void test_worktree_worktree__init_existing_path(void)
{
const char *wtfiles[] = { "HEAD", "commondir", "gitdir", "index" };
git_worktree *wt;
git_buf path = GIT_BUF_INIT;
unsigned i;
/* Delete files to verify they have not been created by
* the init call */
for (i = 0; i < ARRAY_SIZE(wtfiles); i++) {
cl_git_pass(git_buf_joinpath(&path,
fixture.worktree->gitdir, wtfiles[i]));
cl_git_pass(p_unlink(path.ptr));
}
cl_git_pass(git_buf_joinpath(&path, fixture.repo->workdir, "../testrepo-worktree"));
cl_git_fail(git_worktree_add(&wt, fixture.repo, "worktree-new", path.ptr, NULL));
/* Verify files have not been re-created */
for (i = 0; i < ARRAY_SIZE(wtfiles); i++) {
cl_git_pass(git_buf_joinpath(&path,
fixture.worktree->gitdir, wtfiles[i]));
cl_assert(!git_path_exists(path.ptr));
}
git_buf_dispose(&path);
}
void test_worktree_worktree__init_submodule(void)
{
git_repository *repo, *sm, *wt;
git_worktree *worktree;
git_buf path = GIT_BUF_INIT;
cleanup_fixture_worktree(&fixture);
repo = setup_fixture_submod2();
cl_git_pass(git_buf_joinpath(&path, repo->workdir, "sm_unchanged"));
cl_git_pass(git_repository_open(&sm, path.ptr));
cl_git_pass(git_buf_joinpath(&path, repo->workdir, "../worktree/"));
cl_git_pass(git_worktree_add(&worktree, sm, "repo-worktree", path.ptr, NULL));
cl_git_pass(git_repository_open_from_worktree(&wt, worktree));
cl_git_pass(git_path_prettify_dir(&path, path.ptr, NULL));
cl_assert_equal_s(path.ptr, wt->workdir);
cl_git_pass(git_path_prettify_dir(&path, sm->commondir, NULL));
cl_assert_equal_s(sm->commondir, wt->commondir);
cl_git_pass(git_buf_joinpath(&path, sm->gitdir, "worktrees/repo-worktree/"));
cl_assert_equal_s(path.ptr, wt->gitdir);
git_buf_dispose(&path);
git_worktree_free(worktree);
git_repository_free(sm);
git_repository_free(wt);
}
void test_worktree_worktree__validate(void)
{
git_worktree *wt;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_pass(git_worktree_validate(wt));
git_worktree_free(wt);
}
void test_worktree_worktree__name(void)
{
git_worktree *wt;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_assert_equal_s(git_worktree_name(wt), "testrepo-worktree");
git_worktree_free(wt);
}
void test_worktree_worktree__path(void)
{
git_worktree *wt;
git_buf expected_path = GIT_BUF_INIT;
cl_git_pass(git_buf_joinpath(&expected_path, clar_sandbox_path(), "testrepo-worktree"));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_assert_equal_s(git_worktree_path(wt), expected_path.ptr);
git_buf_dispose(&expected_path);
git_worktree_free(wt);
}
void test_worktree_worktree__validate_invalid_commondir(void)
{
git_worktree *wt;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
git__free(wt->commondir_path);
wt->commondir_path = "/path/to/invalid/commondir";
cl_git_fail(git_worktree_validate(wt));
wt->commondir_path = NULL;
git_worktree_free(wt);
}
void test_worktree_worktree__validate_invalid_gitdir(void)
{
git_worktree *wt;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
git__free(wt->gitdir_path);
wt->gitdir_path = "/path/to/invalid/gitdir";
cl_git_fail(git_worktree_validate(wt));
wt->gitdir_path = NULL;
git_worktree_free(wt);
}
void test_worktree_worktree__validate_invalid_parent(void)
{
git_worktree *wt;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
git__free(wt->parent_path);
wt->parent_path = "/path/to/invalid/parent";
cl_git_fail(git_worktree_validate(wt));
wt->parent_path = NULL;
git_worktree_free(wt);
}
void test_worktree_worktree__lock_with_reason(void)
{
git_worktree *wt;
git_buf reason = GIT_BUF_INIT;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_assert(!git_worktree_is_locked(NULL, wt));
cl_git_pass(git_worktree_lock(wt, "because"));
cl_assert(git_worktree_is_locked(&reason, wt) > 0);
cl_assert_equal_s(reason.ptr, "because");
cl_assert(wt->locked);
git_buf_dispose(&reason);
git_worktree_free(wt);
}
void test_worktree_worktree__lock_without_reason(void)
{
git_worktree *wt;
git_buf reason = GIT_BUF_INIT;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_assert(!git_worktree_is_locked(NULL, wt));
cl_git_pass(git_worktree_lock(wt, NULL));
cl_assert(git_worktree_is_locked(&reason, wt) > 0);
cl_assert_equal_i(reason.size, 0);
cl_assert(wt->locked);
git_buf_dispose(&reason);
git_worktree_free(wt);
}
void test_worktree_worktree__unlock_unlocked_worktree(void)
{
git_worktree *wt;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_assert(!git_worktree_is_locked(NULL, wt));
cl_assert_equal_i(1, git_worktree_unlock(wt));
cl_assert(!wt->locked);
git_worktree_free(wt);
}
void test_worktree_worktree__unlock_locked_worktree(void)
{
git_worktree *wt;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_pass(git_worktree_lock(wt, NULL));
cl_assert(git_worktree_is_locked(NULL, wt));
cl_assert_equal_i(0, git_worktree_unlock(wt));
cl_assert(!wt->locked);
git_worktree_free(wt);
}
void test_worktree_worktree__prune_without_opts_fails(void)
{
git_worktree *wt;
git_repository *repo;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_fail(git_worktree_prune(wt, NULL));
/* Assert the repository is still valid */
cl_git_pass(git_repository_open_from_worktree(&repo, wt));
git_worktree_free(wt);
git_repository_free(repo);
}
void test_worktree_worktree__prune_valid(void)
{
git_worktree_prune_options opts = GIT_WORKTREE_PRUNE_OPTIONS_INIT;
git_worktree *wt;
git_repository *repo;
opts.flags = GIT_WORKTREE_PRUNE_VALID;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_pass(git_worktree_prune(wt, &opts));
/* Assert the repository is not valid anymore */
cl_git_fail(git_repository_open_from_worktree(&repo, wt));
git_worktree_free(wt);
git_repository_free(repo);
}
void test_worktree_worktree__prune_locked(void)
{
git_worktree_prune_options opts = GIT_WORKTREE_PRUNE_OPTIONS_INIT;
git_worktree *wt;
git_repository *repo;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_pass(git_worktree_lock(wt, NULL));
opts.flags = GIT_WORKTREE_PRUNE_VALID;
cl_git_fail(git_worktree_prune(wt, &opts));
/* Assert the repository is still valid */
cl_git_pass(git_repository_open_from_worktree(&repo, wt));
opts.flags = GIT_WORKTREE_PRUNE_VALID|GIT_WORKTREE_PRUNE_LOCKED;
cl_git_pass(git_worktree_prune(wt, &opts));
git_worktree_free(wt);
git_repository_free(repo);
}
void test_worktree_worktree__prune_gitdir_only(void)
{
git_worktree_prune_options opts = GIT_WORKTREE_PRUNE_OPTIONS_INIT;
git_worktree *wt;
opts.flags = GIT_WORKTREE_PRUNE_VALID;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_pass(git_worktree_prune(wt, &opts));
cl_assert(!git_path_exists(wt->gitdir_path));
cl_assert(git_path_exists(wt->gitlink_path));
git_worktree_free(wt);
}
void test_worktree_worktree__prune_worktree(void)
{
git_worktree_prune_options opts = GIT_WORKTREE_PRUNE_OPTIONS_INIT;
git_worktree *wt;
opts.flags = GIT_WORKTREE_PRUNE_VALID|GIT_WORKTREE_PRUNE_WORKING_TREE;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_pass(git_worktree_prune(wt, &opts));
cl_assert(!git_path_exists(wt->gitdir_path));
cl_assert(!git_path_exists(wt->gitlink_path));
git_worktree_free(wt);
}
static int foreach_worktree_cb(git_repository *worktree, void *payload)
{
int *counter = (int *)payload;
switch (*counter) {
case 0:
cl_assert_equal_s(git_repository_path(fixture.repo),
git_repository_path(worktree));
cl_assert(!git_repository_is_worktree(worktree));
break;
case 1:
cl_assert_equal_s(git_repository_path(fixture.worktree),
git_repository_path(worktree));
cl_assert(git_repository_is_worktree(worktree));
break;
default:
cl_fail("more worktrees found than expected");
}
(*counter)++;
return 0;
}
void test_worktree_worktree__foreach_worktree_lists_all_worktrees(void)
{
int counter = 0;
cl_git_pass(git_repository_foreach_worktree(fixture.repo, foreach_worktree_cb, &counter));
}
void test_worktree_worktree__validate_invalid_worktreedir(void)
{
git_worktree *wt;
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
p_rename("testrepo-worktree", "testrepo-worktree-tmp");
cl_git_fail(git_worktree_validate(wt));
p_rename("testrepo-worktree-tmp", "testrepo-worktree");
git_worktree_free(wt);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/worktree/reflog.c
|
#include "clar_libgit2.h"
#include "worktree_helpers.h"
#include "reflog.h"
#define COMMON_REPO "testrepo"
#define WORKTREE_REPO "testrepo-worktree"
#define REFLOG "refs/heads/testrepo-worktree"
#define REFLOG_MESSAGE "reflog message"
static worktree_fixture fixture =
WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO);
void test_worktree_reflog__initialize(void)
{
setup_fixture_worktree(&fixture);
}
void test_worktree_reflog__cleanup(void)
{
cleanup_fixture_worktree(&fixture);
}
void test_worktree_reflog__read_worktree_HEAD(void)
{
git_reflog *reflog;
const git_reflog_entry *entry;
cl_git_pass(git_reflog_read(&reflog, fixture.worktree, "HEAD"));
cl_assert_equal_i(1, git_reflog_entrycount(reflog));
entry = git_reflog_entry_byindex(reflog, 0);
cl_assert(entry != NULL);
cl_assert_equal_s("checkout: moving from 099fabac3a9ea935598528c27f866e34089c2eff to testrepo-worktree", git_reflog_entry_message(entry));
git_reflog_free(reflog);
}
void test_worktree_reflog__read_parent_HEAD(void)
{
git_reflog *reflog;
cl_git_pass(git_reflog_read(&reflog, fixture.repo, "HEAD"));
/* there is no logs/HEAD in the parent repo */
cl_assert_equal_i(0, git_reflog_entrycount(reflog));
git_reflog_free(reflog);
}
void test_worktree_reflog__read(void)
{
git_reflog *reflog;
const git_reflog_entry *entry;
cl_git_pass(git_reflog_read(&reflog, fixture.worktree, REFLOG));
cl_assert_equal_i(git_reflog_entrycount(reflog), 1);
entry = git_reflog_entry_byindex(reflog, 0);
cl_assert(entry != NULL);
cl_assert_equal_s(git_reflog_entry_message(entry), "branch: Created from HEAD");
git_reflog_free(reflog);
}
void test_worktree_reflog__append_then_read(void)
{
git_reflog *reflog, *parent_reflog;
const git_reflog_entry *entry;
git_reference *head;
git_signature *sig;
const git_oid *oid;
cl_git_pass(git_repository_head(&head, fixture.worktree));
cl_assert((oid = git_reference_target(head)) != NULL);
cl_git_pass(git_signature_now(&sig, "foo", "foo@bar"));
cl_git_pass(git_reflog_read(&reflog, fixture.worktree, REFLOG));
cl_git_pass(git_reflog_append(reflog, oid, sig, REFLOG_MESSAGE));
git_reflog_write(reflog);
cl_git_pass(git_reflog_read(&parent_reflog, fixture.repo, REFLOG));
entry = git_reflog_entry_byindex(parent_reflog, 0);
cl_assert(git_oid_cmp(oid, &entry->oid_old) == 0);
cl_assert(git_oid_cmp(oid, &entry->oid_cur) == 0);
git_reference_free(head);
git_signature_free(sig);
git_reflog_free(reflog);
git_reflog_free(parent_reflog);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/worktree/repository.c
|
#include "clar_libgit2.h"
#include "worktree_helpers.h"
#include "submodule/submodule_helpers.h"
#include "repository.h"
#define COMMON_REPO "testrepo"
#define WORKTREE_REPO "testrepo-worktree"
static worktree_fixture fixture =
WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO);
void test_worktree_repository__initialize(void)
{
setup_fixture_worktree(&fixture);
}
void test_worktree_repository__cleanup(void)
{
cleanup_fixture_worktree(&fixture);
}
void test_worktree_repository__head(void)
{
git_reference *ref, *head;
cl_git_pass(git_reference_lookup(&ref, fixture.repo, "refs/heads/testrepo-worktree"));
cl_git_pass(git_repository_head_for_worktree(&head, fixture.repo, "testrepo-worktree"));
cl_assert(git_reference_cmp(ref, head) == 0);
cl_assert(git_reference_owner(ref) == fixture.repo);
git_reference_free(ref);
git_reference_free(head);
}
void test_worktree_repository__head_fails_for_invalid_worktree(void)
{
git_reference *head = NULL;
cl_git_fail(git_repository_head_for_worktree(&head, fixture.repo, "invalid"));
cl_assert(head == NULL);
}
void test_worktree_repository__head_detached(void)
{
git_reference *ref, *head;
cl_git_pass(git_reference_lookup(&ref, fixture.repo, "refs/heads/testrepo-worktree"));
cl_git_pass(git_repository_set_head_detached(fixture.worktree, &ref->target.oid));
cl_assert(git_repository_head_detached(fixture.worktree));
cl_assert(git_repository_head_detached_for_worktree(fixture.repo, "testrepo-worktree"));
cl_git_pass(git_repository_head_for_worktree(&head, fixture.repo, "testrepo-worktree"));
cl_assert_equal_oid(&ref->target.oid, &head->target.oid);
git_reference_free(ref);
git_reference_free(head);
}
void test_worktree_repository__head_detached_fails_for_invalid_worktree(void)
{
git_reference *head = NULL;
cl_git_fail(git_repository_head_detached_for_worktree(fixture.repo, "invalid"));
cl_assert(head == NULL);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/worktree/worktree_helpers.h
|
typedef struct {
const char *reponame;
const char *worktreename;
git_repository *repo;
git_repository *worktree;
} worktree_fixture;
#define WORKTREE_FIXTURE_INIT(repo, worktree) { (repo), (worktree), NULL, NULL }
void cleanup_fixture_worktree(worktree_fixture *fixture);
void setup_fixture_worktree(worktree_fixture *fixture);
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/worktree/merge.c
|
#include "clar_libgit2.h"
#include "worktree_helpers.h"
#include "merge/merge_helpers.h"
#define COMMON_REPO "testrepo"
#define WORKTREE_REPO "testrepo-worktree"
#define MASTER_BRANCH "refs/heads/master"
#define CONFLICT_BRANCH "refs/heads/merge-conflict"
#define CONFLICT_BRANCH_FILE_TXT \
"<<<<<<< HEAD\n" \
"hi\n" \
"bye!\n" \
"=======\n" \
"conflict\n" \
">>>>>>> merge-conflict\n" \
static worktree_fixture fixture =
WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO);
static const char *merge_files[] = {
GIT_MERGE_HEAD_FILE,
GIT_ORIG_HEAD_FILE,
GIT_MERGE_MODE_FILE,
GIT_MERGE_MSG_FILE,
};
void test_worktree_merge__initialize(void)
{
setup_fixture_worktree(&fixture);
}
void test_worktree_merge__cleanup(void)
{
cleanup_fixture_worktree(&fixture);
}
void test_worktree_merge__merge_head(void)
{
git_reference *theirs_ref, *ref;
git_annotated_commit *theirs;
cl_git_pass(git_reference_lookup(&theirs_ref, fixture.worktree, CONFLICT_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&theirs, fixture.worktree, theirs_ref));
cl_git_pass(git_merge(fixture.worktree, (const git_annotated_commit **)&theirs, 1, NULL, NULL));
cl_git_pass(git_reference_lookup(&ref, fixture.worktree, GIT_MERGE_HEAD_FILE));
git_reference_free(ref);
git_reference_free(theirs_ref);
git_annotated_commit_free(theirs);
}
void test_worktree_merge__merge_setup(void)
{
git_reference *ours_ref, *theirs_ref;
git_annotated_commit *ours, *theirs;
git_buf path = GIT_BUF_INIT;
unsigned i;
cl_git_pass(git_reference_lookup(&ours_ref, fixture.worktree, MASTER_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&ours, fixture.worktree, ours_ref));
cl_git_pass(git_reference_lookup(&theirs_ref, fixture.worktree, CONFLICT_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&theirs, fixture.worktree, theirs_ref));
cl_git_pass(git_merge__setup(fixture.worktree,
ours, (const git_annotated_commit **)&theirs, 1));
for (i = 0; i < ARRAY_SIZE(merge_files); i++) {
cl_git_pass(git_buf_joinpath(&path,
fixture.worktree->gitdir,
merge_files[i]));
cl_assert(git_path_exists(path.ptr));
}
git_buf_dispose(&path);
git_reference_free(ours_ref);
git_reference_free(theirs_ref);
git_annotated_commit_free(ours);
git_annotated_commit_free(theirs);
}
void test_worktree_merge__merge_conflict(void)
{
git_buf path = GIT_BUF_INIT, buf = GIT_BUF_INIT;
git_reference *theirs_ref;
git_annotated_commit *theirs;
git_index *index;
const git_index_entry *entry;
size_t i, conflicts = 0;
cl_git_pass(git_reference_lookup(&theirs_ref, fixture.worktree, CONFLICT_BRANCH));
cl_git_pass(git_annotated_commit_from_ref(&theirs, fixture.worktree, theirs_ref));
cl_git_pass(git_merge(fixture.worktree,
(const git_annotated_commit **)&theirs, 1, NULL, NULL));
cl_git_pass(git_repository_index(&index, fixture.worktree));
for (i = 0; i < git_index_entrycount(index); i++) {
cl_assert(entry = git_index_get_byindex(index, i));
if (git_index_entry_is_conflict(entry))
conflicts++;
}
cl_assert_equal_sz(conflicts, 3);
git_reference_free(theirs_ref);
git_annotated_commit_free(theirs);
git_index_free(index);
cl_git_pass(git_buf_joinpath(&path, fixture.worktree->workdir, "branch_file.txt"));
cl_git_pass(git_futils_readbuffer(&buf, path.ptr));
cl_assert_equal_s(buf.ptr, CONFLICT_BRANCH_FILE_TXT);
git_buf_dispose(&path);
git_buf_dispose(&buf);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/worktree/open.c
|
#include "clar_libgit2.h"
#include "repository.h"
#include "worktree.h"
#include "worktree_helpers.h"
#define COMMON_REPO "testrepo"
#define WORKTREE_REPO "testrepo-worktree"
static worktree_fixture fixture =
WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO);
static void assert_worktree_valid(git_repository *wt, const char *parentdir, const char *wtdir)
{
cl_assert(wt->is_worktree);
cl_assert_equal_s(wt->workdir, cl_git_sandbox_path(1, wtdir, NULL));
cl_assert_equal_s(wt->gitlink, cl_git_sandbox_path(0, wtdir, ".git", NULL));
cl_assert_equal_s(wt->gitdir, cl_git_sandbox_path(1, parentdir, ".git", "worktrees", wtdir, NULL));
}
void test_worktree_open__initialize(void)
{
setup_fixture_worktree(&fixture);
}
void test_worktree_open__cleanup(void)
{
cleanup_fixture_worktree(&fixture);
}
void test_worktree_open__repository(void)
{
assert_worktree_valid(fixture.worktree, COMMON_REPO, WORKTREE_REPO);
}
void test_worktree_open__repository_through_workdir(void)
{
git_repository *wt;
cl_git_pass(git_repository_open(&wt, WORKTREE_REPO));
assert_worktree_valid(wt, COMMON_REPO, WORKTREE_REPO);
git_repository_free(wt);
}
void test_worktree_open__repository_through_gitlink(void)
{
git_repository *wt;
cl_git_pass(git_repository_open(&wt, WORKTREE_REPO "/.git"));
assert_worktree_valid(wt, COMMON_REPO, WORKTREE_REPO);
git_repository_free(wt);
}
void test_worktree_open__repository_through_gitdir(void)
{
git_buf gitdir_path = GIT_BUF_INIT;
git_repository *wt;
cl_git_pass(git_buf_joinpath(&gitdir_path, COMMON_REPO, ".git"));
cl_git_pass(git_buf_joinpath(&gitdir_path, gitdir_path.ptr, "worktrees"));
cl_git_pass(git_buf_joinpath(&gitdir_path, gitdir_path.ptr, "testrepo-worktree"));
cl_git_pass(git_repository_open(&wt, gitdir_path.ptr));
assert_worktree_valid(wt, COMMON_REPO, WORKTREE_REPO);
git_buf_dispose(&gitdir_path);
git_repository_free(wt);
}
void test_worktree_open__open_discovered_worktree(void)
{
git_buf path = GIT_BUF_INIT;
git_repository *repo;
cl_git_pass(git_repository_discover(&path,
git_repository_workdir(fixture.worktree), false, NULL));
cl_git_pass(git_repository_open(&repo, path.ptr));
cl_assert_equal_s(git_repository_workdir(fixture.worktree),
git_repository_workdir(repo));
git_buf_dispose(&path);
git_repository_free(repo);
}
void test_worktree_open__repository_with_nonexistent_parent(void)
{
git_repository *repo;
cleanup_fixture_worktree(&fixture);
cl_fixture_sandbox(WORKTREE_REPO);
cl_git_pass(p_chdir(WORKTREE_REPO));
cl_git_pass(cl_rename(".gitted", ".git"));
cl_git_pass(p_chdir(".."));
cl_git_fail(git_repository_open(&repo, WORKTREE_REPO));
cl_fixture_cleanup(WORKTREE_REPO);
}
void test_worktree_open__open_from_repository(void)
{
git_worktree *opened, *lookedup;
cl_git_pass(git_worktree_open_from_repository(&opened, fixture.worktree));
cl_git_pass(git_worktree_lookup(&lookedup, fixture.repo, WORKTREE_REPO));
cl_assert_equal_s(opened->name, lookedup->name);
cl_assert_equal_s(opened->gitdir_path, lookedup->gitdir_path);
cl_assert_equal_s(opened->gitlink_path, lookedup->gitlink_path);
cl_assert_equal_s(opened->parent_path, lookedup->parent_path);
cl_assert_equal_s(opened->commondir_path, lookedup->commondir_path);
cl_assert_equal_i(opened->locked, lookedup->locked);
git_worktree_free(opened);
git_worktree_free(lookedup);
}
void test_worktree_open__open_from_nonworktree_fails(void)
{
git_worktree *wt;
cl_git_fail(git_worktree_open_from_repository(&wt, fixture.repo));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/worktree/worktree_helpers.c
|
#include "clar_libgit2.h"
#include "worktree_helpers.h"
void cleanup_fixture_worktree(worktree_fixture *fixture)
{
if (!fixture)
return;
if (fixture->repo) {
git_repository_free(fixture->repo);
fixture->repo = NULL;
}
if (fixture->worktree) {
git_repository_free(fixture->worktree);
fixture->worktree = NULL;
}
if (fixture->reponame)
cl_fixture_cleanup(fixture->reponame);
if (fixture->worktreename)
cl_fixture_cleanup(fixture->worktreename);
}
void setup_fixture_worktree(worktree_fixture *fixture)
{
if (fixture->reponame)
fixture->repo = cl_git_sandbox_init(fixture->reponame);
if (fixture->worktreename)
fixture->worktree = cl_git_sandbox_init(fixture->worktreename);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/worktree/refs.c
|
#include "clar_libgit2.h"
#include "path.h"
#include "refs.h"
#include "worktree.h"
#include "worktree_helpers.h"
#define COMMON_REPO "testrepo"
#define WORKTREE_REPO "testrepo-worktree"
static worktree_fixture fixture =
WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO);
void test_worktree_refs__initialize(void)
{
setup_fixture_worktree(&fixture);
}
void test_worktree_refs__cleanup(void)
{
cleanup_fixture_worktree(&fixture);
}
void test_worktree_refs__list(void)
{
git_strarray refs, wtrefs;
unsigned i, j;
int error = 0;
cl_git_pass(git_reference_list(&refs, fixture.repo));
cl_git_pass(git_reference_list(&wtrefs, fixture.worktree));
if (refs.count != wtrefs.count)
{
error = GIT_ERROR;
goto exit;
}
for (i = 0; i < refs.count; i++)
{
int found = 0;
for (j = 0; j < wtrefs.count; j++)
{
if (!strcmp(refs.strings[i], wtrefs.strings[j]))
{
found = 1;
break;
}
}
if (!found)
{
error = GIT_ERROR;
goto exit;
}
}
exit:
git_strarray_dispose(&refs);
git_strarray_dispose(&wtrefs);
cl_git_pass(error);
}
void test_worktree_refs__read_head(void)
{
git_reference *head;
cl_git_pass(git_repository_head(&head, fixture.worktree));
git_reference_free(head);
}
void test_worktree_refs__set_head_fails_when_worktree_wants_linked_repos_HEAD(void)
{
git_reference *head;
cl_git_pass(git_repository_head(&head, fixture.repo));
cl_git_fail(git_repository_set_head(fixture.worktree, git_reference_name(head)));
git_reference_free(head);
}
void test_worktree_refs__set_head_fails_when_main_repo_wants_worktree_head(void)
{
git_reference *head;
cl_git_pass(git_repository_head(&head, fixture.worktree));
cl_git_fail(git_repository_set_head(fixture.repo, git_reference_name(head)));
git_reference_free(head);
}
void test_worktree_refs__set_head_works_for_current_HEAD(void)
{
git_reference *head;
cl_git_pass(git_repository_head(&head, fixture.repo));
cl_git_pass(git_repository_set_head(fixture.repo, git_reference_name(head)));
git_reference_free(head);
}
void test_worktree_refs__set_head_fails_when_already_checked_out(void)
{
cl_git_fail(git_repository_set_head(fixture.repo, "refs/heads/testrepo-worktree"));
}
void test_worktree_refs__delete_fails_for_checked_out_branch(void)
{
git_reference *branch;
cl_git_pass(git_branch_lookup(&branch, fixture.repo,
"testrepo-worktree", GIT_BRANCH_LOCAL));
cl_git_fail(git_branch_delete(branch));
git_reference_free(branch);
}
void test_worktree_refs__delete_succeeds_after_pruning_worktree(void)
{
git_worktree_prune_options opts = GIT_WORKTREE_PRUNE_OPTIONS_INIT;
git_reference *branch;
git_worktree *worktree;
opts.flags = GIT_WORKTREE_PRUNE_VALID;
cl_git_pass(git_worktree_lookup(&worktree, fixture.repo, fixture.worktreename));
cl_git_pass(git_worktree_prune(worktree, &opts));
git_worktree_free(worktree);
cl_git_pass(git_branch_lookup(&branch, fixture.repo,
"testrepo-worktree", GIT_BRANCH_LOCAL));
cl_git_pass(git_branch_delete(branch));
git_reference_free(branch);
}
void test_worktree_refs__delete_unrelated_branch_on_worktree(void)
{
git_reference *branch;
cl_git_pass(git_branch_lookup(&branch, fixture.worktree,
"merge-conflict", GIT_BRANCH_LOCAL));
cl_git_pass(git_branch_delete(branch));
git_reference_free(branch);
}
void test_worktree_refs__delete_unrelated_branch_on_parent(void)
{
git_reference *branch;
cl_git_pass(git_branch_lookup(&branch, fixture.repo,
"merge-conflict", GIT_BRANCH_LOCAL));
cl_git_pass(git_branch_delete(branch));
git_reference_free(branch);
}
void test_worktree_refs__renaming_reference_updates_worktree_heads(void)
{
git_reference *head, *branch, *renamed;
cl_git_pass(git_branch_lookup(&branch, fixture.repo,
"testrepo-worktree", GIT_BRANCH_LOCAL));
cl_git_pass(git_reference_rename(&renamed, branch, "refs/heads/renamed", 0, NULL));
cl_git_pass(git_reference_lookup(&head, fixture.worktree, GIT_HEAD_FILE));
cl_assert_equal_i(git_reference_type(head), GIT_REFERENCE_SYMBOLIC);
cl_assert_equal_s(git_reference_symbolic_target(head), "refs/heads/renamed");
git_reference_free(head);
git_reference_free(branch);
git_reference_free(renamed);
}
void test_worktree_refs__creating_refs_uses_commondir(void)
{
git_reference *head, *branch, *lookup;
git_commit *commit;
git_buf refpath = GIT_BUF_INIT;
cl_git_pass(git_buf_joinpath(&refpath,
git_repository_commondir(fixture.worktree), "refs/heads/testbranch"));
cl_assert(!git_path_exists(refpath.ptr));
cl_git_pass(git_repository_head(&head, fixture.worktree));
cl_git_pass(git_commit_lookup(&commit, fixture.worktree, git_reference_target(head)));
cl_git_pass(git_branch_create(&branch, fixture.worktree, "testbranch", commit, 0));
cl_git_pass(git_branch_lookup(&lookup, fixture.worktree, "testbranch", GIT_BRANCH_LOCAL));
cl_assert(git_reference_cmp(branch, lookup) == 0);
cl_assert(git_path_exists(refpath.ptr));
git_reference_free(lookup);
git_reference_free(branch);
git_reference_free(head);
git_commit_free(commit);
git_buf_dispose(&refpath);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/worktree/config.c
|
#include "clar_libgit2.h"
#include "worktree_helpers.h"
#define COMMON_REPO "testrepo"
#define WORKTREE_REPO "testrepo-worktree"
static worktree_fixture fixture =
WORKTREE_FIXTURE_INIT(COMMON_REPO, WORKTREE_REPO);
void test_worktree_config__initialize(void)
{
setup_fixture_worktree(&fixture);
}
void test_worktree_config__cleanup(void)
{
cleanup_fixture_worktree(&fixture);
}
void test_worktree_config__open(void)
{
git_config *cfg;
cl_git_pass(git_repository_config(&cfg, fixture.worktree));
cl_assert(cfg != NULL);
git_config_free(cfg);
}
void test_worktree_config__set(void)
{
git_config *cfg;
int32_t val;
cl_git_pass(git_repository_config(&cfg, fixture.worktree));
cl_git_pass(git_config_set_int32(cfg, "core.dummy", 5));
git_config_free(cfg);
/*
* reopen to verify configuration has been set in the
* common dir
*/
cl_git_pass(git_repository_config(&cfg, fixture.repo));
cl_git_pass(git_config_get_int32(&val, cfg, "core.dummy"));
cl_assert_equal_i(val, 5);
git_config_free(cfg);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/blame/simple.c
|
#include "blame_helpers.h"
static git_repository *g_repo;
static git_blame *g_blame;
void test_blame_simple__initialize(void)
{
g_repo = NULL;
g_blame = NULL;
}
void test_blame_simple__cleanup(void)
{
git_blame_free(g_blame);
git_repository_free(g_repo);
}
/*
* $ git blame -s branch_file.txt
* orig line no final line no
* commit V author timestamp V
* c47800c7 1 (Scott Chacon 2010-05-25 11:58:14 -0700 1
* a65fedf3 2 (Scott Chacon 2011-08-09 19:33:46 -0700 2
*/
void test_blame_simple__trivial_testrepo(void)
{
cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo/.gitted")));
cl_git_pass(git_blame_file(&g_blame, g_repo, "branch_file.txt", NULL));
cl_assert_equal_i(2, git_blame_get_hunk_count(g_blame));
check_blame_hunk_index(g_repo, g_blame, 0, 1, 1, 0, "c47800c7", "branch_file.txt");
check_blame_hunk_index(g_repo, g_blame, 1, 2, 1, 0, "a65fedf3", "branch_file.txt");
}
/*
* $ git blame -n b.txt
* orig line no final line no
* commit V author timestamp V
* da237394 1 (Ben Straub 2013-02-12 15:11:30 -0800 1
* da237394 2 (Ben Straub 2013-02-12 15:11:30 -0800 2
* da237394 3 (Ben Straub 2013-02-12 15:11:30 -0800 3
* da237394 4 (Ben Straub 2013-02-12 15:11:30 -0800 4
* ^b99f7ac 1 (Ben Straub 2013-02-12 15:10:12 -0800 5
* 63d671eb 6 (Ben Straub 2013-02-12 15:13:04 -0800 6
* 63d671eb 7 (Ben Straub 2013-02-12 15:13:04 -0800 7
* 63d671eb 8 (Ben Straub 2013-02-12 15:13:04 -0800 8
* 63d671eb 9 (Ben Straub 2013-02-12 15:13:04 -0800 9
* 63d671eb 10 (Ben Straub 2013-02-12 15:13:04 -0800 10
* aa06ecca 6 (Ben Straub 2013-02-12 15:14:46 -0800 11
* aa06ecca 7 (Ben Straub 2013-02-12 15:14:46 -0800 12
* aa06ecca 8 (Ben Straub 2013-02-12 15:14:46 -0800 13
* aa06ecca 9 (Ben Straub 2013-02-12 15:14:46 -0800 14
* aa06ecca 10 (Ben Straub 2013-02-12 15:14:46 -0800 15
*/
void test_blame_simple__trivial_blamerepo(void)
{
cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git")));
cl_git_pass(git_blame_file(&g_blame, g_repo, "b.txt", NULL));
cl_assert_equal_i(4, git_blame_get_hunk_count(g_blame));
check_blame_hunk_index(g_repo, g_blame, 0, 1, 4, 0, "da237394", "b.txt");
check_blame_hunk_index(g_repo, g_blame, 1, 5, 1, 1, "b99f7ac0", "b.txt");
check_blame_hunk_index(g_repo, g_blame, 2, 6, 5, 0, "63d671eb", "b.txt");
check_blame_hunk_index(g_repo, g_blame, 3, 11, 5, 0, "aa06ecca", "b.txt");
}
/*
* $ git blame -n 359fc2d -- include/git2.h
* orig line no final line no
* commit orig path V author timestamp V
* d12299fe src/git.h 1 (Vicent Martí 2010-12-03 22:22:10 +0200 1
* 359fc2d2 include/git2.h 2 (Edward Thomson 2013-01-08 17:07:25 -0600 2
* d12299fe src/git.h 5 (Vicent Martí 2010-12-03 22:22:10 +0200 3
* bb742ede include/git2.h 4 (Vicent Martí 2011-09-19 01:54:32 +0300 4
* bb742ede include/git2.h 5 (Vicent Martí 2011-09-19 01:54:32 +0300 5
* d12299fe src/git.h 24 (Vicent Martí 2010-12-03 22:22:10 +0200 6
* d12299fe src/git.h 25 (Vicent Martí 2010-12-03 22:22:10 +0200 7
* d12299fe src/git.h 26 (Vicent Martí 2010-12-03 22:22:10 +0200 8
* d12299fe src/git.h 27 (Vicent Martí 2010-12-03 22:22:10 +0200 9
* d12299fe src/git.h 28 (Vicent Martí 2010-12-03 22:22:10 +0200 10
* 96fab093 include/git2.h 11 (Sven Strickroth 2011-10-09 18:37:41 +0200 11
* 9d1dcca2 src/git2.h 33 (Vicent Martí 2011-02-07 10:35:58 +0200 12
* 44908fe7 src/git2.h 29 (Vicent Martí 2010-12-06 23:03:16 +0200 13
* a15c550d include/git2.h 14 (Vicent Martí 2011-11-16 14:09:44 +0100 14
* 44908fe7 src/git2.h 30 (Vicent Martí 2010-12-06 23:03:16 +0200 15
* d12299fe src/git.h 32 (Vicent Martí 2010-12-03 22:22:10 +0200 16
* 44908fe7 src/git2.h 33 (Vicent Martí 2010-12-06 23:03:16 +0200 17
* d12299fe src/git.h 34 (Vicent Martí 2010-12-03 22:22:10 +0200 18
* 44908fe7 src/git2.h 35 (Vicent Martí 2010-12-06 23:03:16 +0200 19
* 638c2ca4 src/git2.h 36 (Vicent Martí 2010-12-18 02:10:25 +0200 20
* 44908fe7 src/git2.h 36 (Vicent Martí 2010-12-06 23:03:16 +0200 21
* d12299fe src/git.h 37 (Vicent Martí 2010-12-03 22:22:10 +0200 22
* 44908fe7 src/git2.h 38 (Vicent Martí 2010-12-06 23:03:16 +0200 23
* 44908fe7 src/git2.h 39 (Vicent Martí 2010-12-06 23:03:16 +0200 24
* bf787bd8 include/git2.h 25 (Carlos Martín Nieto 2012-04-08 18:56:50 +0200 25
* 0984c876 include/git2.h 26 (Scott J. Goldman 2012-11-28 18:27:43 -0800 26
* 2f8a8ab2 src/git2.h 41 (Vicent Martí 2011-01-29 01:56:25 +0200 27
* 27df4275 include/git2.h 47 (Michael Schubert 2011-06-28 14:13:12 +0200 28
* a346992f include/git2.h 28 (Ben Straub 2012-05-10 09:47:14 -0700 29
* d12299fe src/git.h 40 (Vicent Martí 2010-12-03 22:22:10 +0200 30
* 44908fe7 src/git2.h 41 (Vicent Martí 2010-12-06 23:03:16 +0200 31
* 44908fe7 src/git2.h 42 (Vicent Martí 2010-12-06 23:03:16 +0200 32
* 44908fe7 src/git2.h 43 (Vicent Martí 2010-12-06 23:03:16 +0200 33
* 44908fe7 src/git2.h 44 (Vicent Martí 2010-12-06 23:03:16 +0200 34
* 44908fe7 src/git2.h 45 (Vicent Martí 2010-12-06 23:03:16 +0200 35
* 65b09b1d include/git2.h 33 (Russell Belfer 2012-02-02 18:03:43 -0800 36
* d12299fe src/git.h 46 (Vicent Martí 2010-12-03 22:22:10 +0200 37
* 44908fe7 src/git2.h 47 (Vicent Martí 2010-12-06 23:03:16 +0200 38
* 5d4cd003 include/git2.h 55 (Carlos Martín Nieto 2011-03-28 17:02:45 +0200 39
* 41fb1ca0 include/git2.h 39 (Philip Kelley 2012-10-29 13:41:14 -0400 40
* 2dc31040 include/git2.h 56 (Carlos Martín Nieto 2011-06-20 18:58:57 +0200 41
* 764df57e include/git2.h 40 (Ben Straub 2012-06-15 13:14:43 -0700 42
* 5280f4e6 include/git2.h 41 (Ben Straub 2012-07-31 19:39:06 -0700 43
* 613d5eb9 include/git2.h 43 (Philip Kelley 2012-11-28 11:42:37 -0500 44
* d12299fe src/git.h 48 (Vicent Martí 2010-12-03 22:22:10 +0200 45
* 111ee3fe include/git2.h 41 (Vicent Martí 2012-07-11 14:37:26 +0200 46
* f004c4a8 include/git2.h 44 (Russell Belfer 2012-08-21 17:26:39 -0700 47
* 111ee3fe include/git2.h 42 (Vicent Martí 2012-07-11 14:37:26 +0200 48
* 9c82357b include/git2.h 58 (Carlos Martín Nieto 2011-06-17 18:13:14 +0200 49
* d6258deb include/git2.h 61 (Carlos Martín Nieto 2011-06-25 15:10:09 +0200 50
* b311e313 include/git2.h 63 (Julien Miotte 2011-07-27 18:31:13 +0200 51
* 3412391d include/git2.h 63 (Carlos Martín Nieto 2011-07-07 11:47:31 +0200 52
* bfc9ca59 include/git2.h 43 (Russell Belfer 2012-03-28 16:45:36 -0700 53
* bf477ed4 include/git2.h 44 (Michael Schubert 2012-02-15 00:33:38 +0100 54
* edebceff include/git2.h 46 (nulltoken 2012-05-01 13:57:45 +0200 55
* 743a4b3b include/git2.h 48 (nulltoken 2012-06-15 22:24:59 +0200 56
* 0a32dca5 include/git2.h 54 (Michael Schubert 2012-08-19 22:26:32 +0200 57
* 590fb68b include/git2.h 55 (nulltoken 2012-10-04 13:47:45 +0200 58
* bf477ed4 include/git2.h 45 (Michael Schubert 2012-02-15 00:33:38 +0100 59
* d12299fe src/git.h 49 (Vicent Martí 2010-12-03 22:22:10 +0200 60
*/
void test_blame_simple__trivial_libgit2(void)
{
git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
git_object *obj;
/* If we can't open the libgit2 repo or if it isn't a full repo
* with proper history, just skip this test */
if (git_repository_open(&g_repo, cl_fixture("../..")) < 0)
cl_skip();
if (git_repository_is_shallow(g_repo))
cl_skip();
if (git_revparse_single(&obj, g_repo, "359fc2d") < 0)
cl_skip();
git_oid_cpy(&opts.newest_commit, git_object_id(obj));
git_object_free(obj);
cl_git_pass(git_blame_file(&g_blame, g_repo, "include/git2.h", &opts));
check_blame_hunk_index(g_repo, g_blame, 0, 1, 1, 0, "d12299fe", "src/git.h");
check_blame_hunk_index(g_repo, g_blame, 1, 2, 1, 0, "359fc2d2", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 2, 3, 1, 0, "d12299fe", "src/git.h");
check_blame_hunk_index(g_repo, g_blame, 3, 4, 2, 0, "bb742ede", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 4, 6, 5, 0, "d12299fe", "src/git.h");
check_blame_hunk_index(g_repo, g_blame, 5, 11, 1, 0, "96fab093", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 6, 12, 1, 0, "9d1dcca2", "src/git2.h");
check_blame_hunk_index(g_repo, g_blame, 7, 13, 1, 0, "44908fe7", "src/git2.h");
check_blame_hunk_index(g_repo, g_blame, 8, 14, 1, 0, "a15c550d", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 9, 15, 1, 0, "44908fe7", "src/git2.h");
check_blame_hunk_index(g_repo, g_blame, 10, 16, 1, 0, "d12299fe", "src/git.h");
check_blame_hunk_index(g_repo, g_blame, 11, 17, 1, 0, "44908fe7", "src/git2.h");
check_blame_hunk_index(g_repo, g_blame, 12, 18, 1, 0, "d12299fe", "src/git.h");
check_blame_hunk_index(g_repo, g_blame, 13, 19, 1, 0, "44908fe7", "src/git2.h");
check_blame_hunk_index(g_repo, g_blame, 14, 20, 1, 0, "638c2ca4", "src/git2.h");
check_blame_hunk_index(g_repo, g_blame, 15, 21, 1, 0, "44908fe7", "src/git2.h");
check_blame_hunk_index(g_repo, g_blame, 16, 22, 1, 0, "d12299fe", "src/git.h");
check_blame_hunk_index(g_repo, g_blame, 17, 23, 2, 0, "44908fe7", "src/git2.h");
check_blame_hunk_index(g_repo, g_blame, 18, 25, 1, 0, "bf787bd8", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 19, 26, 1, 0, "0984c876", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 20, 27, 1, 0, "2f8a8ab2", "src/git2.h");
check_blame_hunk_index(g_repo, g_blame, 21, 28, 1, 0, "27df4275", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 22, 29, 1, 0, "a346992f", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 23, 30, 1, 0, "d12299fe", "src/git.h");
check_blame_hunk_index(g_repo, g_blame, 24, 31, 5, 0, "44908fe7", "src/git2.h");
check_blame_hunk_index(g_repo, g_blame, 25, 36, 1, 0, "65b09b1d", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 26, 37, 1, 0, "d12299fe", "src/git.h");
check_blame_hunk_index(g_repo, g_blame, 27, 38, 1, 0, "44908fe7", "src/git2.h");
check_blame_hunk_index(g_repo, g_blame, 28, 39, 1, 0, "5d4cd003", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 29, 40, 1, 0, "41fb1ca0", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 30, 41, 1, 0, "2dc31040", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 31, 42, 1, 0, "764df57e", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 32, 43, 1, 0, "5280f4e6", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 33, 44, 1, 0, "613d5eb9", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 34, 45, 1, 0, "d12299fe", "src/git.h");
check_blame_hunk_index(g_repo, g_blame, 35, 46, 1, 0, "111ee3fe", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 36, 47, 1, 0, "f004c4a8", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 37, 48, 1, 0, "111ee3fe", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 38, 49, 1, 0, "9c82357b", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 39, 50, 1, 0, "d6258deb", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 40, 51, 1, 0, "b311e313", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 41, 52, 1, 0, "3412391d", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 42, 53, 1, 0, "bfc9ca59", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 43, 54, 1, 0, "bf477ed4", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 44, 55, 1, 0, "edebceff", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 45, 56, 1, 0, "743a4b3b", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 46, 57, 1, 0, "0a32dca5", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 47, 58, 1, 0, "590fb68b", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 48, 59, 1, 0, "bf477ed4", "include/git2.h");
check_blame_hunk_index(g_repo, g_blame, 49, 60, 1, 0, "d12299fe", "src/git.h");
}
/* This was leading to segfaults on some systems during cache eviction. */
void test_blame_simple__trivial_libgit2_under_cache_pressure(void)
{
ssize_t old_max_storage = git_cache__max_storage;
git_cache__max_storage = 1024 * 1024;
test_blame_simple__trivial_libgit2();
git_cache__max_storage = old_max_storage;
}
/*
* $ git blame -n b.txt -L 8
* orig line no final line no
* commit V author timestamp V
* 63d671eb 8 (Ben Straub 2013-02-12 15:13:04 -0800 8
* 63d671eb 9 (Ben Straub 2013-02-12 15:13:04 -0800 9
* 63d671eb 10 (Ben Straub 2013-02-12 15:13:04 -0800 10
* aa06ecca 6 (Ben Straub 2013-02-12 15:14:46 -0800 11
* aa06ecca 7 (Ben Straub 2013-02-12 15:14:46 -0800 12
* aa06ecca 8 (Ben Straub 2013-02-12 15:14:46 -0800 13
* aa06ecca 9 (Ben Straub 2013-02-12 15:14:46 -0800 14
* aa06ecca 10 (Ben Straub 2013-02-12 15:14:46 -0800 15
*/
void test_blame_simple__can_restrict_lines_min(void)
{
git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git")));
opts.min_line = 8;
cl_git_pass(git_blame_file(&g_blame, g_repo, "b.txt", &opts));
cl_assert_equal_i(2, git_blame_get_hunk_count(g_blame));
check_blame_hunk_index(g_repo, g_blame, 0, 8, 3, 0, "63d671eb", "b.txt");
check_blame_hunk_index(g_repo, g_blame, 1, 11, 5, 0, "aa06ecca", "b.txt");
}
/*
* $ git blame -n c.txt
* orig line no final line no
* commit V author timestamp V
* 702c7aa5 1 (Carl Schwan 2020-01-29 01:52:31 +0100 4
*/
void test_blame_simple__can_ignore_whitespace_change(void)
{
git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git")));
opts.flags |= GIT_BLAME_IGNORE_WHITESPACE;
cl_git_pass(git_blame_file(&g_blame, g_repo, "c.txt", &opts));
cl_assert_equal_i(1, git_blame_get_hunk_count(g_blame));
check_blame_hunk_index(g_repo, g_blame, 0, 1, 4, 0, "702c7aa5", "c.txt");
}
/*
* $ git blame -n b.txt -L ,6
* orig line no final line no
* commit V author timestamp V
* da237394 1 (Ben Straub 2013-02-12 15:11:30 -0800 1
* da237394 2 (Ben Straub 2013-02-12 15:11:30 -0800 2
* da237394 3 (Ben Straub 2013-02-12 15:11:30 -0800 3
* da237394 4 (Ben Straub 2013-02-12 15:11:30 -0800 4
* ^b99f7ac 1 (Ben Straub 2013-02-12 15:10:12 -0800 5
* 63d671eb 6 (Ben Straub 2013-02-12 15:13:04 -0800 6
*/
void test_blame_simple__can_restrict_lines_max(void)
{
git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git")));
opts.max_line = 6;
cl_git_pass(git_blame_file(&g_blame, g_repo, "b.txt", &opts));
cl_assert_equal_i(3, git_blame_get_hunk_count(g_blame));
check_blame_hunk_index(g_repo, g_blame, 0, 1, 4, 0, "da237394", "b.txt");
check_blame_hunk_index(g_repo, g_blame, 1, 5, 1, 1, "b99f7ac0", "b.txt");
check_blame_hunk_index(g_repo, g_blame, 2, 6, 1, 0, "63d671eb", "b.txt");
}
/*
* $ git blame -n b.txt -L 2,7
* orig line no final line no
* commit V author timestamp V
* da237394 2 (Ben Straub 2013-02-12 15:11:30 -0800 2
* da237394 3 (Ben Straub 2013-02-12 15:11:30 -0800 3
* da237394 4 (Ben Straub 2013-02-12 15:11:30 -0800 4
* ^b99f7ac 1 (Ben Straub 2013-02-12 15:10:12 -0800 5
* 63d671eb 6 (Ben Straub 2013-02-12 15:13:04 -0800 6
* 63d671eb 7 (Ben Straub 2013-02-12 15:13:04 -0800 7
*/
void test_blame_simple__can_restrict_lines_both(void)
{
git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git")));
opts.min_line = 2;
opts.max_line = 7;
cl_git_pass(git_blame_file(&g_blame, g_repo, "b.txt", &opts));
cl_assert_equal_i(3, git_blame_get_hunk_count(g_blame));
check_blame_hunk_index(g_repo, g_blame, 0, 2, 3, 0, "da237394", "b.txt");
check_blame_hunk_index(g_repo, g_blame, 1, 5, 1, 1, "b99f7ac0", "b.txt");
check_blame_hunk_index(g_repo, g_blame, 2, 6, 2, 0, "63d671eb", "b.txt");
}
void test_blame_simple__can_blame_huge_file(void)
{
git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git")));
cl_git_pass(git_blame_file(&g_blame, g_repo, "huge.txt", &opts));
cl_assert_equal_i(2, git_blame_get_hunk_count(g_blame));
check_blame_hunk_index(g_repo, g_blame, 0, 1, 65536, 0, "4eecfea", "huge.txt");
check_blame_hunk_index(g_repo, g_blame, 1, 65537, 1, 0, "6653ff4", "huge.txt");
}
/*
* $ git blame -n branch_file.txt be3563a..HEAD
* orig line no final line no
* commit V author timestamp V
* ^be3563a 1 (Scott Chacon 2010-05-25 11:58:27 -0700 1) hi
* a65fedf3 2 (Scott Chacon 2011-08-09 19:33:46 -0700 2) bye!
*/
void test_blame_simple__can_restrict_to_newish_commits(void)
{
git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git")));
{
git_object *obj;
cl_git_pass(git_revparse_single(&obj, g_repo, "be3563a"));
git_oid_cpy(&opts.oldest_commit, git_object_id(obj));
git_object_free(obj);
}
cl_git_pass(git_blame_file(&g_blame, g_repo, "branch_file.txt", &opts));
cl_assert_equal_i(2, git_blame_get_hunk_count(g_blame));
check_blame_hunk_index(g_repo, g_blame, 0, 1, 1, 1, "be3563a", "branch_file.txt");
check_blame_hunk_index(g_repo, g_blame, 1, 2, 1, 0, "a65fedf", "branch_file.txt");
}
void test_blame_simple__can_restrict_to_first_parent_commits(void)
{
git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
opts.flags |= GIT_BLAME_FIRST_PARENT;
cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git")));
cl_git_pass(git_blame_file(&g_blame, g_repo, "b.txt", &opts));
cl_assert_equal_i(4, git_blame_get_hunk_count(g_blame));
check_blame_hunk_index(g_repo, g_blame, 0, 1, 4, 0, "da237394", "b.txt");
check_blame_hunk_index(g_repo, g_blame, 1, 5, 1, 1, "b99f7ac0", "b.txt");
check_blame_hunk_index(g_repo, g_blame, 2, 6, 5, 0, "63d671eb", "b.txt");
check_blame_hunk_index(g_repo, g_blame, 3, 11, 5, 0, "bc7c5ac2", "b.txt");
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/blame/buffer.c
|
#include "blame_helpers.h"
static git_repository *g_repo;
static git_blame *g_fileblame, *g_bufferblame;
void test_blame_buffer__initialize(void)
{
cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git")));
cl_git_pass(git_blame_file(&g_fileblame, g_repo, "b.txt", NULL));
g_bufferblame = NULL;
}
void test_blame_buffer__cleanup(void)
{
git_blame_free(g_fileblame);
git_blame_free(g_bufferblame);
git_repository_free(g_repo);
}
void test_blame_buffer__index(void)
{
const git_blame_hunk *hunk;
const char *buffer = "Hello\nWorld!";
/*
* We need to open a different file from the ones used in other tests. Close
* the one opened in test_blame_buffer__initialize() to avoid a leak.
*/
git_blame_free(g_fileblame);
g_fileblame = NULL;
cl_git_pass(git_blame_file(&g_fileblame, g_repo, "file.txt", NULL));
cl_git_pass(git_blame_buffer(&g_bufferblame, g_fileblame, buffer, strlen(buffer)));
cl_assert_equal_i(2, git_blame_get_hunk_count(g_bufferblame));
check_blame_hunk_index(g_repo, g_bufferblame, 0, 1, 1, 0, "836bc00b", "file.txt");
hunk = git_blame_get_hunk_byline(g_bufferblame, 1);
cl_assert(hunk);
cl_assert_equal_s("lhchavez", hunk->final_signature->name);
check_blame_hunk_index(g_repo, g_bufferblame, 1, 2, 1, 0, "00000000", "file.txt");
hunk = git_blame_get_hunk_byline(g_bufferblame, 2);
cl_assert(hunk);
cl_assert(hunk->final_signature == NULL);
}
void test_blame_buffer__added_line(void)
{
const git_blame_hunk *hunk;
const char *buffer = "\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
\n\
abcdefg\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\n";
cl_git_pass(git_blame_buffer(&g_bufferblame, g_fileblame, buffer, strlen(buffer)));
cl_assert_equal_i(5, git_blame_get_hunk_count(g_bufferblame));
check_blame_hunk_index(g_repo, g_bufferblame, 2, 6, 1, 0, "000000", "b.txt");
hunk = git_blame_get_hunk_byline(g_bufferblame, 16);
cl_assert(hunk);
cl_assert_equal_s("Ben Straub", hunk->final_signature->name);
}
void test_blame_buffer__deleted_line(void)
{
const char *buffer = "\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\n";
cl_git_pass(git_blame_buffer(&g_bufferblame, g_fileblame, buffer, strlen(buffer)));
check_blame_hunk_index(g_repo, g_bufferblame, 2, 6, 3, 0, "63d671eb", "b.txt");
check_blame_hunk_index(g_repo, g_bufferblame, 3, 9, 1, 0, "63d671eb", "b.txt");
check_blame_hunk_index(g_repo, g_bufferblame, 4, 10, 5, 0, "aa06ecca", "b.txt");
}
void test_blame_buffer__add_splits_hunk(void)
{
const char *buffer = "\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
abc\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\n";
cl_git_pass(git_blame_buffer(&g_bufferblame, g_fileblame, buffer, strlen(buffer)));
check_blame_hunk_index(g_repo, g_bufferblame, 2, 6, 2, 0, "63d671eb", "b.txt");
check_blame_hunk_index(g_repo, g_bufferblame, 3, 8, 1, 0, "00000000", "b.txt");
check_blame_hunk_index(g_repo, g_bufferblame, 4, 9, 3, 0, "63d671eb", "b.txt");
}
void test_blame_buffer__delete_crosses_hunk_boundary(void)
{
const char *buffer = "\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\n";
cl_git_pass(git_blame_buffer(&g_bufferblame, g_fileblame, buffer, strlen(buffer)));
check_blame_hunk_index(g_repo, g_bufferblame, 2, 6, 1, 0, "63d671eb", "b.txt");
check_blame_hunk_index(g_repo, g_bufferblame, 3, 7, 2, 0, "aa06ecca", "b.txt");
}
void test_blame_buffer__replace_line(void)
{
const char *buffer = "\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
abc\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\n";
cl_git_pass(git_blame_buffer(&g_bufferblame, g_fileblame, buffer, strlen(buffer)));
check_blame_hunk_index(g_repo, g_bufferblame, 2, 6, 1, 0, "63d671eb", "b.txt");
check_blame_hunk_index(g_repo, g_bufferblame, 3, 7, 1, 0, "00000000", "b.txt");
check_blame_hunk_index(g_repo, g_bufferblame, 4, 8, 3, 0, "63d671eb", "b.txt");
}
void test_blame_buffer__add_lines_at_end(void)
{
const char *buffer = "\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
\n\
abc\n\
def\n";
cl_git_pass(git_blame_buffer(&g_bufferblame, g_fileblame, buffer, strlen(buffer)));
cl_assert_equal_i(5, git_blame_get_hunk_count(g_bufferblame));
check_blame_hunk_index(g_repo, g_bufferblame, 0, 1, 4, 0, "da237394", "b.txt");
check_blame_hunk_index(g_repo, g_bufferblame, 1, 5, 1, 1, "b99f7ac0", "b.txt");
check_blame_hunk_index(g_repo, g_bufferblame, 2, 6, 5, 0, "63d671eb", "b.txt");
check_blame_hunk_index(g_repo, g_bufferblame, 3, 11, 5, 0, "aa06ecca", "b.txt");
check_blame_hunk_index(g_repo, g_bufferblame, 4, 16, 2, 0, "00000000", "b.txt");
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/blame/blame_helpers.h
|
#include "clar_libgit2.h"
#include "blame.h"
void hunk_message(size_t idx, const git_blame_hunk *hunk, const char *fmt, ...) GIT_FORMAT_PRINTF(3, 4);
void check_blame_hunk_index(
git_repository *repo,
git_blame *blame,
int idx,
size_t start_line,
size_t len,
char boundary,
const char *commit_id,
const char *orig_path);
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/blame/harder.c
|
#include "clar_libgit2.h"
#include "blame.h"
/**
* The test repo has a history that looks like this:
*
* * (A) bc7c5ac
* |\
* | * (B) aa06ecc
* * | (C) 63d671e
* |/
* * (D) da23739
* * (E) b99f7ac
*
*/
static git_repository *g_repo = NULL;
void test_blame_harder__initialize(void)
{
cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git")));
}
void test_blame_harder__cleanup(void)
{
git_repository_free(g_repo);
g_repo = NULL;
}
void test_blame_harder__m(void)
{
/* TODO */
git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
GIT_UNUSED(opts);
opts.flags = GIT_BLAME_TRACK_COPIES_SAME_FILE;
}
void test_blame_harder__c(void)
{
git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
GIT_UNUSED(opts);
/* Attribute the first hunk in b.txt to (E), since it was cut/pasted from
* a.txt in (D).
*/
opts.flags = GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES;
}
void test_blame_harder__cc(void)
{
git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
GIT_UNUSED(opts);
/* Attribute the second hunk in b.txt to (E), since it was copy/pasted from
* a.txt in (C).
*/
opts.flags = GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES;
}
void test_blame_harder__ccc(void)
{
git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
GIT_UNUSED(opts);
/* Attribute the third hunk in b.txt to (E). This hunk was deleted from
* a.txt in (D), but reintroduced in (B).
*/
opts.flags = GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES;
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/blame/getters.c
|
#include "clar_libgit2.h"
#include "blame.h"
git_blame *g_blame;
void test_blame_getters__initialize(void)
{
size_t i;
git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
git_blame_hunk hunks[] = {
{ 3, {{0}}, 1, NULL, {{0}}, "a", 0},
{ 3, {{0}}, 4, NULL, {{0}}, "b", 0},
{ 3, {{0}}, 7, NULL, {{0}}, "c", 0},
{ 3, {{0}}, 10, NULL, {{0}}, "d", 0},
{ 3, {{0}}, 13, NULL, {{0}}, "e", 0},
};
g_blame = git_blame__alloc(NULL, opts, "");
for (i=0; i<5; i++) {
git_blame_hunk *h = git__calloc(1, sizeof(git_blame_hunk));
h->final_start_line_number = hunks[i].final_start_line_number;
h->orig_path = git__strdup(hunks[i].orig_path);
h->lines_in_hunk = hunks[i].lines_in_hunk;
git_vector_insert(&g_blame->hunks, h);
}
}
void test_blame_getters__cleanup(void)
{
git_blame_free(g_blame);
}
void test_blame_getters__byindex(void)
{
const git_blame_hunk *h = git_blame_get_hunk_byindex(g_blame, 2);
cl_assert(h);
cl_assert_equal_s(h->orig_path, "c");
h = git_blame_get_hunk_byindex(g_blame, 95);
cl_assert_equal_p(h, NULL);
}
void test_blame_getters__byline(void)
{
const git_blame_hunk *h = git_blame_get_hunk_byline(g_blame, 5);
cl_assert(h);
cl_assert_equal_s(h->orig_path, "b");
h = git_blame_get_hunk_byline(g_blame, 95);
cl_assert_equal_p(h, NULL);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/blame/blame_helpers.c
|
#include "blame_helpers.h"
void hunk_message(size_t idx, const git_blame_hunk *hunk, const char *fmt, ...)
{
va_list arglist;
printf("Hunk %"PRIuZ" (line %"PRIuZ" +%"PRIuZ"): ", idx,
hunk->final_start_line_number, hunk->lines_in_hunk-1);
va_start(arglist, fmt);
vprintf(fmt, arglist);
va_end(arglist);
printf("\n");
}
void check_blame_hunk_index(git_repository *repo, git_blame *blame, int idx,
size_t start_line, size_t len, char boundary, const char *commit_id, const char *orig_path)
{
char expected[GIT_OID_HEXSZ+1] = {0}, actual[GIT_OID_HEXSZ+1] = {0};
const git_blame_hunk *hunk = git_blame_get_hunk_byindex(blame, idx);
cl_assert(hunk);
if (!strncmp(commit_id, "0000", 4)) {
strcpy(expected, "0000000000000000000000000000000000000000");
} else {
git_object *obj;
cl_git_pass(git_revparse_single(&obj, repo, commit_id));
git_oid_fmt(expected, git_object_id(obj));
git_object_free(obj);
}
if (hunk->final_start_line_number != start_line) {
hunk_message(idx, hunk, "mismatched start line number: expected %"PRIuZ", got %"PRIuZ,
start_line, hunk->final_start_line_number);
}
cl_assert_equal_i(hunk->final_start_line_number, start_line);
if (hunk->lines_in_hunk != len) {
hunk_message(idx, hunk, "mismatched line count: expected %"PRIuZ", got %"PRIuZ,
len, hunk->lines_in_hunk);
}
cl_assert_equal_i(hunk->lines_in_hunk, len);
git_oid_fmt(actual, &hunk->final_commit_id);
if (strcmp(expected, actual)) {
hunk_message(idx, hunk, "has mismatched original id (got %s, expected %s)\n",
actual, expected);
}
cl_assert_equal_s(actual, expected);
cl_assert_equal_oid(&hunk->final_commit_id, &hunk->orig_commit_id);
if (strcmp(hunk->orig_path, orig_path)) {
hunk_message(idx, hunk, "has mismatched original path (got '%s', expected '%s')\n",
hunk->orig_path, orig_path);
}
cl_assert_equal_s(hunk->orig_path, orig_path);
if (hunk->boundary != boundary) {
hunk_message(idx, hunk, "doesn't match boundary flag (got %d, expected %d)\n",
hunk->boundary, boundary);
}
cl_assert_equal_i(boundary, hunk->boundary);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/win32/forbidden.c
|
#include "clar_libgit2.h"
#include "repository.h"
#include "buffer.h"
#include "submodule.h"
static const char *repo_name = "win32-forbidden";
static git_repository *repo;
void test_win32_forbidden__initialize(void)
{
repo = cl_git_sandbox_init(repo_name);
}
void test_win32_forbidden__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_win32_forbidden__can_open_index(void)
{
git_index *index;
cl_git_pass(git_repository_index(&index, repo));
cl_assert_equal_i(7, git_index_entrycount(index));
/* ensure we can even write the unmodified index */
cl_git_pass(git_index_write(index));
git_index_free(index);
}
void test_win32_forbidden__can_add_forbidden_filename_with_entry(void)
{
git_index *index;
git_index_entry entry = {{0}};
cl_git_pass(git_repository_index(&index, repo));
entry.path = "aux";
entry.mode = GIT_FILEMODE_BLOB;
git_oid_fromstr(&entry.id, "da623abd956bb2fd8052c708c7ed43f05d192d37");
cl_git_pass(git_index_add(index, &entry));
git_index_free(index);
}
void test_win32_forbidden__cannot_add_dot_git_even_with_entry(void)
{
git_index *index;
git_index_entry entry = {{0}};
cl_git_pass(git_repository_index(&index, repo));
entry.path = "foo/.git";
entry.mode = GIT_FILEMODE_BLOB;
git_oid_fromstr(&entry.id, "da623abd956bb2fd8052c708c7ed43f05d192d37");
cl_git_fail(git_index_add(index, &entry));
git_index_free(index);
}
void test_win32_forbidden__cannot_add_forbidden_filename_from_filesystem(void)
{
git_index *index;
/* since our function calls are very low-level, we can create `aux.`,
* but we should not be able to add it to the index
*/
cl_git_pass(git_repository_index(&index, repo));
cl_git_write2file("win32-forbidden/aux.", "foo\n", 4, O_RDWR | O_CREAT, 0666);
#ifdef GIT_WIN32
cl_git_fail(git_index_add_bypath(index, "aux."));
#else
cl_git_pass(git_index_add_bypath(index, "aux."));
#endif
cl_must_pass(p_unlink("win32-forbidden/aux."));
git_index_free(index);
}
static int dummy_submodule_cb(
git_submodule *sm, const char *name, void *payload)
{
GIT_UNUSED(sm);
GIT_UNUSED(name);
GIT_UNUSED(payload);
return 0;
}
void test_win32_forbidden__can_diff_tree_to_index(void)
{
git_diff *diff;
git_tree *tree;
cl_git_pass(git_repository_head_tree(&tree, repo));
cl_git_pass(git_diff_tree_to_index(&diff, repo, tree, NULL, NULL));
cl_assert_equal_i(0, git_diff_num_deltas(diff));
git_diff_free(diff);
git_tree_free(tree);
}
void test_win32_forbidden__can_diff_tree_to_tree(void)
{
git_diff *diff;
git_tree *tree;
cl_git_pass(git_repository_head_tree(&tree, repo));
cl_git_pass(git_diff_tree_to_tree(&diff, repo, tree, tree, NULL));
cl_assert_equal_i(0, git_diff_num_deltas(diff));
git_diff_free(diff);
git_tree_free(tree);
}
void test_win32_forbidden__can_diff_index_to_workdir(void)
{
git_index *index;
git_diff *diff;
const git_diff_delta *delta;
git_tree *tree;
size_t i;
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_repository_head_tree(&tree, repo));
cl_git_pass(git_diff_index_to_workdir(&diff, repo, index, NULL));
for (i = 0; i < git_diff_num_deltas(diff); i++) {
delta = git_diff_get_delta(diff, i);
cl_assert_equal_i(GIT_DELTA_DELETED, delta->status);
}
git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
}
void test_win32_forbidden__checking_out_forbidden_index_fails(void)
{
#ifdef GIT_WIN32
git_index *index;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
git_diff *diff;
const git_diff_delta *delta;
git_tree *tree;
size_t num_deltas, i;
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_git_pass(git_repository_index(&index, repo));
cl_git_fail(git_checkout_index(repo, index, &opts));
cl_git_pass(git_repository_head_tree(&tree, repo));
cl_git_pass(git_diff_index_to_workdir(&diff, repo, index, NULL));
num_deltas = git_diff_num_deltas(diff);
cl_assert(num_deltas > 0);
for (i = 0; i < num_deltas; i++) {
delta = git_diff_get_delta(diff, i);
cl_assert_equal_i(GIT_DELTA_DELETED, delta->status);
}
git_diff_free(diff);
git_tree_free(tree);
git_index_free(index);
#endif
}
void test_win32_forbidden__can_query_submodules(void)
{
cl_git_pass(git_submodule_foreach(repo, dummy_submodule_cb, NULL));
}
void test_win32_forbidden__can_blame_file(void)
{
git_blame *blame;
cl_git_pass(git_blame_file(&blame, repo, "aux", NULL));
git_blame_free(blame);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/win32/longpath.c
|
#include "clar_libgit2.h"
#include "git2/clone.h"
#include "clone.h"
#include "buffer.h"
#include "futils.h"
#include "repository.h"
static git_buf path = GIT_BUF_INIT;
#define LONG_FILENAME "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt"
void test_win32_longpath__initialize(void)
{
#ifdef GIT_WIN32
const char *base = clar_sandbox_path();
size_t base_len = strlen(base);
size_t remain = MAX_PATH - base_len;
size_t i;
git_buf_clear(&path);
git_buf_puts(&path, base);
git_buf_putc(&path, '/');
cl_assert(remain < (MAX_PATH - 5));
for (i = 0; i < (remain - 5); i++)
git_buf_putc(&path, 'a');
#endif
}
void test_win32_longpath__cleanup(void)
{
git_buf_dispose(&path);
cl_git_sandbox_cleanup();
}
void test_win32_longpath__errmsg_on_checkout(void)
{
#ifdef GIT_WIN32
git_repository *repo;
cl_git_fail(git_clone(&repo, cl_fixture("testrepo.git"), path.ptr, NULL));
cl_assert(git__prefixcmp(git_error_last()->message, "path too long") == 0);
#endif
}
void test_win32_longpath__workdir_path_validated(void)
{
#ifdef GIT_WIN32
git_repository *repo = cl_git_sandbox_init("testrepo");
git_buf out = GIT_BUF_INIT;
cl_git_pass(git_repository_workdir_path(&out, repo, "a.txt"));
/* even if the repo path is a drive letter, this is too long */
cl_git_fail(git_repository_workdir_path(&out, repo, LONG_FILENAME));
cl_assert(git__prefixcmp(git_error_last()->message, "path too long") == 0);
cl_repo_set_bool(repo, "core.longpaths", true);
cl_git_pass(git_repository_workdir_path(&out, repo, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt"));
cl_git_pass(git_repository_workdir_path(&out, repo, LONG_FILENAME));
git_buf_dispose(&out);
#endif
}
#ifdef GIT_WIN32
static void assert_longpath_status_and_add(git_repository *repo, const char *wddata, const char *repodata) {
git_index *index;
git_blob *blob;
git_buf out = GIT_BUF_INIT;
const git_index_entry *entry;
unsigned int status_flags;
cl_git_pass(git_repository_workdir_path(&out, repo, LONG_FILENAME));
cl_git_rewritefile(out.ptr, wddata);
cl_git_pass(git_status_file(&status_flags, repo, LONG_FILENAME));
cl_assert_equal_i(GIT_STATUS_WT_NEW, status_flags);
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_add_bypath(index, LONG_FILENAME));
cl_git_pass(git_status_file(&status_flags, repo, LONG_FILENAME));
cl_assert_equal_i(GIT_STATUS_INDEX_NEW, status_flags);
cl_assert((entry = git_index_get_bypath(index, LONG_FILENAME, 0)) != NULL);
cl_git_pass(git_blob_lookup(&blob, repo, &entry->id));
cl_assert_equal_s(repodata, git_blob_rawcontent(blob));
git_blob_free(blob);
git_index_free(index);
git_buf_dispose(&out);
}
#endif
void test_win32_longpath__status_and_add(void)
{
#ifdef GIT_WIN32
git_repository *repo = cl_git_sandbox_init("testrepo");
cl_repo_set_bool(repo, "core.longpaths", true);
/*
* Doing no content filtering, we expect the data we add
* to be the data in the repository.
*/
assert_longpath_status_and_add(repo,
"This is a long path.\r\n",
"This is a long path.\r\n");
#endif
}
void test_win32_longpath__status_and_add_with_filter(void)
{
#ifdef GIT_WIN32
git_repository *repo = cl_git_sandbox_init("testrepo");
cl_repo_set_bool(repo, "core.longpaths", true);
cl_repo_set_bool(repo, "core.autocrlf", true);
/*
* With `core.autocrlf`, we expect the data we add to have
* newline conversion performed.
*/
assert_longpath_status_and_add(repo,
"This is a long path.\r\n",
"This is a long path.\n");
#endif
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/include/git2.h
|
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_git_git_h__
#define INCLUDE_git_git_h__
#include "git2/annotated_commit.h"
#include "git2/apply.h"
#include "git2/attr.h"
#include "git2/blob.h"
#include "git2/blame.h"
#include "git2/branch.h"
#include "git2/buffer.h"
#include "git2/cert.h"
#include "git2/checkout.h"
#include "git2/cherrypick.h"
#include "git2/clone.h"
#include "git2/commit.h"
#include "git2/common.h"
#include "git2/config.h"
#include "git2/credential.h"
#include "git2/deprecated.h"
#include "git2/describe.h"
#include "git2/diff.h"
#include "git2/email.h"
#include "git2/errors.h"
#include "git2/filter.h"
#include "git2/global.h"
#include "git2/graph.h"
#include "git2/ignore.h"
#include "git2/index.h"
#include "git2/indexer.h"
#include "git2/mailmap.h"
#include "git2/merge.h"
#include "git2/message.h"
#include "git2/net.h"
#include "git2/notes.h"
#include "git2/object.h"
#include "git2/odb.h"
#include "git2/odb_backend.h"
#include "git2/oid.h"
#include "git2/pack.h"
#include "git2/patch.h"
#include "git2/pathspec.h"
#include "git2/proxy.h"
#include "git2/rebase.h"
#include "git2/refdb.h"
#include "git2/reflog.h"
#include "git2/refs.h"
#include "git2/refspec.h"
#include "git2/remote.h"
#include "git2/repository.h"
#include "git2/reset.h"
#include "git2/revert.h"
#include "git2/revparse.h"
#include "git2/revwalk.h"
#include "git2/signature.h"
#include "git2/stash.h"
#include "git2/status.h"
#include "git2/submodule.h"
#include "git2/tag.h"
#include "git2/transport.h"
#include "git2/transaction.h"
#include "git2/tree.h"
#include "git2/types.h"
#include "git2/version.h"
#include "git2/worktree.h"
#endif
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/include
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/include/git2/checkout.h
|
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_git_checkout_h__
#define INCLUDE_git_checkout_h__
#include "common.h"
#include "types.h"
#include "diff.h"
/**
* @file git2/checkout.h
* @brief Git checkout routines
* @defgroup git_checkout Git checkout routines
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* Checkout behavior flags
*
* In libgit2, checkout is used to update the working directory and index
* to match a target tree. Unlike git checkout, it does not move the HEAD
* commit for you - use `git_repository_set_head` or the like to do that.
*
* Checkout looks at (up to) four things: the "target" tree you want to
* check out, the "baseline" tree of what was checked out previously, the
* working directory for actual files, and the index for staged changes.
*
* You give checkout one of three strategies for update:
*
* - `GIT_CHECKOUT_NONE` is a dry-run strategy that checks for conflicts,
* etc., but doesn't make any actual changes.
*
* - `GIT_CHECKOUT_FORCE` is at the opposite extreme, taking any action to
* make the working directory match the target (including potentially
* discarding modified files).
*
* - `GIT_CHECKOUT_SAFE` is between these two options, it will only make
* modifications that will not lose changes.
*
* | target == baseline | target != baseline |
* ---------------------|-----------------------|----------------------|
* workdir == baseline | no action | create, update, or |
* | | delete file |
* ---------------------|-----------------------|----------------------|
* workdir exists and | no action | conflict (notify |
* is != baseline | notify dirty MODIFIED | and cancel checkout) |
* ---------------------|-----------------------|----------------------|
* workdir missing, | notify dirty DELETED | create file |
* baseline present | | |
* ---------------------|-----------------------|----------------------|
*
* To emulate `git checkout`, use `GIT_CHECKOUT_SAFE` with a checkout
* notification callback (see below) that displays information about dirty
* files. The default behavior will cancel checkout on conflicts.
*
* To emulate `git checkout-index`, use `GIT_CHECKOUT_SAFE` with a
* notification callback that cancels the operation if a dirty-but-existing
* file is found in the working directory. This core git command isn't
* quite "force" but is sensitive about some types of changes.
*
* To emulate `git checkout -f`, use `GIT_CHECKOUT_FORCE`.
*
*
* There are some additional flags to modify the behavior of checkout:
*
* - GIT_CHECKOUT_ALLOW_CONFLICTS makes SAFE mode apply safe file updates
* even if there are conflicts (instead of cancelling the checkout).
*
* - GIT_CHECKOUT_REMOVE_UNTRACKED means remove untracked files (i.e. not
* in target, baseline, or index, and not ignored) from the working dir.
*
* - GIT_CHECKOUT_REMOVE_IGNORED means remove ignored files (that are also
* untracked) from the working directory as well.
*
* - GIT_CHECKOUT_UPDATE_ONLY means to only update the content of files that
* already exist. Files will not be created nor deleted. This just skips
* applying adds, deletes, and typechanges.
*
* - GIT_CHECKOUT_DONT_UPDATE_INDEX prevents checkout from writing the
* updated files' information to the index.
*
* - Normally, checkout will reload the index and git attributes from disk
* before any operations. GIT_CHECKOUT_NO_REFRESH prevents this reload.
*
* - Unmerged index entries are conflicts. GIT_CHECKOUT_SKIP_UNMERGED skips
* files with unmerged index entries instead. GIT_CHECKOUT_USE_OURS and
* GIT_CHECKOUT_USE_THEIRS to proceed with the checkout using either the
* stage 2 ("ours") or stage 3 ("theirs") version of files in the index.
*
* - GIT_CHECKOUT_DONT_OVERWRITE_IGNORED prevents ignored files from being
* overwritten. Normally, files that are ignored in the working directory
* are not considered "precious" and may be overwritten if the checkout
* target contains that file.
*
* - GIT_CHECKOUT_DONT_REMOVE_EXISTING prevents checkout from removing
* files or folders that fold to the same name on case insensitive
* filesystems. This can cause files to retain their existing names
* and write through existing symbolic links.
*/
typedef enum {
GIT_CHECKOUT_NONE = 0, /**< default is a dry run, no actual updates */
/**
* Allow safe updates that cannot overwrite uncommitted data.
* If the uncommitted changes don't conflict with the checked out files,
* the checkout will still proceed, leaving the changes intact.
*
* Mutually exclusive with GIT_CHECKOUT_FORCE.
* GIT_CHECKOUT_FORCE takes precedence over GIT_CHECKOUT_SAFE.
*/
GIT_CHECKOUT_SAFE = (1u << 0),
/**
* Allow all updates to force working directory to look like index.
*
* Mutually exclusive with GIT_CHECKOUT_SAFE.
* GIT_CHECKOUT_FORCE takes precedence over GIT_CHECKOUT_SAFE.
*/
GIT_CHECKOUT_FORCE = (1u << 1),
/** Allow checkout to recreate missing files */
GIT_CHECKOUT_RECREATE_MISSING = (1u << 2),
/** Allow checkout to make safe updates even if conflicts are found */
GIT_CHECKOUT_ALLOW_CONFLICTS = (1u << 4),
/** Remove untracked files not in index (that are not ignored) */
GIT_CHECKOUT_REMOVE_UNTRACKED = (1u << 5),
/** Remove ignored files not in index */
GIT_CHECKOUT_REMOVE_IGNORED = (1u << 6),
/** Only update existing files, don't create new ones */
GIT_CHECKOUT_UPDATE_ONLY = (1u << 7),
/**
* Normally checkout updates index entries as it goes; this stops that.
* Implies `GIT_CHECKOUT_DONT_WRITE_INDEX`.
*/
GIT_CHECKOUT_DONT_UPDATE_INDEX = (1u << 8),
/** Don't refresh index/config/etc before doing checkout */
GIT_CHECKOUT_NO_REFRESH = (1u << 9),
/** Allow checkout to skip unmerged files */
GIT_CHECKOUT_SKIP_UNMERGED = (1u << 10),
/** For unmerged files, checkout stage 2 from index */
GIT_CHECKOUT_USE_OURS = (1u << 11),
/** For unmerged files, checkout stage 3 from index */
GIT_CHECKOUT_USE_THEIRS = (1u << 12),
/** Treat pathspec as simple list of exact match file paths */
GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH = (1u << 13),
/** Ignore directories in use, they will be left empty */
GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES = (1u << 18),
/** Don't overwrite ignored files that exist in the checkout target */
GIT_CHECKOUT_DONT_OVERWRITE_IGNORED = (1u << 19),
/** Write normal merge files for conflicts */
GIT_CHECKOUT_CONFLICT_STYLE_MERGE = (1u << 20),
/** Include common ancestor data in diff3 format files for conflicts */
GIT_CHECKOUT_CONFLICT_STYLE_DIFF3 = (1u << 21),
/** Don't overwrite existing files or folders */
GIT_CHECKOUT_DONT_REMOVE_EXISTING = (1u << 22),
/** Normally checkout writes the index upon completion; this prevents that. */
GIT_CHECKOUT_DONT_WRITE_INDEX = (1u << 23),
/**
* Show what would be done by a checkout. Stop after sending
* notifications; don't update the working directory or index.
*/
GIT_CHECKOUT_DRY_RUN = (1u << 24),
/**
* THE FOLLOWING OPTIONS ARE NOT YET IMPLEMENTED
*/
/** Recursively checkout submodules with same options (NOT IMPLEMENTED) */
GIT_CHECKOUT_UPDATE_SUBMODULES = (1u << 16),
/** Recursively checkout submodules if HEAD moved in super repo (NOT IMPLEMENTED) */
GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED = (1u << 17),
} git_checkout_strategy_t;
/**
* Checkout notification flags
*
* Checkout will invoke an options notification callback (`notify_cb`) for
* certain cases - you pick which ones via `notify_flags`:
*
* Returning a non-zero value from this callback will cancel the checkout.
* The non-zero return value will be propagated back and returned by the
* git_checkout_... call.
*
* Notification callbacks are made prior to modifying any files on disk,
* so canceling on any notification will still happen prior to any files
* being modified.
*/
typedef enum {
GIT_CHECKOUT_NOTIFY_NONE = 0,
/**
* Invokes checkout on conflicting paths.
*/
GIT_CHECKOUT_NOTIFY_CONFLICT = (1u << 0),
/**
* Notifies about "dirty" files, i.e. those that do not need an update
* but no longer match the baseline. Core git displays these files when
* checkout runs, but won't stop the checkout.
*/
GIT_CHECKOUT_NOTIFY_DIRTY = (1u << 1),
/**
* Sends notification for any file changed.
*/
GIT_CHECKOUT_NOTIFY_UPDATED = (1u << 2),
/**
* Notifies about untracked files.
*/
GIT_CHECKOUT_NOTIFY_UNTRACKED = (1u << 3),
/**
* Notifies about ignored files.
*/
GIT_CHECKOUT_NOTIFY_IGNORED = (1u << 4),
GIT_CHECKOUT_NOTIFY_ALL = 0x0FFFFu
} git_checkout_notify_t;
/** Checkout performance-reporting structure */
typedef struct {
size_t mkdir_calls;
size_t stat_calls;
size_t chmod_calls;
} git_checkout_perfdata;
/** Checkout notification callback function */
typedef int GIT_CALLBACK(git_checkout_notify_cb)(
git_checkout_notify_t why,
const char *path,
const git_diff_file *baseline,
const git_diff_file *target,
const git_diff_file *workdir,
void *payload);
/** Checkout progress notification function */
typedef void GIT_CALLBACK(git_checkout_progress_cb)(
const char *path,
size_t completed_steps,
size_t total_steps,
void *payload);
/** Checkout perfdata notification function */
typedef void GIT_CALLBACK(git_checkout_perfdata_cb)(
const git_checkout_perfdata *perfdata,
void *payload);
/**
* Checkout options structure
*
* Initialize with `GIT_CHECKOUT_OPTIONS_INIT`. Alternatively, you can
* use `git_checkout_options_init`.
*
*/
typedef struct git_checkout_options {
unsigned int version; /**< The version */
unsigned int checkout_strategy; /**< default will be a safe checkout */
int disable_filters; /**< don't apply filters like CRLF conversion */
unsigned int dir_mode; /**< default is 0755 */
unsigned int file_mode; /**< default is 0644 or 0755 as dictated by blob */
int file_open_flags; /**< default is O_CREAT | O_TRUNC | O_WRONLY */
unsigned int notify_flags; /**< see `git_checkout_notify_t` above */
/**
* Optional callback to get notifications on specific file states.
* @see git_checkout_notify_t
*/
git_checkout_notify_cb notify_cb;
/** Payload passed to notify_cb */
void *notify_payload;
/** Optional callback to notify the consumer of checkout progress. */
git_checkout_progress_cb progress_cb;
/** Payload passed to progress_cb */
void *progress_payload;
/**
* A list of wildmatch patterns or paths.
*
* By default, all paths are processed. If you pass an array of wildmatch
* patterns, those will be used to filter which paths should be taken into
* account.
*
* Use GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH to treat as a simple list.
*/
git_strarray paths;
/**
* The expected content of the working directory; defaults to HEAD.
*
* If the working directory does not match this baseline information,
* that will produce a checkout conflict.
*/
git_tree *baseline;
/**
* Like `baseline` above, though expressed as an index. This
* option overrides `baseline`.
*/
git_index *baseline_index;
const char *target_directory; /**< alternative checkout path to workdir */
const char *ancestor_label; /**< the name of the common ancestor side of conflicts */
const char *our_label; /**< the name of the "our" side of conflicts */
const char *their_label; /**< the name of the "their" side of conflicts */
/** Optional callback to notify the consumer of performance data. */
git_checkout_perfdata_cb perfdata_cb;
/** Payload passed to perfdata_cb */
void *perfdata_payload;
} git_checkout_options;
#define GIT_CHECKOUT_OPTIONS_VERSION 1
#define GIT_CHECKOUT_OPTIONS_INIT {GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE}
/**
* Initialize git_checkout_options structure
*
* Initializes a `git_checkout_options` with default values. Equivalent to creating
* an instance with GIT_CHECKOUT_OPTIONS_INIT.
*
* @param opts The `git_checkout_options` struct to initialize.
* @param version The struct version; pass `GIT_CHECKOUT_OPTIONS_VERSION`.
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_checkout_options_init(
git_checkout_options *opts,
unsigned int version);
/**
* Updates files in the index and the working tree to match the content of
* the commit pointed at by HEAD.
*
* Note that this is _not_ the correct mechanism used to switch branches;
* do not change your `HEAD` and then call this method, that would leave
* you with checkout conflicts since your working directory would then
* appear to be dirty. Instead, checkout the target of the branch and
* then update `HEAD` using `git_repository_set_head` to point to the
* branch you checked out.
*
* @param repo repository to check out (must be non-bare)
* @param opts specifies checkout options (may be NULL)
* @return 0 on success, GIT_EUNBORNBRANCH if HEAD points to a non
* existing branch, non-zero value returned by `notify_cb`, or
* other error code < 0 (use git_error_last for error details)
*/
GIT_EXTERN(int) git_checkout_head(
git_repository *repo,
const git_checkout_options *opts);
/**
* Updates files in the working tree to match the content of the index.
*
* @param repo repository into which to check out (must be non-bare)
* @param index index to be checked out (or NULL to use repository index)
* @param opts specifies checkout options (may be NULL)
* @return 0 on success, non-zero return value from `notify_cb`, or error
* code < 0 (use git_error_last for error details)
*/
GIT_EXTERN(int) git_checkout_index(
git_repository *repo,
git_index *index,
const git_checkout_options *opts);
/**
* Updates files in the index and working tree to match the content of the
* tree pointed at by the treeish.
*
* @param repo repository to check out (must be non-bare)
* @param treeish a commit, tag or tree which content will be used to update
* the working directory (or NULL to use HEAD)
* @param opts specifies checkout options (may be NULL)
* @return 0 on success, non-zero return value from `notify_cb`, or error
* code < 0 (use git_error_last for error details)
*/
GIT_EXTERN(int) git_checkout_tree(
git_repository *repo,
const git_object *treeish,
const git_checkout_options *opts);
/** @} */
GIT_END_DECL
#endif
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/include
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/include/git2/rebase.h
|
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_git_rebase_h__
#define INCLUDE_git_rebase_h__
#include "common.h"
#include "types.h"
#include "oid.h"
#include "annotated_commit.h"
#include "merge.h"
#include "checkout.h"
#include "commit.h"
/**
* @file git2/rebase.h
* @brief Git rebase routines
* @defgroup git_rebase Git merge routines
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* Rebase options
*
* Use to tell the rebase machinery how to operate.
*/
typedef struct {
unsigned int version;
/**
* Used by `git_rebase_init`, this will instruct other clients working
* on this rebase that you want a quiet rebase experience, which they
* may choose to provide in an application-specific manner. This has no
* effect upon libgit2 directly, but is provided for interoperability
* between Git tools.
*/
int quiet;
/**
* Used by `git_rebase_init`, this will begin an in-memory rebase,
* which will allow callers to step through the rebase operations and
* commit the rebased changes, but will not rewind HEAD or update the
* repository to be in a rebasing state. This will not interfere with
* the working directory (if there is one).
*/
int inmemory;
/**
* Used by `git_rebase_finish`, this is the name of the notes reference
* used to rewrite notes for rebased commits when finishing the rebase;
* if NULL, the contents of the configuration option `notes.rewriteRef`
* is examined, unless the configuration option `notes.rewrite.rebase`
* is set to false. If `notes.rewriteRef` is also NULL, notes will
* not be rewritten.
*/
const char *rewrite_notes_ref;
/**
* Options to control how trees are merged during `git_rebase_next`.
*/
git_merge_options merge_options;
/**
* Options to control how files are written during `git_rebase_init`,
* `git_rebase_next` and `git_rebase_abort`. Note that a minimum
* strategy of `GIT_CHECKOUT_SAFE` is defaulted in `init` and `next`,
* and a minimum strategy of `GIT_CHECKOUT_FORCE` is defaulted in
* `abort` to match git semantics.
*/
git_checkout_options checkout_options;
/**
* Optional callback that allows users to override commit
* creation in `git_rebase_commit`. If specified, users can
* create their own commit and provide the commit ID, which
* may be useful for signing commits or otherwise customizing
* the commit creation.
*
* If this callback returns `GIT_PASSTHROUGH`, then
* `git_rebase_commit` will continue to create the commit.
*/
git_commit_create_cb commit_create_cb;
#ifdef GIT_DEPRECATE_HARD
void *reserved;
#else
/**
* If provided, this will be called with the commit content, allowing
* a signature to be added to the rebase commit. Can be skipped with
* GIT_PASSTHROUGH. If GIT_PASSTHROUGH is returned, a commit will be made
* without a signature.
*
* This field is only used when performing git_rebase_commit.
*
* This callback is not invoked if a `git_commit_create_cb` is
* specified.
*
* This callback is deprecated; users should provide a
* creation callback as `commit_create_cb` that produces a
* commit buffer, signs it, and commits it.
*/
int (*signing_cb)(git_buf *, git_buf *, const char *, void *);
#endif
/**
* This will be passed to each of the callbacks in this struct
* as the last parameter.
*/
void *payload;
} git_rebase_options;
/**
* Type of rebase operation in-progress after calling `git_rebase_next`.
*/
typedef enum {
/**
* The given commit is to be cherry-picked. The client should commit
* the changes and continue if there are no conflicts.
*/
GIT_REBASE_OPERATION_PICK = 0,
/**
* The given commit is to be cherry-picked, but the client should prompt
* the user to provide an updated commit message.
*/
GIT_REBASE_OPERATION_REWORD,
/**
* The given commit is to be cherry-picked, but the client should stop
* to allow the user to edit the changes before committing them.
*/
GIT_REBASE_OPERATION_EDIT,
/**
* The given commit is to be squashed into the previous commit. The
* commit message will be merged with the previous message.
*/
GIT_REBASE_OPERATION_SQUASH,
/**
* The given commit is to be squashed into the previous commit. The
* commit message from this commit will be discarded.
*/
GIT_REBASE_OPERATION_FIXUP,
/**
* No commit will be cherry-picked. The client should run the given
* command and (if successful) continue.
*/
GIT_REBASE_OPERATION_EXEC,
} git_rebase_operation_t;
#define GIT_REBASE_OPTIONS_VERSION 1
#define GIT_REBASE_OPTIONS_INIT \
{ GIT_REBASE_OPTIONS_VERSION, 0, 0, NULL, GIT_MERGE_OPTIONS_INIT, \
GIT_CHECKOUT_OPTIONS_INIT, NULL, NULL }
/** Indicates that a rebase operation is not (yet) in progress. */
#define GIT_REBASE_NO_OPERATION SIZE_MAX
/**
* A rebase operation
*
* Describes a single instruction/operation to be performed during the
* rebase.
*/
typedef struct {
/** The type of rebase operation. */
git_rebase_operation_t type;
/**
* The commit ID being cherry-picked. This will be populated for
* all operations except those of type `GIT_REBASE_OPERATION_EXEC`.
*/
const git_oid id;
/**
* The executable the user has requested be run. This will only
* be populated for operations of type `GIT_REBASE_OPERATION_EXEC`.
*/
const char *exec;
} git_rebase_operation;
/**
* Initialize git_rebase_options structure
*
* Initializes a `git_rebase_options` with default values. Equivalent to
* creating an instance with `GIT_REBASE_OPTIONS_INIT`.
*
* @param opts The `git_rebase_options` struct to initialize.
* @param version The struct version; pass `GIT_REBASE_OPTIONS_VERSION`.
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_rebase_options_init(
git_rebase_options *opts,
unsigned int version);
/**
* Initializes a rebase operation to rebase the changes in `branch`
* relative to `upstream` onto another branch. To begin the rebase
* process, call `git_rebase_next`. When you have finished with this
* object, call `git_rebase_free`.
*
* @param out Pointer to store the rebase object
* @param repo The repository to perform the rebase
* @param branch The terminal commit to rebase, or NULL to rebase the
* current branch
* @param upstream The commit to begin rebasing from, or NULL to rebase all
* reachable commits
* @param onto The branch to rebase onto, or NULL to rebase onto the given
* upstream
* @param opts Options to specify how rebase is performed, or NULL
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_rebase_init(
git_rebase **out,
git_repository *repo,
const git_annotated_commit *branch,
const git_annotated_commit *upstream,
const git_annotated_commit *onto,
const git_rebase_options *opts);
/**
* Opens an existing rebase that was previously started by either an
* invocation of `git_rebase_init` or by another client.
*
* @param out Pointer to store the rebase object
* @param repo The repository that has a rebase in-progress
* @param opts Options to specify how rebase is performed
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_rebase_open(
git_rebase **out,
git_repository *repo,
const git_rebase_options *opts);
/**
* Gets the original `HEAD` ref name for merge rebases.
*
* @return The original `HEAD` ref name
*/
GIT_EXTERN(const char *) git_rebase_orig_head_name(git_rebase *rebase);
/**
* Gets the original `HEAD` id for merge rebases.
*
* @return The original `HEAD` id
*/
GIT_EXTERN(const git_oid *) git_rebase_orig_head_id(git_rebase *rebase);
/**
* Gets the `onto` ref name for merge rebases.
*
* @return The `onto` ref name
*/
GIT_EXTERN(const char *) git_rebase_onto_name(git_rebase *rebase);
/**
* Gets the `onto` id for merge rebases.
*
* @return The `onto` id
*/
GIT_EXTERN(const git_oid *) git_rebase_onto_id(git_rebase *rebase);
/**
* Gets the count of rebase operations that are to be applied.
*
* @param rebase The in-progress rebase
* @return The number of rebase operations in total
*/
GIT_EXTERN(size_t) git_rebase_operation_entrycount(git_rebase *rebase);
/**
* Gets the index of the rebase operation that is currently being applied.
* If the first operation has not yet been applied (because you have
* called `init` but not yet `next`) then this returns
* `GIT_REBASE_NO_OPERATION`.
*
* @param rebase The in-progress rebase
* @return The index of the rebase operation currently being applied.
*/
GIT_EXTERN(size_t) git_rebase_operation_current(git_rebase *rebase);
/**
* Gets the rebase operation specified by the given index.
*
* @param rebase The in-progress rebase
* @param idx The index of the rebase operation to retrieve
* @return The rebase operation or NULL if `idx` was out of bounds
*/
GIT_EXTERN(git_rebase_operation *) git_rebase_operation_byindex(
git_rebase *rebase,
size_t idx);
/**
* Performs the next rebase operation and returns the information about it.
* If the operation is one that applies a patch (which is any operation except
* GIT_REBASE_OPERATION_EXEC) then the patch will be applied and the index and
* working directory will be updated with the changes. If there are conflicts,
* you will need to address those before committing the changes.
*
* @param operation Pointer to store the rebase operation that is to be performed next
* @param rebase The rebase in progress
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_rebase_next(
git_rebase_operation **operation,
git_rebase *rebase);
/**
* Gets the index produced by the last operation, which is the result
* of `git_rebase_next` and which will be committed by the next
* invocation of `git_rebase_commit`. This is useful for resolving
* conflicts in an in-memory rebase before committing them. You must
* call `git_index_free` when you are finished with this.
*
* This is only applicable for in-memory rebases; for rebases within
* a working directory, the changes were applied to the repository's
* index.
*/
GIT_EXTERN(int) git_rebase_inmemory_index(
git_index **index,
git_rebase *rebase);
/**
* Commits the current patch. You must have resolved any conflicts that
* were introduced during the patch application from the `git_rebase_next`
* invocation.
*
* @param id Pointer in which to store the OID of the newly created commit
* @param rebase The rebase that is in-progress
* @param author The author of the updated commit, or NULL to keep the
* author from the original commit
* @param committer The committer of the rebase
* @param message_encoding The encoding for the message in the commit,
* represented with a standard encoding name. If message is NULL,
* this should also be NULL, and the encoding from the original
* commit will be maintained. If message is specified, this may be
* NULL to indicate that "UTF-8" is to be used.
* @param message The message for this commit, or NULL to use the message
* from the original commit.
* @return Zero on success, GIT_EUNMERGED if there are unmerged changes in
* the index, GIT_EAPPLIED if the current commit has already
* been applied to the upstream and there is nothing to commit,
* -1 on failure.
*/
GIT_EXTERN(int) git_rebase_commit(
git_oid *id,
git_rebase *rebase,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message);
/**
* Aborts a rebase that is currently in progress, resetting the repository
* and working directory to their state before rebase began.
*
* @param rebase The rebase that is in-progress
* @return Zero on success; GIT_ENOTFOUND if a rebase is not in progress,
* -1 on other errors.
*/
GIT_EXTERN(int) git_rebase_abort(git_rebase *rebase);
/**
* Finishes a rebase that is currently in progress once all patches have
* been applied.
*
* @param rebase The rebase that is in-progress
* @param signature The identity that is finishing the rebase (optional)
* @return Zero on success; -1 on error
*/
GIT_EXTERN(int) git_rebase_finish(
git_rebase *rebase,
const git_signature *signature);
/**
* Frees the `git_rebase` object.
*
* @param rebase The rebase object
*/
GIT_EXTERN(void) git_rebase_free(git_rebase *rebase);
/** @} */
GIT_END_DECL
#endif
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.