summaryrefslogtreecommitdiff
path: root/tests-clar
diff options
context:
space:
mode:
authorBen Straub <bs@github.com>2013-09-25 14:47:32 -0700
committerBen Straub <bs@github.com>2013-09-25 14:47:32 -0700
commit41dd999d12946ca2085ad315e9c5e8e57cc4e4f6 (patch)
tree0f9b3f7beefa40809a913e1e215b75dfe5a87115 /tests-clar
parentf7db1b6f26837b44a5cb8956c23bbbdff28ba4f7 (diff)
parentac316e743878908df762cc0ea07a71cbee5c5802 (diff)
downloadlibgit2-41dd999d12946ca2085ad315e9c5e8e57cc4e4f6.tar.gz
Merge branch 'development' into blame
Diffstat (limited to 'tests-clar')
-rw-r--r--tests-clar/attr/repo.c16
-rw-r--r--tests-clar/checkout/checkout_helpers.c58
-rw-r--r--tests-clar/checkout/checkout_helpers.h13
-rw-r--r--tests-clar/checkout/crlf.c104
-rw-r--r--tests-clar/checkout/head.c6
-rw-r--r--tests-clar/clar.h1
-rw-r--r--tests-clar/clar_libgit2.c143
-rw-r--r--tests-clar/clar_libgit2.h30
-rw-r--r--tests-clar/clone/empty.c4
-rw-r--r--tests-clar/clone/nonetwork.c2
-rw-r--r--tests-clar/config/global.c23
-rw-r--r--tests-clar/config/include.c109
-rw-r--r--tests-clar/config/read.c15
-rw-r--r--tests-clar/core/buffer.c47
-rw-r--r--tests-clar/core/filebuf.c10
-rw-r--r--tests-clar/diff/rename.c2
-rw-r--r--tests-clar/diff/submodules.c26
-rw-r--r--tests-clar/diff/workdir.c25
-rw-r--r--tests-clar/filter/blob.c84
-rw-r--r--tests-clar/filter/crlf.c71
-rw-r--r--tests-clar/filter/crlf.h25
-rw-r--r--tests-clar/filter/custom.c337
-rw-r--r--tests-clar/filter/ident.c131
-rw-r--r--tests-clar/index/addall.c35
-rw-r--r--tests-clar/index/filemodes.c11
-rw-r--r--tests-clar/object/blob/filter.c106
-rw-r--r--tests-clar/online/clone.c2
-rw-r--r--tests-clar/online/fetch.c5
-rw-r--r--tests-clar/refs/branches/delete.c4
-rw-r--r--tests-clar/refs/branches/ishead.c4
-rw-r--r--tests-clar/repo/head.c26
-rw-r--r--tests-clar/repo/headtree.c8
-rw-r--r--tests-clar/repo/init.c7
-rw-r--r--tests-clar/repo/repo_helpers.c2
-rw-r--r--tests-clar/repo/repo_helpers.h2
-rw-r--r--tests-clar/reset/soft.c8
-rw-r--r--tests-clar/resources/config/config-include2
-rw-r--r--tests-clar/resources/config/config-included2
-rw-r--r--tests-clar/revwalk/mergebase.c4
-rw-r--r--tests-clar/revwalk/simplify.c6
-rw-r--r--tests-clar/stash/drop.c16
-rw-r--r--tests-clar/stash/save.c7
-rw-r--r--tests-clar/stash/stash_helpers.c33
-rw-r--r--tests-clar/stash/stash_helpers.h5
-rw-r--r--tests-clar/status/renames.c4
-rw-r--r--tests-clar/status/submodules.c1
-rw-r--r--tests-clar/status/worktree.c25
-rw-r--r--tests-clar/stress/diff.c24
-rw-r--r--tests-clar/submodule/lookup.c10
-rw-r--r--tests-clar/submodule/status.c1
-rw-r--r--tests-clar/submodule/submodule_helpers.c21
-rw-r--r--tests-clar/submodule/submodule_helpers.h2
-rw-r--r--tests-clar/valgrind-supp-mac.txt28
53 files changed, 1324 insertions, 369 deletions
diff --git a/tests-clar/attr/repo.c b/tests-clar/attr/repo.c
index ca3e71e7f..ef2ad5ce9 100644
--- a/tests-clar/attr/repo.c
+++ b/tests-clar/attr/repo.c
@@ -100,6 +100,22 @@ void test_attr_repo__get_many(void)
cl_assert_equal_s("yes", values[3]);
}
+void test_attr_repo__get_many_in_place(void)
+{
+ const char *vals[4] = { "repoattr", "rootattr", "missingattr", "subattr" };
+
+ /* it should be legal to look up values into the same array that has
+ * the attribute names, overwriting each name as the value is found.
+ */
+
+ cl_git_pass(git_attr_get_many(vals, g_repo, 0, "sub/subdir_test1", 4, vals));
+
+ cl_assert(GIT_ATTR_TRUE(vals[0]));
+ cl_assert(GIT_ATTR_TRUE(vals[1]));
+ cl_assert(GIT_ATTR_UNSPECIFIED(vals[2]));
+ cl_assert_equal_s("yes", vals[3]);
+}
+
static int count_attrs(
const char *name,
const char *value,
diff --git a/tests-clar/checkout/checkout_helpers.c b/tests-clar/checkout/checkout_helpers.c
index f55f7b611..06b4e0682 100644
--- a/tests-clar/checkout/checkout_helpers.c
+++ b/tests-clar/checkout/checkout_helpers.c
@@ -3,22 +3,6 @@
#include "refs.h"
#include "fileops.h"
-/* this is essentially the code from git__unescape modified slightly */
-void strip_cr_from_buf(git_buf *buf)
-{
- char *scan, *pos = buf->ptr, *end = pos + buf->size;
-
- for (scan = pos; scan < end; pos++, scan++) {
- if (*scan == '\r')
- scan++; /* skip '\r' */
- if (pos != scan)
- *pos = *scan;
- }
-
- *pos = '\0';
- buf->size = (pos - buf->ptr);
-}
-
void assert_on_branch(git_repository *repo, const char *branch)
{
git_reference *head;
@@ -50,48 +34,6 @@ void reset_index_to_treeish(git_object *treeish)
git_index_free(index);
}
-static void check_file_contents_internal(
- const char *path,
- const char *expected_content,
- bool strip_cr,
- const char *file,
- int line,
- const char *msg)
-{
- int fd;
- char data[1024] = {0};
- git_buf buf = GIT_BUF_INIT;
- size_t expected_len = expected_content ? strlen(expected_content) : 0;
-
- fd = p_open(path, O_RDONLY);
- cl_assert(fd >= 0);
-
- buf.ptr = data;
- buf.size = p_read(fd, buf.ptr, sizeof(data));
-
- cl_git_pass(p_close(fd));
-
- if (strip_cr)
- strip_cr_from_buf(&buf);
-
- clar__assert_equal(file, line, "strlen(expected_content) != strlen(actual_content)", 1, PRIuZ, expected_len, (size_t)buf.size);
- clar__assert_equal(file, line, msg, 1, "%s", expected_content, buf.ptr);
-}
-
-void check_file_contents_at_line(
- const char *path, const char *expected,
- const char *file, int line, const char *msg)
-{
- check_file_contents_internal(path, expected, false, file, line, msg);
-}
-
-void check_file_contents_nocr_at_line(
- const char *path, const char *expected,
- const char *file, int line, const char *msg)
-{
- check_file_contents_internal(path, expected, true, file, line, msg);
-}
-
int checkout_count_callback(
git_checkout_notify_t why,
const char *path,
diff --git a/tests-clar/checkout/checkout_helpers.h b/tests-clar/checkout/checkout_helpers.h
index 0e8da31d1..705ee903d 100644
--- a/tests-clar/checkout/checkout_helpers.h
+++ b/tests-clar/checkout/checkout_helpers.h
@@ -2,23 +2,14 @@
#include "git2/object.h"
#include "git2/repository.h"
-extern void strip_cr_from_buf(git_buf *buf);
extern void assert_on_branch(git_repository *repo, const char *branch);
extern void reset_index_to_treeish(git_object *treeish);
-extern void check_file_contents_at_line(
- const char *path, const char *expected,
- const char *file, int line, const char *msg);
-
-extern void check_file_contents_nocr_at_line(
- const char *path, const char *expected,
- const char *file, int line, const char *msg);
-
#define check_file_contents(PATH,EXP) \
- check_file_contents_at_line(PATH,EXP,__FILE__,__LINE__,"String mismatch: " #EXP " != " #PATH)
+ cl_assert_equal_file(EXP,0,PATH)
#define check_file_contents_nocr(PATH,EXP) \
- check_file_contents_nocr_at_line(PATH,EXP,__FILE__,__LINE__,"String mismatch: " #EXP " != " #PATH)
+ cl_assert_equal_file_ignore_cr(EXP,0,PATH)
typedef struct {
int n_conflicts;
diff --git a/tests-clar/checkout/crlf.c b/tests-clar/checkout/crlf.c
index 285b1f272..9a4cbd313 100644
--- a/tests-clar/checkout/crlf.c
+++ b/tests-clar/checkout/crlf.c
@@ -1,18 +1,10 @@
#include "clar_libgit2.h"
#include "checkout_helpers.h"
+#include "../filter/crlf.h"
#include "git2/checkout.h"
#include "repository.h"
-
-#define UTF8_BOM "\xEF\xBB\xBF"
-#define ALL_CRLF_TEXT_RAW "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n"
-#define ALL_LF_TEXT_RAW "lf\nlf\nlf\nlf\nlf\n"
-#define MORE_CRLF_TEXT_RAW "crlf\r\ncrlf\r\nlf\ncrlf\r\ncrlf\r\n"
-#define MORE_LF_TEXT_RAW "lf\nlf\ncrlf\r\nlf\nlf\n"
-
-#define ALL_LF_TEXT_AS_CRLF "lf\r\nlf\r\nlf\r\nlf\r\nlf\r\n"
-#define MORE_CRLF_TEXT_AS_CRLF "crlf\r\ncrlf\r\nlf\r\ncrlf\r\ncrlf\r\n"
-#define MORE_LF_TEXT_AS_CRLF "lf\r\nlf\r\ncrlf\r\nlf\r\nlf\r\n"
+#include "posix.h"
static git_repository *g_repo;
@@ -145,3 +137,95 @@ void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
git_index_free(index);
}
+
+void test_checkout_crlf__with_ident(void)
+{
+ git_index *index;
+ git_blob *blob;
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
+
+ cl_git_mkfile("crlf/.gitattributes",
+ "*.txt text\n*.bin binary\n"
+ "*.crlf text eol=crlf\n"
+ "*.lf text eol=lf\n"
+ "*.ident text ident\n"
+ "*.identcrlf ident text eol=crlf\n"
+ "*.identlf ident text eol=lf\n");
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ /* add files with $Id$ */
+
+ cl_git_mkfile("crlf/lf.ident", ALL_LF_TEXT_RAW "\n$Id: initial content$\n");
+ cl_git_mkfile("crlf/crlf.ident", ALL_CRLF_TEXT_RAW "\r\n$Id$\r\n\r\n");
+ cl_git_mkfile("crlf/more1.identlf", "$Id$\n" MORE_LF_TEXT_RAW);
+ cl_git_mkfile("crlf/more2.identcrlf", "\r\n$Id: $\r\n" MORE_CRLF_TEXT_RAW);
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_git_pass(git_index_add_bypath(index, "lf.ident"));
+ cl_git_pass(git_index_add_bypath(index, "crlf.ident"));
+ cl_git_pass(git_index_add_bypath(index, "more1.identlf"));
+ cl_git_pass(git_index_add_bypath(index, "more2.identcrlf"));
+ cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "Some ident files\n");
+
+ git_checkout_head(g_repo, &opts);
+
+ /* check that blobs have $Id$ */
+
+ cl_git_pass(git_blob_lookup(&blob, g_repo,
+ & git_index_get_bypath(index, "lf.ident", 0)->oid));
+ cl_assert_equal_s(
+ ALL_LF_TEXT_RAW "\n$Id$\n", git_blob_rawcontent(blob));
+ git_blob_free(blob);
+
+ cl_git_pass(git_blob_lookup(&blob, g_repo,
+ & git_index_get_bypath(index, "more2.identcrlf", 0)->oid));
+ cl_assert_equal_s(
+ "\n$Id$\n" MORE_CRLF_TEXT_AS_LF, git_blob_rawcontent(blob));
+ git_blob_free(blob);
+
+ /* check that filesystem is initially untouched - matching core Git */
+
+ cl_assert_equal_file(
+ ALL_LF_TEXT_RAW "\n$Id: initial content$\n", 0, "crlf/lf.ident");
+
+ /* check that forced checkout rewrites correctly */
+
+ p_unlink("crlf/lf.ident");
+ p_unlink("crlf/crlf.ident");
+ p_unlink("crlf/more1.identlf");
+ p_unlink("crlf/more2.identcrlf");
+
+ git_checkout_head(g_repo, &opts);
+
+ if (GIT_EOL_NATIVE == GIT_EOL_LF) {
+ cl_assert_equal_file(
+ ALL_LF_TEXT_RAW
+ "\n$Id: fcf6d4d9c212dc66563b1171b1cd99953c756467$\n",
+ 0, "crlf/lf.ident");
+ cl_assert_equal_file(
+ ALL_CRLF_TEXT_AS_LF
+ "\n$Id: f2c66ad9b2b5a734d9bf00d5000cc10a62b8a857$\n\n",
+ 0, "crlf/crlf.ident");
+ } else {
+ cl_assert_equal_file(
+ ALL_LF_TEXT_AS_CRLF
+ "\r\n$Id: fcf6d4d9c212dc66563b1171b1cd99953c756467$\r\n",
+ 0, "crlf/lf.ident");
+ cl_assert_equal_file(
+ ALL_CRLF_TEXT_RAW
+ "\r\n$Id: f2c66ad9b2b5a734d9bf00d5000cc10a62b8a857$\r\n\r\n",
+ 0, "crlf/crlf.ident");
+ }
+
+ cl_assert_equal_file(
+ "$Id: f7830382dac1f1583422be5530fdfbd26289431b$\n"
+ MORE_LF_TEXT_AS_LF, 0, "crlf/more1.identlf");
+
+ cl_assert_equal_file(
+ "\r\n$Id: 74677a68413012ce8d7e7cfc3f12603df3a3eac4$\r\n"
+ MORE_CRLF_TEXT_AS_CRLF, 0, "crlf/more2.identcrlf");
+
+ git_index_free(index);
+}
diff --git a/tests-clar/checkout/head.c b/tests-clar/checkout/head.c
index 46646f8bf..74c6fb87a 100644
--- a/tests-clar/checkout/head.c
+++ b/tests-clar/checkout/head.c
@@ -16,11 +16,11 @@ void test_checkout_head__cleanup(void)
cl_git_sandbox_cleanup();
}
-void test_checkout_head__orphaned_head_returns_GIT_EORPHANEDHEAD(void)
+void test_checkout_head__unborn_head_returns_GIT_EUNBORNBRANCH(void)
{
- make_head_orphaned(g_repo, NON_EXISTING_HEAD);
+ make_head_unborn(g_repo, NON_EXISTING_HEAD);
- cl_assert_equal_i(GIT_EORPHANEDHEAD, git_checkout_head(g_repo, NULL));
+ cl_assert_equal_i(GIT_EUNBORNBRANCH, git_checkout_head(g_repo, NULL));
}
void test_checkout_head__with_index_only_tree(void)
diff --git a/tests-clar/clar.h b/tests-clar/clar.h
index c40bc7ac9..e1f244eba 100644
--- a/tests-clar/clar.h
+++ b/tests-clar/clar.h
@@ -68,7 +68,6 @@ void cl_fixture_cleanup(const char *fixture_name);
#define cl_assert_equal_p(p1,p2) clar__assert_equal(__FILE__,__LINE__,"Pointer mismatch: " #p1 " != " #p2, 1, "%p", (p1), (p2))
-#define cl_assert_equal_sz(sz1,sz2) clar__assert_equal(__FILE__,__LINE__,#sz1 " != " #sz2, 1, "%"PRIuZ, (size_t)(sz1), (size_t)(sz2))
void clar__fail(
const char *file,
diff --git a/tests-clar/clar_libgit2.c b/tests-clar/clar_libgit2.c
index 340943ca8..555af38db 100644
--- a/tests-clar/clar_libgit2.c
+++ b/tests-clar/clar_libgit2.c
@@ -30,24 +30,26 @@ void cl_git_mkfile(const char *filename, const char *content)
}
void cl_git_write2file(
- const char *filename, const char *new_content, int flags, unsigned int mode)
+ const char *path, const char *content, size_t content_len,
+ int flags, unsigned int mode)
{
- int fd = p_open(filename, flags, mode);
- cl_assert(fd >= 0);
- if (!new_content)
- new_content = "\n";
- cl_must_pass(p_write(fd, new_content, strlen(new_content)));
+ int fd;
+ cl_assert(path && content);
+ cl_assert((fd = p_open(path, flags, mode)) >= 0);
+ if (!content_len)
+ content_len = strlen(content);
+ cl_must_pass(p_write(fd, content, content_len));
cl_must_pass(p_close(fd));
}
-void cl_git_append2file(const char *filename, const char *new_content)
+void cl_git_append2file(const char *path, const char *content)
{
- cl_git_write2file(filename, new_content, O_WRONLY | O_CREAT | O_APPEND, 0644);
+ cl_git_write2file(path, content, 0, O_WRONLY | O_CREAT | O_APPEND, 0644);
}
-void cl_git_rewritefile(const char *filename, const char *new_content)
+void cl_git_rewritefile(const char *path, const char *content)
{
- cl_git_write2file(filename, new_content, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ cl_git_write2file(path, content, 0, O_WRONLY | O_CREAT | O_TRUNC, 0644);
}
#ifdef GIT_WIN32
@@ -337,6 +339,65 @@ int cl_git_remove_placeholders(const char *directory_path, const char *filename)
return error;
}
+#define CL_COMMIT_NAME "Libgit2 Tester"
+#define CL_COMMIT_EMAIL "libgit2-test@github.com"
+#define CL_COMMIT_MSG "Test commit of tree "
+
+void cl_repo_commit_from_index(
+ git_oid *out,
+ git_repository *repo,
+ git_signature *sig,
+ git_time_t time,
+ const char *msg)
+{
+ git_index *index;
+ git_oid commit_id, tree_id;
+ git_object *parent = NULL;
+ git_reference *ref = NULL;
+ git_tree *tree = NULL;
+ char buf[128];
+ int free_sig = (sig == NULL);
+
+ /* it is fine if looking up HEAD fails - we make this the first commit */
+ git_revparse_ext(&parent, &ref, repo, "HEAD");
+
+ /* write the index content as a tree */
+ cl_git_pass(git_repository_index(&index, repo));
+ cl_git_pass(git_index_write_tree(&tree_id, index));
+ cl_git_pass(git_index_write(index));
+ git_index_free(index);
+
+ cl_git_pass(git_tree_lookup(&tree, repo, &tree_id));
+
+ if (sig)
+ cl_assert(sig->name && sig->email);
+ else if (!time)
+ cl_git_pass(git_signature_now(&sig, CL_COMMIT_NAME, CL_COMMIT_EMAIL));
+ else
+ cl_git_pass(git_signature_new(
+ &sig, CL_COMMIT_NAME, CL_COMMIT_EMAIL, time, 0));
+
+ if (!msg) {
+ strcpy(buf, CL_COMMIT_MSG);
+ git_oid_tostr(buf + strlen(CL_COMMIT_MSG),
+ sizeof(buf) - strlen(CL_COMMIT_MSG), &tree_id);
+ msg = buf;
+ }
+
+ cl_git_pass(git_commit_create_v(
+ &commit_id, repo, ref ? git_reference_name(ref) : "HEAD",
+ sig, sig, NULL, msg, tree, parent ? 1 : 0, parent));
+
+ if (out)
+ git_oid_cpy(out, &commit_id);
+
+ git_object_free(parent);
+ git_reference_free(ref);
+ if (free_sig)
+ git_signature_free(sig);
+ git_tree_free(tree);
+}
+
void cl_repo_set_bool(git_repository *repo, const char *cfg, int value)
{
git_config *config;
@@ -354,3 +415,65 @@ int cl_repo_get_bool(git_repository *repo, const char *cfg)
git_config_free(config);
return val;
}
+
+/* this is essentially the code from git__unescape modified slightly */
+static size_t strip_cr_from_buf(char *start, size_t len)
+{
+ char *scan, *trail, *end = start + len;
+
+ for (scan = trail = start; scan < end; trail++, scan++) {
+ while (*scan == '\r')
+ scan++; /* skip '\r' */
+
+ if (trail != scan)
+ *trail = *scan;
+ }
+
+ *trail = '\0';
+
+ return (trail - start);
+}
+
+void clar__assert_equal_file(
+ const char *expected_data,
+ size_t expected_bytes,
+ int ignore_cr,
+ const char *path,
+ const char *file,
+ size_t line)
+{
+ char buf[4000];
+ ssize_t bytes, total_bytes = 0;
+ int fd = p_open(path, O_RDONLY | O_BINARY);
+ cl_assert(fd >= 0);
+
+ if (expected_data && !expected_bytes)
+ expected_bytes = strlen(expected_data);
+
+ while ((bytes = p_read(fd, buf, sizeof(buf))) != 0) {
+ clar__assert(
+ bytes > 0, file, line, "error reading from file", path, 1);
+
+ if (ignore_cr)
+ bytes = strip_cr_from_buf(buf, bytes);
+
+ if (memcmp(expected_data, buf, bytes) != 0) {
+ int pos;
+ for (pos = 0; pos < bytes && expected_data[pos] == buf[pos]; ++pos)
+ /* find differing byte offset */;
+ p_snprintf(
+ buf, sizeof(buf), "file content mismatch at byte %d",
+ (int)(total_bytes + pos));
+ clar__fail(file, line, buf, path, 1);
+ }
+
+ expected_data += bytes;
+ total_bytes += bytes;
+ }
+
+ p_close(fd);
+
+ clar__assert(!bytes, file, line, "error reading from file", path, 1);
+ clar__assert_equal(file, line, "mismatched file length", 1, "%"PRIuZ,
+ (size_t)expected_bytes, (size_t)total_bytes);
+}
diff --git a/tests-clar/clar_libgit2.h b/tests-clar/clar_libgit2.h
index 8dcfdee48..9d4d63e6c 100644
--- a/tests-clar/clar_libgit2.h
+++ b/tests-clar/clar_libgit2.h
@@ -43,9 +43,28 @@ GIT_INLINE(void) clar__assert_in_range(
}
}
+#define cl_assert_equal_sz(sz1,sz2) do { \
+ size_t __sz1 = (sz1), __sz2 = (sz2); \
+ clar__assert_equal(__FILE__,__LINE__,#sz1 " != " #sz2, 1, "%"PRIuZ, __sz1, __sz2); \
+} while (0)
+
#define cl_assert_in_range(L,V,H) \
clar__assert_in_range((L),(V),(H),__FILE__,__LINE__,"Range check: " #V " in [" #L "," #H "]", 1)
+#define cl_assert_equal_file(DATA,SIZE,PATH) \
+ clar__assert_equal_file(DATA,SIZE,0,PATH,__FILE__,__LINE__)
+
+#define cl_assert_equal_file_ignore_cr(DATA,SIZE,PATH) \
+ clar__assert_equal_file(DATA,SIZE,1,PATH,__FILE__,__LINE__)
+
+void clar__assert_equal_file(
+ const char *expected_data,
+ size_t expected_size,
+ int ignore_cr,
+ const char *path,
+ const char *file,
+ size_t line);
+
/*
* Some utility macros for building long strings
*/
@@ -59,7 +78,8 @@ GIT_INLINE(void) clar__assert_in_range(
void cl_git_mkfile(const char *filename, const char *content);
void cl_git_append2file(const char *filename, const char *new_content);
void cl_git_rewritefile(const char *filename, const char *new_content);
-void cl_git_write2file(const char *filename, const char *new_content, int flags, unsigned int mode);
+void cl_git_write2file(const char *path, const char *data,
+ size_t datalen, int flags, unsigned int mode);
bool cl_toggle_filemode(const char *filename);
bool cl_is_chmod_supported(void);
@@ -84,6 +104,14 @@ const char* cl_git_path_url(const char *path);
/* Test repository cleaner */
int cl_git_remove_placeholders(const char *directory_path, const char *filename);
+/* commit creation helpers */
+void cl_repo_commit_from_index(
+ git_oid *out,
+ git_repository *repo,
+ git_signature *sig,
+ git_time_t time,
+ const char *msg);
+
/* config setting helpers */
void cl_repo_set_bool(git_repository *repo, const char *cfg, int value);
int cl_repo_get_bool(git_repository *repo, const char *cfg);
diff --git a/tests-clar/clone/empty.c b/tests-clar/clone/empty.c
index f92fa6cbb..d9dc24fde 100644
--- a/tests-clar/clone/empty.c
+++ b/tests-clar/clone/empty.c
@@ -44,7 +44,7 @@ void test_clone_empty__can_clone_an_empty_local_repo_barely(void)
g_options.bare = true;
cl_git_pass(git_clone(&g_repo_cloned, "./empty_bare.git", "./empty", &g_options));
- /* Although the HEAD is orphaned... */
+ /* Although the HEAD is unborn... */
cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&ref, g_repo_cloned, local_name));
/* ...one can still retrieve the name of the remote tracking reference */
@@ -59,7 +59,7 @@ void test_clone_empty__can_clone_an_empty_local_repo_barely(void)
cl_assert_equal_s(expected_remote_name, buffer);
- /* ...even when the remote HEAD is orphaned as well */
+ /* ...even when the remote HEAD is unborn as well */
cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&ref, g_repo_cloned,
expected_tracked_branch_name));
}
diff --git a/tests-clar/clone/nonetwork.c b/tests-clar/clone/nonetwork.c
index 339b1e70d..5b9faa645 100644
--- a/tests-clar/clone/nonetwork.c
+++ b/tests-clar/clone/nonetwork.c
@@ -228,7 +228,7 @@ void test_clone_nonetwork__can_checkout_given_branch(void)
g_options.checkout_branch = "test";
cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
- cl_assert_equal_i(0, git_repository_head_orphan(g_repo));
+ cl_assert_equal_i(0, git_repository_head_unborn(g_repo));
cl_git_pass(git_repository_head(&g_ref, g_repo));
cl_assert_equal_s(git_reference_name(g_ref), "refs/heads/test");
diff --git a/tests-clar/config/global.c b/tests-clar/config/global.c
index 2ecdf97d8..d5f95f504 100644
--- a/tests-clar/config/global.c
+++ b/tests-clar/config/global.c
@@ -6,18 +6,21 @@ void test_config_global__initialize(void)
{
git_buf path = GIT_BUF_INIT;
- cl_must_pass(p_mkdir("home", 0777));
+ cl_assert_equal_i(0, p_mkdir("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_must_pass(p_mkdir("xdg", 0777));
- cl_git_pass(git_path_prettify(&path, "xdg", NULL));
+ cl_assert_equal_i(0, p_mkdir("xdg", 0777));
+ cl_assert_equal_i(0, p_mkdir("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_SYSTEM, path.ptr));
+ GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr));
+ cl_assert_equal_i(0, p_mkdir("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_XDG, NULL));
+ GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr));
git_buf_free(&path);
}
@@ -26,6 +29,11 @@ void test_config_global__cleanup(void)
{
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));
+
+ git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, NULL);
+ git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, NULL);
+ git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, NULL);
}
void test_config_global__open_global(void)
@@ -48,10 +56,7 @@ void test_config_global__open_xdg(void)
const char *val, *str = "teststring";
const char *key = "this.variable";
- p_setenv("XDG_CONFIG_HOME", "xdg", 1);
-
- cl_must_pass(p_mkdir("xdg/git/", 0777));
- cl_git_mkfile("xdg/git/config", "");
+ 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));
diff --git a/tests-clar/config/include.c b/tests-clar/config/include.c
new file mode 100644
index 000000000..535573808
--- /dev/null
+++ b/tests-clar/config/include.c
@@ -0,0 +1,109 @@
+#include "clar_libgit2.h"
+#include "buffer.h"
+#include "fileops.h"
+
+void test_config_include__relative(void)
+{
+ git_config *cfg;
+ const char *str;
+
+ cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config-include")));
+
+ cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
+ cl_assert_equal_s(str, "huzzah");
+
+ git_config_free(cfg);
+}
+
+void test_config_include__absolute(void)
+{
+ git_config *cfg;
+ const char *str;
+ git_buf buf = GIT_BUF_INIT;
+
+ 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_free(&buf);
+ cl_git_pass(git_config_open_ondisk(&cfg, "config-include-absolute"));
+
+ cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
+ cl_assert_equal_s(str, "huzzah");
+
+ git_config_free(cfg);
+}
+
+void test_config_include__homedir(void)
+{
+ git_config *cfg;
+ const char *str;
+
+ 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(&str, cfg, "foo.bar.baz"));
+ cl_assert_equal_s(str, "huzzah");
+
+ git_config_free(cfg);
+}
+
+void test_config_include__refresh(void)
+{
+ git_config *cfg;
+ const char *str;
+
+ cl_fixture_sandbox("config");
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "config/config-include"));
+
+ cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
+ cl_assert_equal_s(str, "huzzah");
+
+ /* Change the included file and see if we refresh */
+ cl_git_mkfile("config/config-included", "[foo \"bar\"]\nbaz = hurrah");
+ cl_git_pass(git_config_refresh(cfg));
+
+ cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
+ cl_assert_equal_s(str, "hurrah");
+
+ git_config_free(cfg);
+ cl_fixture_cleanup("config");
+}
+
+/* We need to pretend that the variables were defined where the file was included */
+void test_config_include__ordering(void)
+{
+ git_config *cfg;
+ const char *str;
+
+ 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(&str, cfg, "foo.bar.frotz"));
+ cl_assert_equal_s(str, "hiya");
+ cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
+ cl_assert_equal_s(str, "huzzah");
+
+ git_config_free(cfg);
+}
+
+/* We need to pretend that the variables were defined where the file was included */
+void test_config_include__depth(void)
+{
+ git_config *cfg;
+
+ cl_git_mkfile("a", "[include]\npath = b");
+ cl_git_mkfile("b", "[include]\npath = a");
+
+ cl_git_fail(git_config_open_ondisk(&cfg, "a"));
+
+ unlink("a");
+ unlink("b");
+}
diff --git a/tests-clar/config/read.c b/tests-clar/config/read.c
index 395f1cfdb..722a15a71 100644
--- a/tests-clar/config/read.c
+++ b/tests-clar/config/read.c
@@ -523,3 +523,18 @@ void test_config_read__corrupt_header(void)
git_config_free(cfg);
}
+
+void test_config_read__override_variable(void)
+{
+ git_config *cfg;
+ const char *str;
+
+ 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(&str, cfg, "some.var"));
+ cl_assert_equal_s(str, "two");
+
+ git_config_free(cfg);
+}
diff --git a/tests-clar/core/buffer.c b/tests-clar/core/buffer.c
index 8a0b6711f..11d173d49 100644
--- a/tests-clar/core/buffer.c
+++ b/tests-clar/core/buffer.c
@@ -919,6 +919,8 @@ void test_core_buffer__similarity_metric_whitespace(void)
git_buf_free(&buf);
}
+#include "../filter/crlf.h"
+
#define check_buf(expected,buf) do { \
cl_assert_equal_s(expected, buf.ptr); \
cl_assert_equal_sz(strlen(expected), buf.size); } while (0)
@@ -934,16 +936,16 @@ void test_core_buffer__lf_and_crlf_conversions(void)
cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
check_buf("lf\r\nlf\r\nlf\r\nlf\r\n", tgt);
- cl_assert_equal_i(GIT_ENOTFOUND, git_buf_text_crlf_to_lf(&tgt, &src));
- /* no conversion needed if all LFs already */
+ cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
+ check_buf(src.ptr, tgt);
git_buf_sets(&src, "\nlf\nlf\nlf\nlf\nlf");
cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
check_buf("\r\nlf\r\nlf\r\nlf\r\nlf\r\nlf", tgt);
- cl_assert_equal_i(GIT_ENOTFOUND, git_buf_text_crlf_to_lf(&tgt, &src));
- /* no conversion needed if all LFs already */
+ cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
+ check_buf(src.ptr, tgt);
/* CRLF source */
@@ -993,10 +995,45 @@ void test_core_buffer__lf_and_crlf_conversions(void)
check_buf("\rcrlf\nlf\nlf\ncr\rcrlf\nlf\ncr\r", tgt);
git_buf_sets(&src, "\rcr\r");
- cl_assert_equal_i(GIT_ENOTFOUND, git_buf_text_lf_to_crlf(&tgt, &src));
+ cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
+ check_buf(src.ptr, tgt);
cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
check_buf("\rcr\r", tgt);
git_buf_free(&src);
git_buf_free(&tgt);
+
+ /* blob correspondence tests */
+
+ git_buf_sets(&src, ALL_CRLF_TEXT_RAW);
+ cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
+ check_buf(ALL_CRLF_TEXT_AS_CRLF, tgt);
+ cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
+ check_buf(ALL_CRLF_TEXT_AS_LF, tgt);
+ git_buf_free(&src);
+ git_buf_free(&tgt);
+
+ git_buf_sets(&src, ALL_LF_TEXT_RAW);
+ cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
+ check_buf(ALL_LF_TEXT_AS_CRLF, tgt);
+ cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
+ check_buf(ALL_LF_TEXT_AS_LF, tgt);
+ git_buf_free(&src);
+ git_buf_free(&tgt);
+
+ git_buf_sets(&src, MORE_CRLF_TEXT_RAW);
+ cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
+ check_buf(MORE_CRLF_TEXT_AS_CRLF, tgt);
+ cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
+ check_buf(MORE_CRLF_TEXT_AS_LF, tgt);
+ git_buf_free(&src);
+ git_buf_free(&tgt);
+
+ git_buf_sets(&src, MORE_LF_TEXT_RAW);
+ cl_git_pass(git_buf_text_lf_to_crlf(&tgt, &src));
+ check_buf(MORE_LF_TEXT_AS_CRLF, tgt);
+ cl_git_pass(git_buf_text_crlf_to_lf(&tgt, &src));
+ check_buf(MORE_LF_TEXT_AS_LF, tgt);
+ git_buf_free(&src);
+ git_buf_free(&tgt);
}
diff --git a/tests-clar/core/filebuf.c b/tests-clar/core/filebuf.c
index 4451c01c7..bf2167057 100644
--- a/tests-clar/core/filebuf.c
+++ b/tests-clar/core/filebuf.c
@@ -24,18 +24,16 @@ void test_core_filebuf__0(void)
void test_core_filebuf__1(void)
{
git_filebuf file = GIT_FILEBUF_INIT;
- int fd;
char test[] = "test";
- fd = p_creat(test, 0666); //-V536
- cl_must_pass(fd);
- cl_must_pass(p_write(fd, "libgit2 rocks\n", 14));
- cl_must_pass(p_close(fd));
+ cl_git_mkfile(test, "libgit2 rocks\n");
cl_git_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND));
cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks"));
cl_git_pass(git_filebuf_commit(&file, 0666));
+ cl_assert_equal_file("libgit2 rocks\nlibgit2 rocks\n", 0, test);
+
cl_must_pass(p_unlink(test));
}
@@ -53,6 +51,8 @@ void test_core_filebuf__2(void)
cl_git_pass(git_filebuf_write(&file, buf, sizeof(buf)));
cl_git_pass(git_filebuf_commit(&file, 0666));
+ cl_assert_equal_file((char *)buf, sizeof(buf), test);
+
cl_must_pass(p_unlink(test));
}
diff --git a/tests-clar/diff/rename.c b/tests-clar/diff/rename.c
index b5a9935fd..9864c5896 100644
--- a/tests-clar/diff/rename.c
+++ b/tests-clar/diff/rename.c
@@ -7,6 +7,8 @@ static git_repository *g_repo = NULL;
void test_diff_rename__initialize(void)
{
g_repo = cl_git_sandbox_init("renames");
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", false);
}
void test_diff_rename__cleanup(void)
diff --git a/tests-clar/diff/submodules.c b/tests-clar/diff/submodules.c
index 9dcf8194e..036ff09aa 100644
--- a/tests-clar/diff/submodules.c
+++ b/tests-clar/diff/submodules.c
@@ -11,7 +11,6 @@ void test_diff_submodules__initialize(void)
void test_diff_submodules__cleanup(void)
{
- cleanup_fixture_submodules();
}
static void check_diff_patches_at_line(
@@ -229,11 +228,11 @@ void test_diff_submodules__invalid_cache(void)
"<END>"
};
static const char *expected_moved[] = {
- "diff --git a/sm_changed_head b/sm_changed_head\nindex 3d9386c..0910a13 160000\n--- a/sm_changed_head\n+++ b/sm_changed_head\n@@ -1 +1 @@\n-Subproject commit 3d9386c507f6b093471a3e324085657a3c2b4247\n+Subproject commit 0910a13dfa2210496f6c590d75bc360dd11b2a1b\n",
+ "diff --git a/sm_changed_head b/sm_changed_head\nindex 3d9386c..7002348 160000\n--- a/sm_changed_head\n+++ b/sm_changed_head\n@@ -1 +1 @@\n-Subproject commit 3d9386c507f6b093471a3e324085657a3c2b4247\n+Subproject commit 700234833f6ccc20d744b238612646be071acaae\n",
"<END>"
};
static const char *expected_moved_dirty[] = {
- "diff --git a/sm_changed_head b/sm_changed_head\nindex 3d9386c..0910a13 160000\n--- a/sm_changed_head\n+++ b/sm_changed_head\n@@ -1 +1 @@\n-Subproject commit 3d9386c507f6b093471a3e324085657a3c2b4247\n+Subproject commit 0910a13dfa2210496f6c590d75bc360dd11b2a1b-dirty\n",
+ "diff --git a/sm_changed_head b/sm_changed_head\nindex 3d9386c..7002348 160000\n--- a/sm_changed_head\n+++ b/sm_changed_head\n@@ -1 +1 @@\n-Subproject commit 3d9386c507f6b093471a3e324085657a3c2b4247\n+Subproject commit 700234833f6ccc20d744b238612646be071acaae-dirty\n",
"<END>"
};
@@ -310,26 +309,7 @@ void test_diff_submodules__invalid_cache(void)
git_diff_list_free(diff);
/* commit changed index of submodule */
- {
- git_object *parent;
- git_oid tree_id, commit_id;
- git_tree *tree;
- git_signature *sig;
- git_reference *ref;
-
- cl_git_pass(git_revparse_ext(&parent, &ref, smrepo, "HEAD"));
- cl_git_pass(git_index_write_tree(&tree_id, smindex));
- cl_git_pass(git_index_write(smindex));
- cl_git_pass(git_tree_lookup(&tree, smrepo, &tree_id));
- cl_git_pass(git_signature_new(&sig, "Sm Test", "sm@tester.test", 1372350000, 480));
- cl_git_pass(git_commit_create_v(
- &commit_id, smrepo, git_reference_name(ref), sig, sig,
- NULL, "Move it", tree, 1, parent));
- git_object_free(parent);
- git_tree_free(tree);
- git_reference_free(ref);
- git_signature_free(sig);
- }
+ cl_repo_commit_from_index(NULL, smrepo, NULL, 1372350000, "Move it");
git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_DIRTY);
diff --git a/tests-clar/diff/workdir.c b/tests-clar/diff/workdir.c
index c7fac1e48..6c17b41c6 100644
--- a/tests-clar/diff/workdir.c
+++ b/tests-clar/diff/workdir.c
@@ -1266,3 +1266,28 @@ void test_diff_workdir__untracked_directory_comes_last(void)
git_diff_list_free(diff);
}
+
+void test_diff_workdir__untracked_with_bom(void)
+{
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_list *diff = NULL;
+ const git_diff_delta *delta;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+
+ cl_git_write2file("empty_standard_repo/bom.txt",
+ "\xFF\xFE\x31\x00\x32\x00\x33\x00\x34\x00", 10, O_WRONLY|O_CREAT, 0664);
+
+ opts.flags =
+ GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_INCLUDE_UNTRACKED_CONTENT;
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+
+ cl_assert_equal_i(1, git_diff_num_deltas(diff));
+ cl_git_pass(git_diff_get_patch(NULL, &delta, diff, 0));
+ cl_assert_equal_i(GIT_DELTA_UNTRACKED, delta->status);
+ cl_assert((delta->flags & GIT_DIFF_FLAG_BINARY) != 0);
+
+ git_diff_list_free(diff);
+}
diff --git a/tests-clar/filter/blob.c b/tests-clar/filter/blob.c
new file mode 100644
index 000000000..9600a9779
--- /dev/null
+++ b/tests-clar/filter/blob.c
@@ -0,0 +1,84 @@
+#include "clar_libgit2.h"
+#include "crlf.h"
+
+static git_repository *g_repo = NULL;
+
+void test_filter_blob__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("crlf");
+ cl_git_mkfile("crlf/.gitattributes",
+ "*.txt text\n*.bin binary\n"
+ "*.crlf text eol=crlf\n"
+ "*.lf text eol=lf\n"
+ "*.ident text ident\n"
+ "*.identcrlf ident text eol=crlf\n"
+ "*.identlf ident text eol=lf\n");
+}
+
+void test_filter_blob__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_filter_blob__all_crlf(void)
+{
+ git_blob *blob;
+ git_buf buf = { 0 };
+
+ cl_git_pass(git_revparse_single(
+ (git_object **)&blob, g_repo, "a9a2e891")); /* all-crlf */
+
+ cl_assert_equal_s(ALL_CRLF_TEXT_RAW, git_blob_rawcontent(blob));
+
+ cl_git_pass(git_blob_filtered_content(&buf, blob, "file.bin", 1));
+
+ cl_assert_equal_s(ALL_CRLF_TEXT_RAW, buf.ptr);
+
+ cl_git_pass(git_blob_filtered_content(&buf, blob, "file.crlf", 1));
+
+ /* in this case, raw content has crlf in it already */
+ cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF, buf.ptr);
+
+ cl_git_pass(git_blob_filtered_content(&buf, blob, "file.lf", 1));
+
+ cl_assert_equal_s(ALL_CRLF_TEXT_AS_LF, buf.ptr);
+
+ git_buf_free(&buf);
+ git_blob_free(blob);
+}
+
+void test_filter_blob__ident(void)
+{
+ git_oid id;
+ git_blob *blob;
+ git_buf buf = { 0 };
+
+ cl_git_mkfile("crlf/test.ident", "Some text\n$Id$\nGoes there\n");
+ cl_git_pass(git_blob_create_fromworkdir(&id, g_repo, "test.ident"));
+ cl_git_pass(git_blob_lookup(&blob, g_repo, &id));
+ cl_assert_equal_s(
+ "Some text\n$Id$\nGoes there\n", git_blob_rawcontent(blob));
+ git_blob_free(blob);
+
+ cl_git_mkfile("crlf/test.ident", "Some text\n$Id: Any old just you want$\nGoes there\n");
+ cl_git_pass(git_blob_create_fromworkdir(&id, g_repo, "test.ident"));
+ cl_git_pass(git_blob_lookup(&blob, g_repo, &id));
+ cl_assert_equal_s(
+ "Some text\n$Id$\nGoes there\n", git_blob_rawcontent(blob));
+
+ cl_git_pass(git_blob_filtered_content(&buf, blob, "filter.bin", 1));
+ cl_assert_equal_s(
+ "Some text\n$Id$\nGoes there\n", buf.ptr);
+
+ cl_git_pass(git_blob_filtered_content(&buf, blob, "filter.identcrlf", 1));
+ cl_assert_equal_s(
+ "Some text\r\n$Id: 3164f585d548ac68027d22b104f2d8100b2b6845$\r\nGoes there\r\n", buf.ptr);
+
+ cl_git_pass(git_blob_filtered_content(&buf, blob, "filter.identlf", 1));
+ cl_assert_equal_s(
+ "Some text\n$Id: 3164f585d548ac68027d22b104f2d8100b2b6845$\nGoes there\n", buf.ptr);
+
+ git_buf_free(&buf);
+ git_blob_free(blob);
+
+}
diff --git a/tests-clar/filter/crlf.c b/tests-clar/filter/crlf.c
new file mode 100644
index 000000000..c9fb9cd7f
--- /dev/null
+++ b/tests-clar/filter/crlf.c
@@ -0,0 +1,71 @@
+#include "clar_libgit2.h"
+#include "git2/sys/filter.h"
+
+static git_repository *g_repo = NULL;
+
+void test_filter_crlf__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("crlf");
+
+ cl_git_mkfile("crlf/.gitattributes",
+ "*.txt text\n*.bin binary\n*.crlf text eol=crlf\n*.lf text eol=lf\n");
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
+}
+
+void test_filter_crlf__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_filter_crlf__to_worktree(void)
+{
+ git_filter_list *fl;
+ git_filter *crlf;
+ git_buf in = { 0 }, out = { 0 };
+
+ cl_git_pass(git_filter_list_new(&fl, g_repo, GIT_FILTER_TO_WORKTREE));
+
+ crlf = git_filter_lookup(GIT_FILTER_CRLF);
+ cl_assert(crlf != NULL);
+
+ cl_git_pass(git_filter_list_push(fl, crlf, NULL));
+
+ in.ptr = "Some text\nRight here\n";
+ in.size = strlen(in.ptr);
+
+ cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+
+#ifdef GIT_WIN32
+ cl_assert_equal_s("Some text\r\nRight here\r\n", out.ptr);
+#else
+ cl_assert_equal_s("Some text\nRight here\n", out.ptr);
+#endif
+
+ git_filter_list_free(fl);
+ git_buf_free(&out);
+}
+
+void test_filter_crlf__to_odb(void)
+{
+ git_filter_list *fl;
+ git_filter *crlf;
+ git_buf in = { 0 }, out = { 0 };
+
+ cl_git_pass(git_filter_list_new(&fl, g_repo, GIT_FILTER_TO_ODB));
+
+ crlf = git_filter_lookup(GIT_FILTER_CRLF);
+ cl_assert(crlf != NULL);
+
+ cl_git_pass(git_filter_list_push(fl, crlf, NULL));
+
+ in.ptr = "Some text\r\nRight here\r\n";
+ in.size = strlen(in.ptr);
+
+ cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+
+ cl_assert_equal_s("Some text\nRight here\n", out.ptr);
+
+ git_filter_list_free(fl);
+ git_buf_free(&out);
+}
diff --git a/tests-clar/filter/crlf.h b/tests-clar/filter/crlf.h
new file mode 100644
index 000000000..9cb98ad4c
--- /dev/null
+++ b/tests-clar/filter/crlf.h
@@ -0,0 +1,25 @@
+#ifndef INCLUDE_filter_crlf_h__
+#define INCLUDE_filter_crlf_h__
+
+/*
+ * file content for files in the resources/crlf repository
+ */
+
+#define UTF8_BOM "\xEF\xBB\xBF"
+
+#define ALL_CRLF_TEXT_RAW "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n"
+#define ALL_LF_TEXT_RAW "lf\nlf\nlf\nlf\nlf\n"
+#define MORE_CRLF_TEXT_RAW "crlf\r\ncrlf\r\nlf\ncrlf\r\ncrlf\r\n"
+#define MORE_LF_TEXT_RAW "lf\nlf\ncrlf\r\nlf\nlf\n"
+
+#define ALL_CRLF_TEXT_AS_CRLF ALL_CRLF_TEXT_RAW
+#define ALL_LF_TEXT_AS_CRLF "lf\r\nlf\r\nlf\r\nlf\r\nlf\r\n"
+#define MORE_CRLF_TEXT_AS_CRLF "crlf\r\ncrlf\r\nlf\r\ncrlf\r\ncrlf\r\n"
+#define MORE_LF_TEXT_AS_CRLF "lf\r\nlf\r\ncrlf\r\nlf\r\nlf\r\n"
+
+#define ALL_CRLF_TEXT_AS_LF "crlf\ncrlf\ncrlf\ncrlf\n"
+#define ALL_LF_TEXT_AS_LF ALL_LF_TEXT_RAW
+#define MORE_CRLF_TEXT_AS_LF "crlf\ncrlf\nlf\ncrlf\ncrlf\n"
+#define MORE_LF_TEXT_AS_LF "lf\nlf\ncrlf\nlf\nlf\n"
+
+#endif
diff --git a/tests-clar/filter/custom.c b/tests-clar/filter/custom.c
new file mode 100644
index 000000000..a81885c28
--- /dev/null
+++ b/tests-clar/filter/custom.c
@@ -0,0 +1,337 @@
+#include "clar_libgit2.h"
+#include "posix.h"
+#include "blob.h"
+#include "filter.h"
+#include "buf_text.h"
+#include "git2/sys/filter.h"
+#include "git2/sys/repository.h"
+
+/* going TO_WORKDIR, filters are executed low to high
+ * going TO_ODB, filters are executed high to low
+ */
+#define BITFLIP_FILTER_PRIORITY -1
+#define REVERSE_FILTER_PRIORITY -2
+
+#define VERY_SECURE_ENCRYPTION(b) ((b) ^ 0xff)
+
+#ifdef GIT_WIN32
+# define NEWLINE "\r\n"
+#else
+# define NEWLINE "\n"
+#endif
+
+static char workdir_data[] =
+ "some simple" NEWLINE
+ "data" NEWLINE
+ "that will be" NEWLINE
+ "trivially" NEWLINE
+ "scrambled." NEWLINE;
+
+/* Represents the data above scrambled (bits flipped) after \r\n -> \n
+ * conversion, then bytewise reversed
+ */
+static unsigned char bitflipped_and_reversed_data[] =
+ { 0xf5, 0xd1, 0x9b, 0x9a, 0x93, 0x9d, 0x92, 0x9e, 0x8d, 0x9c, 0x8c,
+ 0xf5, 0x86, 0x93, 0x93, 0x9e, 0x96, 0x89, 0x96, 0x8d, 0x8b, 0xf5,
+ 0x9a, 0x9d, 0xdf, 0x93, 0x93, 0x96, 0x88, 0xdf, 0x8b, 0x9e, 0x97,
+ 0x8b, 0xf5, 0x9e, 0x8b, 0x9e, 0x9b, 0xf5, 0x9a, 0x93, 0x8f, 0x92,
+ 0x96, 0x8c, 0xdf, 0x9a, 0x92, 0x90, 0x8c };
+
+#define BITFLIPPED_AND_REVERSED_DATA_LEN 51
+
+static git_repository *g_repo = NULL;
+
+static void register_custom_filters(void);
+
+void test_filter_custom__initialize(void)
+{
+ register_custom_filters();
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+
+ cl_git_mkfile(
+ "empty_standard_repo/.gitattributes",
+ "hero* bitflip reverse\n"
+ "herofile text\n"
+ "heroflip -reverse binary\n"
+ "*.bin binary\n");
+}
+
+void test_filter_custom__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+ g_repo = NULL;
+}
+
+static int bitflip_filter_apply(
+ git_filter *self,
+ void **payload,
+ git_buf *to,
+ const git_buf *from,
+ const git_filter_source *source)
+{
+ const unsigned char *src = (const unsigned char *)from->ptr;
+ unsigned char *dst;
+ size_t i;
+
+ GIT_UNUSED(self); GIT_UNUSED(payload);
+
+ /* verify that attribute path match worked as expected */
+ cl_assert_equal_i(
+ 0, git__strncmp("hero", git_filter_source_path(source), 4));
+
+ if (!from->size)
+ return 0;
+
+ cl_git_pass(git_buf_grow(to, from->size));
+
+ dst = (unsigned char *)to->ptr;
+
+ for (i = 0; i < from->size; i++)
+ dst[i] = VERY_SECURE_ENCRYPTION(src[i]);
+
+ to->size = from->size;
+
+ return 0;
+}
+
+static void bitflip_filter_free(git_filter *f)
+{
+ git__free(f);
+}
+
+static git_filter *create_bitflip_filter(void)
+{
+ git_filter *filter = git__calloc(1, sizeof(git_filter));
+ cl_assert(filter);
+
+ filter->version = GIT_FILTER_VERSION;
+ filter->attributes = "+bitflip";
+ filter->shutdown = bitflip_filter_free;
+ filter->apply = bitflip_filter_apply;
+
+ return filter;
+}
+
+
+static int reverse_filter_apply(
+ git_filter *self,
+ void **payload,
+ git_buf *to,
+ const git_buf *from,
+ const git_filter_source *source)
+{
+ const unsigned char *src = (const unsigned char *)from->ptr;
+ const unsigned char *end = src + from->size;
+ unsigned char *dst;
+
+ GIT_UNUSED(self); GIT_UNUSED(payload); GIT_UNUSED(source);
+
+ /* verify that attribute path match worked as expected */
+ cl_assert_equal_i(
+ 0, git__strncmp("hero", git_filter_source_path(source), 4));
+
+ if (!from->size)
+ return 0;
+
+ cl_git_pass(git_buf_grow(to, from->size));
+
+ dst = (unsigned char *)to->ptr + from->size - 1;
+
+ while (src < end)
+ *dst-- = *src++;
+
+ to->size = from->size;
+
+ return 0;
+}
+
+static void reverse_filter_free(git_filter *f)
+{
+ git__free(f);
+}
+
+static git_filter *create_reverse_filter(const char *attrs)
+{
+ git_filter *filter = git__calloc(1, sizeof(git_filter));
+ cl_assert(filter);
+
+ filter->version = GIT_FILTER_VERSION;
+ filter->attributes = attrs;
+ filter->shutdown = reverse_filter_free;
+ filter->apply = reverse_filter_apply;
+
+ return filter;
+}
+
+static void register_custom_filters(void)
+{
+ static int filters_registered = 0;
+
+ if (!filters_registered) {
+ cl_git_pass(git_filter_register(
+ "bitflip", create_bitflip_filter(), BITFLIP_FILTER_PRIORITY));
+
+ cl_git_pass(git_filter_register(
+ "reverse", create_reverse_filter("+reverse"),
+ REVERSE_FILTER_PRIORITY));
+
+ /* re-register reverse filter with standard filter=xyz priority */
+ cl_git_pass(git_filter_register(
+ "pre-reverse",
+ create_reverse_filter("+prereverse"),
+ GIT_FILTER_DRIVER_PRIORITY));
+
+ filters_registered = 1;
+ }
+}
+
+
+void test_filter_custom__to_odb(void)
+{
+ git_filter_list *fl;
+ git_buf out = { 0 };
+ git_buf in = GIT_BUF_INIT_CONST(workdir_data, strlen(workdir_data));
+
+ cl_git_pass(git_filter_list_load(
+ &fl, g_repo, NULL, "herofile", GIT_FILTER_TO_ODB));
+
+ cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+
+ cl_assert_equal_i(BITFLIPPED_AND_REVERSED_DATA_LEN, out.size);
+
+ cl_assert_equal_i(
+ 0, memcmp(bitflipped_and_reversed_data, out.ptr, out.size));
+
+ git_filter_list_free(fl);
+ git_buf_free(&out);
+}
+
+void test_filter_custom__to_workdir(void)
+{
+ git_filter_list *fl;
+ git_buf out = { 0 };
+ git_buf in = GIT_BUF_INIT_CONST(
+ bitflipped_and_reversed_data, BITFLIPPED_AND_REVERSED_DATA_LEN);
+
+ cl_git_pass(git_filter_list_load(
+ &fl, g_repo, NULL, "herofile", GIT_FILTER_TO_WORKTREE));
+
+ cl_git_pass(git_filter_list_apply_to_data(&out, fl, &in));
+
+ cl_assert_equal_i(strlen(workdir_data), out.size);
+
+ cl_assert_equal_i(
+ 0, memcmp(workdir_data, out.ptr, out.size));
+
+ git_filter_list_free(fl);
+ git_buf_free(&out);
+}
+
+void test_filter_custom__can_register_a_custom_filter_in_the_repository(void)
+{
+ git_filter_list *fl;
+
+ cl_git_pass(git_filter_list_load(
+ &fl, g_repo, NULL, "herofile", GIT_FILTER_TO_WORKTREE));
+ /* expect: bitflip, reverse, crlf */
+ cl_assert_equal_sz(3, git_filter_list_length(fl));
+ git_filter_list_free(fl);
+
+ cl_git_pass(git_filter_list_load(
+ &fl, g_repo, NULL, "herocorp", GIT_FILTER_TO_WORKTREE));
+ /* expect: bitflip, reverse - possibly crlf depending on global config */
+ {
+ size_t flen = git_filter_list_length(fl);
+ cl_assert(flen == 2 || flen == 3);
+ }
+ git_filter_list_free(fl);
+
+ cl_git_pass(git_filter_list_load(
+ &fl, g_repo, NULL, "hero.bin", GIT_FILTER_TO_WORKTREE));
+ /* expect: bitflip, reverse */
+ cl_assert_equal_sz(2, git_filter_list_length(fl));
+ git_filter_list_free(fl);
+
+ cl_git_pass(git_filter_list_load(
+ &fl, g_repo, NULL, "heroflip", GIT_FILTER_TO_WORKTREE));
+ /* expect: bitflip (because of -reverse) */
+ cl_assert_equal_sz(1, git_filter_list_length(fl));
+ git_filter_list_free(fl);
+
+ cl_git_pass(git_filter_list_load(
+ &fl, g_repo, NULL, "doesntapplytome.bin", GIT_FILTER_TO_WORKTREE));
+ /* expect: none */
+ cl_assert_equal_sz(0, git_filter_list_length(fl));
+ git_filter_list_free(fl);
+}
+
+void test_filter_custom__order_dependency(void)
+{
+ git_index *index;
+ git_blob *blob;
+ git_buf buf = { 0 };
+
+ /* so if ident and reverse are used together, an interesting thing
+ * happens - a reversed "$Id$" string is no longer going to trigger
+ * ident correctly. When checking out, the filters should be applied
+ * in order CLRF, then ident, then reverse, so ident expansion should
+ * work correctly. On check in, the content should be reversed, then
+ * ident, then CRLF filtered. Let's make sure that works...
+ */
+
+ cl_git_mkfile(
+ "empty_standard_repo/.gitattributes",
+ "hero.*.rev-ident text ident prereverse eol=lf\n");
+
+ cl_git_mkfile(
+ "empty_standard_repo/hero.1.rev-ident",
+ "This is a test\n$Id$\nHave fun!\n");
+
+ cl_git_mkfile(
+ "empty_standard_repo/hero.2.rev-ident",
+ "Another test\n$dI$\nCrazy!\n");
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_git_pass(git_index_add_bypath(index, "hero.1.rev-ident"));
+ cl_git_pass(git_index_add_bypath(index, "hero.2.rev-ident"));
+ cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "Filter chains\n");
+ git_index_free(index);
+
+ cl_git_pass(git_blob_lookup(&blob, g_repo,
+ & git_index_get_bypath(index, "hero.1.rev-ident", 0)->oid));
+ cl_assert_equal_s(
+ "\n!nuf evaH\n$dI$\ntset a si sihT", git_blob_rawcontent(blob));
+ cl_git_pass(git_blob_filtered_content(&buf, blob, "hero.1.rev-ident", 0));
+ /* no expansion because id was reversed at checkin and now at ident
+ * time, reverse is not applied yet */
+ cl_assert_equal_s(
+ "This is a test\n$Id$\nHave fun!\n", buf.ptr);
+ git_blob_free(blob);
+
+ cl_git_pass(git_blob_lookup(&blob, g_repo,
+ & git_index_get_bypath(index, "hero.2.rev-ident", 0)->oid));
+ cl_assert_equal_s(
+ "\n!yzarC\n$Id$\ntset rehtonA", git_blob_rawcontent(blob));
+ cl_git_pass(git_blob_filtered_content(&buf, blob, "hero.2.rev-ident", 0));
+ /* expansion because reverse was applied at checkin and at ident time,
+ * reverse is not applied yet */
+ cl_assert_equal_s(
+ "Another test\n$59001fe193103b1016b27027c0c827d036fd0ac8 :dI$\nCrazy!\n", buf.ptr);
+ cl_assert_equal_i(0, git_oid_strcmp(
+ git_blob_id(blob), "8ca0df630d728c0c72072b6101b301391ef10095"));
+ git_blob_free(blob);
+
+ git_buf_free(&buf);
+}
+
+void test_filter_custom__filter_registry_failure_cases(void)
+{
+ git_filter fake = { GIT_FILTER_VERSION, 0 };
+
+ cl_assert_equal_i(GIT_EEXISTS, git_filter_register("bitflip", &fake, 0));
+
+ cl_git_fail(git_filter_unregister(GIT_FILTER_CRLF));
+ cl_git_fail(git_filter_unregister(GIT_FILTER_IDENT));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_filter_unregister("not-a-filter"));
+}
diff --git a/tests-clar/filter/ident.c b/tests-clar/filter/ident.c
new file mode 100644
index 000000000..2c8e6abea
--- /dev/null
+++ b/tests-clar/filter/ident.c
@@ -0,0 +1,131 @@
+#include "clar_libgit2.h"
+#include "git2/sys/filter.h"
+
+static git_repository *g_repo = NULL;
+
+void test_filter_ident__initialize(void)
+{
+ g_repo = cl_git_sandbox_init("crlf");
+}
+
+void test_filter_ident__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+static void add_blob_and_filter(
+ const char *data,
+ git_filter_list *fl,
+ const char *expected)
+{
+ git_oid id;
+ git_blob *blob;
+ git_buf out = { 0 };
+
+ cl_git_mkfile("crlf/identtest", data);
+ cl_git_pass(git_blob_create_fromworkdir(&id, g_repo, "identtest"));
+ cl_git_pass(git_blob_lookup(&blob, g_repo, &id));
+
+ cl_git_pass(git_filter_list_apply_to_blob(&out, fl, blob));
+
+ cl_assert_equal_s(expected, out.ptr);
+
+ git_blob_free(blob);
+ git_buf_free(&out);
+}
+
+void test_filter_ident__to_worktree(void)
+{
+ git_filter_list *fl;
+ git_filter *ident;
+
+ cl_git_pass(git_filter_list_new(&fl, g_repo, GIT_FILTER_TO_WORKTREE));
+
+ ident = git_filter_lookup(GIT_FILTER_IDENT);
+ cl_assert(ident != NULL);
+
+ cl_git_pass(git_filter_list_push(fl, ident, NULL));
+
+ add_blob_and_filter(
+ "Hello\n$Id$\nFun stuff\n", fl,
+ "Hello\n$Id: b69e2387aafcaf73c4de5b9ab59abe27fdadee30$\nFun stuff\n");
+ add_blob_and_filter(
+ "Hello\n$Id: Junky$\nFun stuff\n", fl,
+ "Hello\n$Id: 45cd107a7102911cb2a7df08404674327fa050b9$\nFun stuff\n");
+ add_blob_and_filter(
+ "$Id$\nAt the start\n", fl,
+ "$Id: b13415c767abc196fb95bd17070e8c1113e32160$\nAt the start\n");
+ add_blob_and_filter(
+ "At the end\n$Id$", fl,
+ "At the end\n$Id: 1344925c6bc65b34c5a7b50f86bf688e48e9a272$");
+ add_blob_and_filter(
+ "$Id$", fl,
+ "$Id: b3f5ebfb5843bc43ceecff6d4f26bb37c615beb1$");
+ add_blob_and_filter(
+ "$Id: Some sort of junk goes here$", fl,
+ "$Id: ab2dd3853c7c9a4bff55aca2bea077a73c32ac06$");
+
+ add_blob_and_filter("$Id: ", fl, "$Id: ");
+ add_blob_and_filter("$Id", fl, "$Id");
+ add_blob_and_filter("$I", fl, "$I");
+ add_blob_and_filter("Id$", fl, "Id$");
+
+ git_filter_list_free(fl);
+}
+
+void test_filter_ident__to_odb(void)
+{
+ git_filter_list *fl;
+ git_filter *ident;
+
+ cl_git_pass(git_filter_list_new(&fl, g_repo, GIT_FILTER_TO_ODB));
+
+ ident = git_filter_lookup(GIT_FILTER_IDENT);
+ cl_assert(ident != NULL);
+
+ cl_git_pass(git_filter_list_push(fl, ident, NULL));
+
+ add_blob_and_filter(
+ "Hello\n$Id$\nFun stuff\n",
+ fl, "Hello\n$Id$\nFun stuff\n");
+ add_blob_and_filter(
+ "Hello\n$Id: b69e2387aafcaf73c4de5b9ab59abe27fdadee30$\nFun stuff\n",
+ fl, "Hello\n$Id$\nFun stuff\n");
+ add_blob_and_filter(
+ "Hello\n$Id: Any junk you may have left here$\nFun stuff\n",
+ fl, "Hello\n$Id$\nFun stuff\n");
+ add_blob_and_filter(
+ "Hello\n$Id:$\nFun stuff\n",
+ fl, "Hello\n$Id$\nFun stuff\n");
+ add_blob_and_filter(
+ "Hello\n$Id:x$\nFun stuff\n",
+ fl, "Hello\n$Id$\nFun stuff\n");
+
+ add_blob_and_filter(
+ "$Id$\nAt the start\n", fl, "$Id$\nAt the start\n");
+ add_blob_and_filter(
+ "$Id: lots of random text that should be removed from here$\nAt the start\n", fl, "$Id$\nAt the start\n");
+ add_blob_and_filter(
+ "$Id: lots of random text that should not be removed without a terminator\nAt the start\n", fl, "$Id: lots of random text that should not be removed without a terminator\nAt the start\n");
+
+ add_blob_and_filter(
+ "At the end\n$Id$", fl, "At the end\n$Id$");
+ add_blob_and_filter(
+ "At the end\n$Id:$", fl, "At the end\n$Id$");
+ add_blob_and_filter(
+ "At the end\n$Id:asdfasdf$", fl, "At the end\n$Id$");
+ add_blob_and_filter(
+ "At the end\n$Id", fl, "At the end\n$Id");
+ add_blob_and_filter(
+ "At the end\n$IddI", fl, "At the end\n$IddI");
+
+ add_blob_and_filter("$Id$", fl, "$Id$");
+ add_blob_and_filter("$Id: any$", fl, "$Id$");
+ add_blob_and_filter("$Id: any long stuff goes here you see$", fl, "$Id$");
+ add_blob_and_filter("$Id: ", fl, "$Id: ");
+ add_blob_and_filter("$Id", fl, "$Id");
+ add_blob_and_filter("$I", fl, "$I");
+ add_blob_and_filter("Id$", fl, "Id$");
+
+ git_filter_list_free(fl);
+}
diff --git a/tests-clar/index/addall.c b/tests-clar/index/addall.c
index 00388ee00..f46a1e16c 100644
--- a/tests-clar/index/addall.c
+++ b/tests-clar/index/addall.c
@@ -120,37 +120,6 @@ static void check_stat_data(git_index *index, const char *path, bool match)
}
}
-static void commit_index_to_head(
- git_repository *repo,
- const char *commit_message)
-{
- git_index *index;
- git_oid tree_id, commit_id;
- git_tree *tree;
- git_signature *sig;
- git_commit *parent = NULL;
-
- git_revparse_single((git_object **)&parent, repo, "HEAD");
- /* it is okay if looking up the HEAD fails */
-
- cl_git_pass(git_repository_index(&index, repo));
- cl_git_pass(git_index_write_tree(&tree_id, index));
- cl_git_pass(git_index_write(index)); /* not needed, but might as well */
- git_index_free(index);
-
- cl_git_pass(git_tree_lookup(&tree, repo, &tree_id));
-
- cl_git_pass(git_signature_now(&sig, "Testy McTester", "tt@tester.test"));
-
- cl_git_pass(git_commit_create_v(
- &commit_id, repo, "HEAD", sig, sig,
- NULL, commit_message, tree, parent ? 1 : 0, parent));
-
- git_commit_free(parent);
- git_tree_free(tree);
- git_signature_free(sig);
-}
-
void test_index_addall__repo_lifecycle(void)
{
int error;
@@ -197,7 +166,7 @@ void test_index_addall__repo_lifecycle(void)
check_stat_data(index, "addall/file.zzz", true);
check_status(g_repo, 2, 0, 0, 3, 0, 0, 1);
- commit_index_to_head(g_repo, "first commit");
+ cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "first commit");
check_status(g_repo, 0, 0, 0, 3, 0, 0, 1);
/* attempt to add an ignored file - does nothing */
@@ -244,7 +213,7 @@ void test_index_addall__repo_lifecycle(void)
cl_git_pass(git_index_add_bypath(index, "file.zzz"));
check_status(g_repo, 1, 0, 1, 3, 0, 0, 0);
- commit_index_to_head(g_repo, "second commit");
+ cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "second commit");
check_status(g_repo, 0, 0, 0, 3, 0, 0, 0);
cl_must_pass(p_unlink("addall/file.zzz"));
diff --git a/tests-clar/index/filemodes.c b/tests-clar/index/filemodes.c
index e56a9c069..02f83efba 100644
--- a/tests-clar/index/filemodes.c
+++ b/tests-clar/index/filemodes.c
@@ -44,7 +44,8 @@ static void replace_file_with_mode(
cl_git_pass(p_rename(path.ptr, backup));
cl_git_write2file(
- path.ptr, content.ptr, O_WRONLY|O_CREAT|O_TRUNC, create_mode);
+ path.ptr, content.ptr, content.size,
+ O_WRONLY|O_CREAT|O_TRUNC, create_mode);
git_buf_free(&path);
git_buf_free(&content);
@@ -91,7 +92,7 @@ void test_index_filemodes__untrusted(void)
add_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB_EXECUTABLE);
/* 5 - add new 0644 -> expect 0644 */
- cl_git_write2file("filemodes/new_off", "blah",
+ cl_git_write2file("filemodes/new_off", "blah", 0,
O_WRONLY | O_CREAT | O_TRUNC, 0644);
add_and_check_mode(index, "new_off", GIT_FILEMODE_BLOB);
@@ -100,7 +101,7 @@ void test_index_filemodes__untrusted(void)
*/
if (can_filemode) {
/* 6 - add 0755 -> expect 0755 */
- cl_git_write2file("filemodes/new_on", "blah",
+ cl_git_write2file("filemodes/new_on", "blah", 0,
O_WRONLY | O_CREAT | O_TRUNC, 0755);
add_and_check_mode(index, "new_on", GIT_FILEMODE_BLOB_EXECUTABLE);
}
@@ -140,12 +141,12 @@ void test_index_filemodes__trusted(void)
add_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB_EXECUTABLE);
/* 5 - add new 0644 -> expect 0644 */
- cl_git_write2file("filemodes/new_off", "blah",
+ cl_git_write2file("filemodes/new_off", "blah", 0,
O_WRONLY | O_CREAT | O_TRUNC, 0644);
add_and_check_mode(index, "new_off", GIT_FILEMODE_BLOB);
/* 6 - add 0755 -> expect 0755 */
- cl_git_write2file("filemodes/new_on", "blah",
+ cl_git_write2file("filemodes/new_on", "blah", 0,
O_WRONLY | O_CREAT | O_TRUNC, 0755);
add_and_check_mode(index, "new_on", GIT_FILEMODE_BLOB_EXECUTABLE);
diff --git a/tests-clar/object/blob/filter.c b/tests-clar/object/blob/filter.c
index 2b3954d9c..0b2d6bf9e 100644
--- a/tests-clar/object/blob/filter.c
+++ b/tests-clar/object/blob/filter.c
@@ -1,13 +1,13 @@
#include "clar_libgit2.h"
#include "posix.h"
#include "blob.h"
-#include "filter.h"
#include "buf_text.h"
static git_repository *g_repo = NULL;
-#define NUM_TEST_OBJECTS 9
-static git_oid g_oids[NUM_TEST_OBJECTS];
-static const char *g_raw[NUM_TEST_OBJECTS] = {
+
+#define CRLF_NUM_TEST_OBJECTS 9
+
+static const char *g_crlf_raw[CRLF_NUM_TEST_OBJECTS] = {
"",
"foo\nbar\n",
"foo\rbar\r",
@@ -18,19 +18,14 @@ static const char *g_raw[NUM_TEST_OBJECTS] = {
"\xEF\xBB\xBF\xE3\x81\xBB\xE3\x81\x92\xE3\x81\xBB\xE3\x81\x92\r\n\xE3\x81\xBB\xE3\x81\x92\xE3\x81\xBB\xE3\x81\x92\r\n",
"\xFE\xFF\x00T\x00h\x00i\x00s\x00!"
};
-static git_off_t g_len[NUM_TEST_OBJECTS] = { -1, -1, -1, -1, -1, 17, -1, -1, 12 };
-static git_buf_text_stats g_stats[NUM_TEST_OBJECTS] = {
- { 0, 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 2, 0, 6, 0 },
- { 0, 0, 2, 0, 0, 6, 0 },
- { 0, 0, 2, 2, 2, 6, 0 },
- { 0, 0, 4, 4, 1, 31, 0 },
- { 0, 1, 1, 2, 1, 9, 5 },
- { GIT_BOM_UTF8, 0, 0, 1, 0, 16, 0 },
- { GIT_BOM_UTF8, 0, 2, 2, 2, 27, 0 },
- { GIT_BOM_UTF16_BE, 5, 0, 0, 0, 7, 5 },
+
+static git_off_t g_crlf_raw_len[CRLF_NUM_TEST_OBJECTS] = {
+ -1, -1, -1, -1, -1, 17, -1, -1, 12
};
-static git_buf g_crlf_filtered[NUM_TEST_OBJECTS] = {
+
+static git_oid g_crlf_oids[CRLF_NUM_TEST_OBJECTS];
+
+static git_buf g_crlf_filtered[CRLF_NUM_TEST_OBJECTS] = {
{ "", 0, 0 },
{ "foo\nbar\n", 0, 8 },
{ "foo\rbar\r", 0, 8 },
@@ -42,30 +37,36 @@ static git_buf g_crlf_filtered[NUM_TEST_OBJECTS] = {
{ "\xFE\xFF\x00T\x00h\x00i\x00s\x00!", 0, 12 }
};
+static git_buf_text_stats g_crlf_filtered_stats[CRLF_NUM_TEST_OBJECTS] = {
+ { 0, 0, 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 2, 0, 6, 0 },
+ { 0, 0, 2, 0, 0, 6, 0 },
+ { 0, 0, 2, 2, 2, 6, 0 },
+ { 0, 0, 4, 4, 1, 31, 0 },
+ { 0, 1, 1, 2, 1, 9, 5 },
+ { GIT_BOM_UTF8, 0, 0, 1, 0, 16, 0 },
+ { GIT_BOM_UTF8, 0, 2, 2, 2, 27, 0 },
+ { GIT_BOM_UTF16_BE, 5, 0, 0, 0, 7, 5 },
+};
+
void test_object_blob_filter__initialize(void)
{
int i;
- cl_fixture_sandbox("empty_standard_repo");
- cl_git_pass(p_rename(
- "empty_standard_repo/.gitted", "empty_standard_repo/.git"));
- cl_git_pass(git_repository_open(&g_repo, "empty_standard_repo"));
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
- for (i = 0; i < NUM_TEST_OBJECTS; i++) {
- size_t len = (g_len[i] < 0) ? strlen(g_raw[i]) : (size_t)g_len[i];
- g_len[i] = (git_off_t)len;
+ for (i = 0; i < CRLF_NUM_TEST_OBJECTS; i++) {
+ if (g_crlf_raw_len[i] < 0)
+ g_crlf_raw_len[i] = strlen(g_crlf_raw[i]);
- cl_git_pass(
- git_blob_create_frombuffer(&g_oids[i], g_repo, g_raw[i], len)
- );
+ cl_git_pass(git_blob_create_frombuffer(
+ &g_crlf_oids[i], g_repo, g_crlf_raw[i], (size_t)g_crlf_raw_len[i]));
}
}
void test_object_blob_filter__cleanup(void)
{
- git_repository_free(g_repo);
- g_repo = NULL;
- cl_fixture_cleanup("empty_standard_repo");
+ cl_git_sandbox_cleanup();
}
void test_object_blob_filter__unfiltered(void)
@@ -73,10 +74,15 @@ void test_object_blob_filter__unfiltered(void)
int i;
git_blob *blob;
- for (i = 0; i < NUM_TEST_OBJECTS; i++) {
- cl_git_pass(git_blob_lookup(&blob, g_repo, &g_oids[i]));
- cl_assert(g_len[i] == git_blob_rawsize(blob));
- cl_assert(memcmp(git_blob_rawcontent(blob), g_raw[i], (size_t)g_len[i]) == 0);
+ for (i = 0; i < CRLF_NUM_TEST_OBJECTS; i++) {
+ size_t raw_len = (size_t)g_crlf_raw_len[i];
+
+ cl_git_pass(git_blob_lookup(&blob, g_repo, &g_crlf_oids[i]));
+
+ cl_assert_equal_sz(raw_len, (size_t)git_blob_rawsize(blob));
+ cl_assert_equal_i(
+ 0, memcmp(g_crlf_raw[i], git_blob_rawcontent(blob), raw_len));
+
git_blob_free(blob);
}
}
@@ -88,11 +94,12 @@ void test_object_blob_filter__stats(void)
git_buf buf = GIT_BUF_INIT;
git_buf_text_stats stats;
- for (i = 0; i < NUM_TEST_OBJECTS; i++) {
- cl_git_pass(git_blob_lookup(&blob, g_repo, &g_oids[i]));
+ for (i = 0; i < CRLF_NUM_TEST_OBJECTS; i++) {
+ cl_git_pass(git_blob_lookup(&blob, g_repo, &g_crlf_oids[i]));
cl_git_pass(git_blob__getbuf(&buf, blob));
git_buf_text_gather_stats(&stats, &buf, false);
- cl_assert(memcmp(&g_stats[i], &stats, sizeof(stats)) == 0);
+ cl_assert_equal_i(
+ 0, memcmp(&g_crlf_filtered_stats[i], &stats, sizeof(stats)));
git_blob_free(blob);
}
@@ -101,11 +108,11 @@ void test_object_blob_filter__stats(void)
void test_object_blob_filter__to_odb(void)
{
- git_vector filters = GIT_VECTOR_INIT;
+ git_filter_list *fl = NULL;
git_config *cfg;
int i;
git_blob *blob;
- git_buf orig = GIT_BUF_INIT, out = GIT_BUF_INIT;
+ git_buf out = GIT_BUF_INIT;
cl_git_pass(git_repository_config(&cfg, g_repo));
cl_assert(cfg);
@@ -113,23 +120,24 @@ void test_object_blob_filter__to_odb(void)
git_attr_cache_flush(g_repo);
cl_git_append2file("empty_standard_repo/.gitattributes", "*.txt text\n");
- cl_assert(git_filters_load(
- &filters, g_repo, "filename.txt", GIT_FILTER_TO_ODB) > 0);
- cl_assert(filters.length == 1);
+ cl_git_pass(git_filter_list_load(
+ &fl, g_repo, NULL, "filename.txt", GIT_FILTER_TO_ODB));
+ cl_assert(fl != NULL);
- for (i = 0; i < NUM_TEST_OBJECTS; i++) {
- cl_git_pass(git_blob_lookup(&blob, g_repo, &g_oids[i]));
- cl_git_pass(git_blob__getbuf(&orig, blob));
+ for (i = 0; i < CRLF_NUM_TEST_OBJECTS; i++) {
+ cl_git_pass(git_blob_lookup(&blob, g_repo, &g_crlf_oids[i]));
- cl_git_pass(git_filters_apply(&out, &orig, &filters));
- cl_assert(git_buf_cmp(&out, &g_crlf_filtered[i]) == 0);
+ cl_git_pass(git_filter_list_apply_to_blob(&out, fl, blob));
+
+ cl_assert_equal_sz(g_crlf_filtered[i].size, out.size);
+
+ cl_assert_equal_i(
+ 0, memcmp(out.ptr, g_crlf_filtered[i].ptr, out.size));
git_blob_free(blob);
}
- git_filters_free(&filters);
- git_buf_free(&orig);
+ git_filter_list_free(fl);
git_buf_free(&out);
git_config_free(cfg);
}
-
diff --git a/tests-clar/online/clone.c b/tests-clar/online/clone.c
index bc4285a00..dc5aa4150 100644
--- a/tests-clar/online/clone.c
+++ b/tests-clar/online/clone.c
@@ -69,7 +69,7 @@ void test_online_clone__empty_repository(void)
cl_git_pass(git_clone(&g_repo, LIVE_EMPTYREPO_URL, "./foo", &g_options));
cl_assert_equal_i(true, git_repository_is_empty(g_repo));
- cl_assert_equal_i(true, git_repository_head_orphan(g_repo));
+ cl_assert_equal_i(true, git_repository_head_unborn(g_repo));
cl_git_pass(git_reference_lookup(&head, g_repo, GIT_HEAD_FILE));
cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head));
diff --git a/tests-clar/online/fetch.c b/tests-clar/online/fetch.c
index bfa1eb972..f76c6cff9 100644
--- a/tests-clar/online/fetch.c
+++ b/tests-clar/online/fetch.c
@@ -64,6 +64,11 @@ void test_online_fetch__default_http(void)
do_fetch("http://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_AUTO, 6);
}
+void test_online_fetch__default_https(void)
+{
+ do_fetch("https://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_AUTO, 6);
+}
+
void test_online_fetch__no_tags_git(void)
{
do_fetch("git://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_NONE, 3);
diff --git a/tests-clar/refs/branches/delete.c b/tests-clar/refs/branches/delete.c
index 7af5a3e86..de90cb734 100644
--- a/tests-clar/refs/branches/delete.c
+++ b/tests-clar/refs/branches/delete.c
@@ -57,11 +57,11 @@ void test_refs_branches_delete__can_delete_a_branch_even_if_HEAD_is_missing(void
git_reference_free(branch);
}
-void test_refs_branches_delete__can_delete_a_branch_when_HEAD_is_orphaned(void)
+void test_refs_branches_delete__can_delete_a_branch_when_HEAD_is_unborn(void)
{
git_reference *branch;
- make_head_orphaned(repo, NON_EXISTING_HEAD);
+ make_head_unborn(repo, NON_EXISTING_HEAD);
cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL));
cl_git_pass(git_branch_delete(branch));
diff --git a/tests-clar/refs/branches/ishead.c b/tests-clar/refs/branches/ishead.c
index dfcf1b5f1..b1ad09c3e 100644
--- a/tests-clar/refs/branches/ishead.c
+++ b/tests-clar/refs/branches/ishead.c
@@ -26,13 +26,13 @@ void test_refs_branches_ishead__can_tell_if_a_branch_is_pointed_at_by_HEAD(void)
cl_assert_equal_i(true, git_branch_is_head(branch));
}
-void test_refs_branches_ishead__can_properly_handle_orphaned_HEAD(void)
+void test_refs_branches_ishead__can_properly_handle_unborn_HEAD(void)
{
git_repository_free(repo);
repo = cl_git_sandbox_init("testrepo.git");
- make_head_orphaned(repo, NON_EXISTING_HEAD);
+ make_head_unborn(repo, NON_EXISTING_HEAD);
cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
diff --git a/tests-clar/repo/head.c b/tests-clar/repo/head.c
index a9f5cfc58..5a55984bd 100644
--- a/tests-clar/repo/head.c
+++ b/tests-clar/repo/head.c
@@ -32,20 +32,20 @@ void test_repo_head__head_detached(void)
cl_assert_equal_i(false, git_repository_head_detached(repo));
}
-void test_repo_head__head_orphan(void)
+void test_repo_head__unborn_head(void)
{
git_reference *ref;
cl_git_pass(git_repository_head_detached(repo));
- make_head_orphaned(repo, NON_EXISTING_HEAD);
+ make_head_unborn(repo, NON_EXISTING_HEAD);
- cl_assert(git_repository_head_orphan(repo) == 1);
+ cl_assert(git_repository_head_unborn(repo) == 1);
/* take the repo back to it's original state */
cl_git_pass(git_reference_symbolic_create(&ref, repo, "HEAD", "refs/heads/master", 1));
- cl_assert(git_repository_head_orphan(repo) == 0);
+ cl_assert(git_repository_head_unborn(repo) == 0);
git_reference_free(ref);
}
@@ -58,7 +58,7 @@ void test_repo_head__set_head_Attaches_HEAD_to_un_unborn_branch_when_the_branch_
cl_assert_equal_i(false, git_repository_head_detached(repo));
- cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_head(&head, repo));
+ cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_head(&head, repo));
}
void test_repo_head__set_head_Returns_ENOTFOUND_when_the_reference_doesnt_exist(void)
@@ -163,20 +163,20 @@ void test_repo_head__detach_head_Fails_if_HEAD_and_point_to_a_non_commitish(void
git_reference_free(head);
}
-void test_repo_head__detaching_an_orphaned_head_returns_GIT_EORPHANEDHEAD(void)
+void test_repo_head__detaching_an_unborn_branch_returns_GIT_EUNBORNBRANCH(void)
{
- make_head_orphaned(repo, NON_EXISTING_HEAD);
+ make_head_unborn(repo, NON_EXISTING_HEAD);
- cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_detach_head(repo));
+ cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_detach_head(repo));
}
-void test_repo_head__retrieving_an_orphaned_head_returns_GIT_EORPHANEDHEAD(void)
+void test_repo_head__retrieving_an_unborn_branch_returns_GIT_EUNBORNBRANCH(void)
{
git_reference *head;
- make_head_orphaned(repo, NON_EXISTING_HEAD);
+ make_head_unborn(repo, NON_EXISTING_HEAD);
- cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_head(&head, repo));
+ cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_head(&head, repo));
}
void test_repo_head__retrieving_a_missing_head_returns_GIT_ENOTFOUND(void)
@@ -188,9 +188,9 @@ void test_repo_head__retrieving_a_missing_head_returns_GIT_ENOTFOUND(void)
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_head(&head, repo));
}
-void test_repo_head__can_tell_if_an_orphaned_head_is_detached(void)
+void test_repo_head__can_tell_if_an_unborn_head_is_detached(void)
{
- make_head_orphaned(repo, NON_EXISTING_HEAD);
+ make_head_unborn(repo, NON_EXISTING_HEAD);
cl_assert_equal_i(false, git_repository_head_detached(repo));
}
diff --git a/tests-clar/repo/headtree.c b/tests-clar/repo/headtree.c
index 0e7fe93e5..e899ac399 100644
--- a/tests-clar/repo/headtree.c
+++ b/tests-clar/repo/headtree.c
@@ -36,13 +36,13 @@ void test_repo_headtree__can_retrieve_the_root_tree_from_a_non_detached_head(voi
cl_assert(git_oid_streq(git_tree_id(tree), "az"));
}
-void test_repo_headtree__when_head_is_orphaned_returns_EORPHANEDHEAD(void)
+void test_repo_headtree__when_head_is_unborn_returns_EUNBORNBRANCH(void)
{
- make_head_orphaned(repo, NON_EXISTING_HEAD);
+ make_head_unborn(repo, NON_EXISTING_HEAD);
- cl_assert_equal_i(true, git_repository_head_orphan(repo));
+ cl_assert_equal_i(true, git_repository_head_unborn(repo));
- cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_head_tree(&tree, repo));
+ cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_head_tree(&tree, repo));
}
void test_repo_headtree__when_head_is_missing_returns_ENOTFOUND(void)
diff --git a/tests-clar/repo/init.c b/tests-clar/repo/init.c
index e3fc112b3..392be205b 100644
--- a/tests-clar/repo/init.c
+++ b/tests-clar/repo/init.c
@@ -382,7 +382,7 @@ static void assert_hooks_match(
cl_git_pass(git_buf_joinpath(&actual, repo_dir, hook_path));
cl_git_pass(git_path_lstat(actual.ptr, &st));
- cl_assert_equal_sz(expected_st.st_size, st.st_size);
+ cl_assert(expected_st.st_size == st.st_size);
if (GIT_MODE_TYPE(expected_st.st_mode) != GIT_FILEMODE_LINK) {
mode_t expected_mode =
@@ -565,6 +565,11 @@ void test_repo_init__init_with_initial_commit(void)
cl_git_pass(git_index_add_bypath(index, "file.txt"));
cl_git_pass(git_index_write(index));
+ /* Intentionally not using cl_repo_commit_from_index here so this code
+ * can be used as an example of how an initial commit is typically
+ * made to a repository...
+ */
+
/* Make sure we're ready to use git_signature_default :-) */
{
git_config *cfg, *local;
diff --git a/tests-clar/repo/repo_helpers.c b/tests-clar/repo/repo_helpers.c
index 74902e439..3d477ff42 100644
--- a/tests-clar/repo/repo_helpers.c
+++ b/tests-clar/repo/repo_helpers.c
@@ -3,7 +3,7 @@
#include "repo_helpers.h"
#include "posix.h"
-void make_head_orphaned(git_repository* repo, const char *target)
+void make_head_unborn(git_repository* repo, const char *target)
{
git_reference *head;
diff --git a/tests-clar/repo/repo_helpers.h b/tests-clar/repo/repo_helpers.h
index 09b5cac84..6783d5701 100644
--- a/tests-clar/repo/repo_helpers.h
+++ b/tests-clar/repo/repo_helpers.h
@@ -2,5 +2,5 @@
#define NON_EXISTING_HEAD "refs/heads/hide/and/seek"
-extern void make_head_orphaned(git_repository* repo, const char *target);
+extern void make_head_unborn(git_repository* repo, const char *target);
extern void delete_head(git_repository* repo);
diff --git a/tests-clar/reset/soft.c b/tests-clar/reset/soft.c
index 884697c91..bd6fcc205 100644
--- a/tests-clar/reset/soft.c
+++ b/tests-clar/reset/soft.c
@@ -95,19 +95,19 @@ void test_reset_soft__cannot_reset_to_a_tag_not_pointing_at_a_commit(void)
cl_git_fail(git_reset(repo, target, GIT_RESET_SOFT));
}
-void test_reset_soft__resetting_against_an_orphaned_head_repo_makes_the_head_no_longer_orphaned(void)
+void test_reset_soft__resetting_against_an_unborn_head_repo_makes_the_head_no_longer_unborn(void)
{
git_reference *head;
retrieve_target_from_oid(&target, repo, KNOWN_COMMIT_IN_BARE_REPO);
- make_head_orphaned(repo, NON_EXISTING_HEAD);
+ make_head_unborn(repo, NON_EXISTING_HEAD);
- cl_assert_equal_i(true, git_repository_head_orphan(repo));
+ cl_assert_equal_i(true, git_repository_head_unborn(repo));
cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT));
- cl_assert_equal_i(false, git_repository_head_orphan(repo));
+ 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));
diff --git a/tests-clar/resources/config/config-include b/tests-clar/resources/config/config-include
new file mode 100644
index 000000000..6b5e79de7
--- /dev/null
+++ b/tests-clar/resources/config/config-include
@@ -0,0 +1,2 @@
+[include]
+ path = config-included
diff --git a/tests-clar/resources/config/config-included b/tests-clar/resources/config/config-included
new file mode 100644
index 000000000..089ca08a7
--- /dev/null
+++ b/tests-clar/resources/config/config-included
@@ -0,0 +1,2 @@
+[foo "bar"]
+ baz = huzzah
diff --git a/tests-clar/revwalk/mergebase.c b/tests-clar/revwalk/mergebase.c
index a2dbbc738..2d01647fd 100644
--- a/tests-clar/revwalk/mergebase.c
+++ b/tests-clar/revwalk/mergebase.c
@@ -172,9 +172,9 @@ static void assert_mergebase_many(const char *expected_sha, int count, ...)
va_end(ap);
if (expected_sha == NULL)
- cl_assert_equal_i(GIT_ENOTFOUND, git_merge_base_many(&oid, _repo, oids, count));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_merge_base_many(&oid, _repo, count, oids));
else {
- cl_git_pass(git_merge_base_many(&oid, _repo, oids, count));
+ cl_git_pass(git_merge_base_many(&oid, _repo, count, oids));
cl_git_pass(git_oid_fromstr(&expected, expected_sha));
cl_assert(git_oid_cmp(&expected, &oid) == 0);
diff --git a/tests-clar/revwalk/simplify.c b/tests-clar/revwalk/simplify.c
index c94952105..81c19d366 100644
--- a/tests-clar/revwalk/simplify.c
+++ b/tests-clar/revwalk/simplify.c
@@ -1,5 +1,10 @@
#include "clar_libgit2.h"
+void test_revwalk_simplify__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
/*
* a4a7dce [0] Merge branch 'master' into br2
|\
@@ -47,5 +52,4 @@ void test_revwalk_simplify__first_parent(void)
cl_assert_equal_i(error, GIT_ITEROVER);
git_revwalk_free(walk);
- git_repository_free(repo);
}
diff --git a/tests-clar/stash/drop.c b/tests-clar/stash/drop.c
index 60b3c72e0..59413f01e 100644
--- a/tests-clar/stash/drop.c
+++ b/tests-clar/stash/drop.c
@@ -36,25 +36,27 @@ static void push_three_states(void)
cl_git_mkfile("stash/zero.txt", "content\n");
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_add_bypath(index, "zero.txt"));
- commit_staged_files(&oid, index, signature);
+ cl_repo_commit_from_index(NULL, repo, signature, 0, "Initial commit");
cl_assert(git_path_exists("stash/zero.txt"));
+ git_index_free(index);
cl_git_mkfile("stash/one.txt", "content\n");
- cl_git_pass(git_stash_save(&oid, repo, signature, "First", GIT_STASH_INCLUDE_UNTRACKED));
+ cl_git_pass(git_stash_save(
+ &oid, repo, signature, "First", GIT_STASH_INCLUDE_UNTRACKED));
cl_assert(!git_path_exists("stash/one.txt"));
cl_assert(git_path_exists("stash/zero.txt"));
cl_git_mkfile("stash/two.txt", "content\n");
- cl_git_pass(git_stash_save(&oid, repo, signature, "Second", GIT_STASH_INCLUDE_UNTRACKED));
+ cl_git_pass(git_stash_save(
+ &oid, repo, signature, "Second", GIT_STASH_INCLUDE_UNTRACKED));
cl_assert(!git_path_exists("stash/two.txt"));
cl_assert(git_path_exists("stash/zero.txt"));
cl_git_mkfile("stash/three.txt", "content\n");
- cl_git_pass(git_stash_save(&oid, repo, signature, "Third", GIT_STASH_INCLUDE_UNTRACKED));
+ cl_git_pass(git_stash_save(
+ &oid, repo, signature, "Third", GIT_STASH_INCLUDE_UNTRACKED));
cl_assert(!git_path_exists("stash/three.txt"));
cl_assert(git_path_exists("stash/zero.txt"));
-
- git_index_free(index);
}
void test_stash_drop__cannot_drop_a_non_existing_stashed_state(void)
@@ -160,7 +162,7 @@ void test_stash_drop__dropping_the_top_stash_updates_the_stash_reference(void)
retrieve_top_stash_id(&oid);
cl_git_pass(git_revparse_single(&next_top_stash, repo, "stash@{1}"));
- cl_assert_equal_i(false, git_oid_cmp(&oid, git_object_id(next_top_stash)) == 0);
+ cl_assert(git_oid_cmp(&oid, git_object_id(next_top_stash)) != 0);
cl_git_pass(git_stash_drop(repo, 0));
diff --git a/tests-clar/stash/save.c b/tests-clar/stash/save.c
index eae116ac5..035b62279 100644
--- a/tests-clar/stash/save.c
+++ b/tests-clar/stash/save.c
@@ -194,7 +194,7 @@ void test_stash_save__cannot_stash_against_an_unborn_branch(void)
cl_git_pass(git_reference_symbolic_create(&head, repo, "HEAD", "refs/heads/unborn", 1));
- cl_assert_equal_i(GIT_EORPHANEDHEAD,
+ cl_assert_equal_i(GIT_EUNBORNBRANCH,
git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT));
git_reference_free(head);
@@ -241,7 +241,7 @@ void test_stash_save__stashing_updates_the_reflog(void)
void test_stash_save__cannot_stash_when_there_are_no_local_change(void)
{
git_index *index;
- git_oid commit_oid, stash_tip_oid;
+ git_oid stash_tip_oid;
cl_git_pass(git_repository_index(&index, repo));
@@ -251,8 +251,7 @@ void test_stash_save__cannot_stash_when_there_are_no_local_change(void)
*/
cl_git_pass(git_index_add_bypath(index, "what"));
cl_git_pass(git_index_add_bypath(index, "who"));
- cl_git_pass(git_index_write(index));
- commit_staged_files(&commit_oid, index, signature);
+ cl_repo_commit_from_index(NULL, repo, signature, 0, "Initial commit");
git_index_free(index);
cl_assert_equal_i(GIT_ENOTFOUND,
diff --git a/tests-clar/stash/stash_helpers.c b/tests-clar/stash/stash_helpers.c
index f462a1351..06b63f177 100644
--- a/tests-clar/stash/stash_helpers.c
+++ b/tests-clar/stash/stash_helpers.c
@@ -2,38 +2,8 @@
#include "fileops.h"
#include "stash_helpers.h"
-void commit_staged_files(
- git_oid *commit_oid,
- git_index *index,
- git_signature *signature)
-{
- git_tree *tree;
- git_oid tree_oid;
- git_repository *repo;
-
- repo = git_index_owner(index);
-
- cl_git_pass(git_index_write_tree(&tree_oid, index));
-
- cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid));
-
- cl_git_pass(git_commit_create_v(
- commit_oid,
- repo,
- "HEAD",
- signature,
- signature,
- NULL,
- "Initial commit",
- tree,
- 0));
-
- git_tree_free(tree);
-}
-
void setup_stash(git_repository *repo, git_signature *signature)
{
- git_oid commit_oid;
git_index *index;
cl_git_pass(git_repository_index(&index, repo));
@@ -50,9 +20,8 @@ void setup_stash(git_repository *repo, git_signature *signature)
cl_git_pass(git_index_add_bypath(index, "how"));
cl_git_pass(git_index_add_bypath(index, "who"));
cl_git_pass(git_index_add_bypath(index, ".gitignore"));
- cl_git_pass(git_index_write(index));
- commit_staged_files(&commit_oid, index, signature);
+ cl_repo_commit_from_index(NULL, repo, signature, 0, "Initial commit");
cl_git_rewritefile("stash/what", "goodbye\n"); /* dd7e1c6f0fefe118f0b63d9f10908c460aa317a6 */
cl_git_rewritefile("stash/how", "not so small and\n"); /* e6d64adb2c7f3eb8feb493b556cc8070dca379a3 */
diff --git a/tests-clar/stash/stash_helpers.h b/tests-clar/stash/stash_helpers.h
index bb7fec4f5..7c3e13de3 100644
--- a/tests-clar/stash/stash_helpers.h
+++ b/tests-clar/stash/stash_helpers.h
@@ -1,8 +1,3 @@
void setup_stash(
git_repository *repo,
git_signature *signature);
-
-void commit_staged_files(
- git_oid *commit_oid,
- git_index *index,
- git_signature *signature); \ No newline at end of file
diff --git a/tests-clar/status/renames.c b/tests-clar/status/renames.c
index d72e563bf..de84a574d 100644
--- a/tests-clar/status/renames.c
+++ b/tests-clar/status/renames.c
@@ -11,6 +11,8 @@ static git_repository *g_repo = NULL;
void test_status_renames__initialize(void)
{
g_repo = cl_git_sandbox_init("renames");
+
+ cl_repo_set_bool(g_repo, "core.autocrlf", false);
}
void test_status_renames__cleanup(void)
@@ -67,7 +69,7 @@ static void test_status(
actual = git_status_byindex(status_list, i);
expected = &expected_list[i];
- cl_assert_equal_i((int)expected->status, (int)actual->status);
+ cl_assert_equal_i_fmt(expected->status, actual->status, "%04x");
oldname = actual->head_to_index ? actual->head_to_index->old_file.path :
actual->index_to_workdir ? actual->index_to_workdir->old_file.path : NULL;
diff --git a/tests-clar/status/submodules.c b/tests-clar/status/submodules.c
index 7bfef503f..ef2888f7d 100644
--- a/tests-clar/status/submodules.c
+++ b/tests-clar/status/submodules.c
@@ -13,7 +13,6 @@ void test_status_submodules__initialize(void)
void test_status_submodules__cleanup(void)
{
- cleanup_fixture_submodules();
}
void test_status_submodules__api(void)
diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c
index be7398cb6..135a95871 100644
--- a/tests-clar/status/worktree.c
+++ b/tests-clar/status/worktree.c
@@ -632,35 +632,12 @@ void test_status_worktree__conflicted_item(void)
static void stage_and_commit(git_repository *repo, const char *path)
{
- git_oid tree_oid, commit_oid;
- git_tree *tree;
- git_signature *signature;
git_index *index;
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_add_bypath(index, path));
- cl_git_pass(git_index_write(index));
-
- cl_git_pass(git_index_write_tree(&tree_oid, index));
+ cl_repo_commit_from_index(NULL, repo, NULL, 1323847743, "Initial commit\n");
git_index_free(index);
-
- cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid));
-
- cl_git_pass(git_signature_new(&signature, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60));
-
- cl_git_pass(git_commit_create_v(
- &commit_oid,
- repo,
- "HEAD",
- signature,
- signature,
- NULL,
- "Initial commit\n\0",
- tree,
- 0));
-
- git_tree_free(tree);
- git_signature_free(signature);
}
static void assert_ignore_case(
diff --git a/tests-clar/stress/diff.c b/tests-clar/stress/diff.c
index 0524aa108..1d319738e 100644
--- a/tests-clar/stress/diff.c
+++ b/tests-clar/stress/diff.c
@@ -54,27 +54,9 @@ static void test_with_many(int expected_new)
git_diff_list_free(diff);
- {
- git_object *parent;
- git_signature *sig;
- git_oid tree_id, commit_id;
- git_reference *ref;
-
- cl_git_pass(git_index_write_tree(&tree_id, index));
- cl_git_pass(git_tree_lookup(&new_tree, g_repo, &tree_id));
-
- cl_git_pass(git_revparse_ext(&parent, &ref, g_repo, "HEAD"));
- cl_git_pass(git_signature_new(
- &sig, "Sm Test", "sm@tester.test", 1372350000, 480));
-
- cl_git_pass(git_commit_create_v(
- &commit_id, g_repo, git_reference_name(ref), sig, sig,
- NULL, "yoyoyo", new_tree, 1, parent));
-
- git_object_free(parent);
- git_reference_free(ref);
- git_signature_free(sig);
- }
+ cl_repo_commit_from_index(NULL, g_repo, NULL, 1372350000, "yoyoyo");
+ cl_git_pass(git_revparse_single(
+ (git_object **)&new_tree, g_repo, "HEAD^{tree}"));
cl_git_pass(git_diff_tree_to_tree(
&diff, g_repo, tree, new_tree, &diffopts));
diff --git a/tests-clar/submodule/lookup.c b/tests-clar/submodule/lookup.c
index 013bbdf96..b626cdf04 100644
--- a/tests-clar/submodule/lookup.c
+++ b/tests-clar/submodule/lookup.c
@@ -114,15 +114,15 @@ void test_submodule_lookup__foreach(void)
cl_assert_equal_i(8, data.count);
}
-void test_submodule_lookup__lookup_even_with_orphaned_head(void)
+void test_submodule_lookup__lookup_even_with_unborn_head(void)
{
- git_reference *orphan;
+ git_reference *head;
git_submodule *sm;
- /* orphan the head */
+ /* put us on an unborn branch */
cl_git_pass(git_reference_symbolic_create(
- &orphan, g_repo, "HEAD", "refs/heads/garbage", 1));
- git_reference_free(orphan);
+ &head, g_repo, "HEAD", "refs/heads/garbage", 1));
+ git_reference_free(head);
/* lookup existing */
cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
diff --git a/tests-clar/submodule/status.c b/tests-clar/submodule/status.c
index 7b29ac288..f1227a575 100644
--- a/tests-clar/submodule/status.c
+++ b/tests-clar/submodule/status.c
@@ -14,7 +14,6 @@ void test_submodule_status__initialize(void)
void test_submodule_status__cleanup(void)
{
- cleanup_fixture_submodules();
}
void test_submodule_status__unchanged(void)
diff --git a/tests-clar/submodule/submodule_helpers.c b/tests-clar/submodule/submodule_helpers.c
index a7807522b..3e79c77fd 100644
--- a/tests-clar/submodule/submodule_helpers.c
+++ b/tests-clar/submodule/submodule_helpers.c
@@ -83,6 +83,14 @@ void rewrite_gitmodules(const char *workdir)
git_buf_free(&path);
}
+static void cleanup_fixture_submodules(void *payload)
+{
+ cl_git_sandbox_cleanup(); /* either "submodules" or "submod2" */
+
+ if (payload)
+ cl_fixture_cleanup(payload);
+}
+
git_repository *setup_fixture_submodules(void)
{
git_repository *repo = cl_git_sandbox_init("submodules");
@@ -92,6 +100,8 @@ git_repository *setup_fixture_submodules(void)
rewrite_gitmodules(git_repository_workdir(repo));
p_rename("submodules/testrepo/.gitted", "submodules/testrepo/.git");
+ cl_set_cleanup(cleanup_fixture_submodules, "testrepo.git");
+
return repo;
}
@@ -106,14 +116,7 @@ git_repository *setup_fixture_submod2(void)
p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git");
p_rename("submod2/not/.gitted", "submod2/not/.git");
- return repo;
-}
+ cl_set_cleanup(cleanup_fixture_submodules, "submod2_target");
-void cleanup_fixture_submodules(void)
-{
- cl_git_sandbox_cleanup();
-
- /* just try to clean up both possible extras */
- cl_fixture_cleanup("testrepo.git");
- cl_fixture_cleanup("submod2_target");
+ return repo;
}
diff --git a/tests-clar/submodule/submodule_helpers.h b/tests-clar/submodule/submodule_helpers.h
index 1de15ca17..610c40720 100644
--- a/tests-clar/submodule/submodule_helpers.h
+++ b/tests-clar/submodule/submodule_helpers.h
@@ -1,5 +1,5 @@
extern void rewrite_gitmodules(const char *workdir);
+/* these will automatically set a cleanup callback */
extern git_repository *setup_fixture_submodules(void);
extern git_repository *setup_fixture_submod2(void);
-extern void cleanup_fixture_submodules(void);
diff --git a/tests-clar/valgrind-supp-mac.txt b/tests-clar/valgrind-supp-mac.txt
index fcc7ede86..99833d091 100644
--- a/tests-clar/valgrind-supp-mac.txt
+++ b/tests-clar/valgrind-supp-mac.txt
@@ -154,3 +154,31 @@
fun:printf
fun:clar_print_init
}
+{
+ molo-1
+ Memcheck:Leak
+ fun:malloc_zone_malloc
+ ...
+ fun:_objc_init
+}
+{
+ molo-2
+ Memcheck:Leak
+ fun:malloc_zone_calloc
+ ...
+ fun:_objc_init
+}
+{
+ molo-3
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:_objc_init
+}
+{
+ molo-4
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:dyld_register_image_state_change_handler
+}