Example #1
0
void test_attr_repo__get_many(void)
{
	const char *names[4] = { "repoattr", "rootattr", "missingattr", "subattr" };
	const char *values[4];

	cl_git_pass(git_attr_get_many(g_repo, "root_test1", 4, names, values));

	cl_assert(values[0] == GIT_ATTR_TRUE);
	cl_assert(values[1] == GIT_ATTR_TRUE);
	cl_assert(values[2] == NULL);
	cl_assert(values[3] == NULL);

	cl_git_pass(git_attr_get_many(g_repo, "root_test2", 4, names, values));

	cl_assert(values[0] == GIT_ATTR_TRUE);
	cl_assert(values[1] == GIT_ATTR_FALSE);
	cl_assert(values[2] == NULL);
	cl_assert(values[3] == NULL);

	cl_git_pass(git_attr_get_many(g_repo, "sub/subdir_test1", 4, names, values));

	cl_assert(values[0] == GIT_ATTR_TRUE);
	cl_assert(values[1] == GIT_ATTR_TRUE);
	cl_assert(values[2] == NULL);
	cl_assert_strequal("yes", values[3]);

}
Example #2
0
void test_attr_repo__macros(void)
{
	const char *names[5] = { "rootattr", "binary", "diff", "crlf", "frotz" };
	const char *names2[5] = { "mymacro", "positive", "negative", "rootattr", "another" };
	const char *names3[3] = { "macro2", "multi2", "multi3" };
	const char *values[5];

	cl_git_pass(git_attr_get_many(g_repo, "binfile", 5, names, values));

	cl_assert(values[0] == GIT_ATTR_TRUE);
	cl_assert(values[1] == GIT_ATTR_TRUE);
	cl_assert(values[2] == GIT_ATTR_FALSE);
	cl_assert(values[3] == GIT_ATTR_FALSE);
	cl_assert(values[4] == NULL);

	cl_git_pass(git_attr_get_many(g_repo, "macro_test", 5, names2, values));

	cl_assert(values[0] == GIT_ATTR_TRUE);
	cl_assert(values[1] == GIT_ATTR_TRUE);
	cl_assert(values[2] == GIT_ATTR_FALSE);
	cl_assert(values[3] == NULL);
	cl_assert_strequal("77", values[4]);

	cl_git_pass(git_attr_get_many(g_repo, "macro_test", 3, names3, values));

	cl_assert(values[0] == GIT_ATTR_TRUE);
	cl_assert(values[1] == GIT_ATTR_FALSE);
	cl_assert_strequal("answer", values[2]);
}
Example #3
0
void test_attr_repo__get_many(void)
{
	const char *names[4] = { "repoattr", "rootattr", "missingattr", "subattr" };
	const char *values[4];

	cl_git_pass(git_attr_get_many(values, g_repo, 0, "root_test1", 4, names));

	cl_assert(GIT_ATTR_TRUE(values[0]));
	cl_assert(GIT_ATTR_TRUE(values[1]));
	cl_assert(GIT_ATTR_UNSPECIFIED(values[2]));
	cl_assert(GIT_ATTR_UNSPECIFIED(values[3]));

	cl_git_pass(git_attr_get_many(values, g_repo, 0, "root_test2", 4, names));

	cl_assert(GIT_ATTR_TRUE(values[0]));
	cl_assert(GIT_ATTR_FALSE(values[1]));
	cl_assert(GIT_ATTR_UNSPECIFIED(values[2]));
	cl_assert(GIT_ATTR_UNSPECIFIED(values[3]));

	cl_git_pass(git_attr_get_many(values, g_repo, 0, "sub/subdir_test1", 4, names));

	cl_assert(GIT_ATTR_TRUE(values[0]));
	cl_assert(GIT_ATTR_TRUE(values[1]));
	cl_assert(GIT_ATTR_UNSPECIFIED(values[2]));
	cl_assert_equal_s("yes", values[3]);
}
Example #4
0
void test_attr_repo__macros(void)
{
	const char *names[5] = { "rootattr", "binary", "diff", "crlf", "frotz" };
	const char *names2[5] = { "mymacro", "positive", "negative", "rootattr", "another" };
	const char *names3[3] = { "macro2", "multi2", "multi3" };
	const char *values[5];

	cl_git_pass(git_attr_get_many(values, g_repo, 0, "binfile", 5, names));

	cl_assert(GIT_ATTR_TRUE(values[0]));
	cl_assert(GIT_ATTR_TRUE(values[1]));
	cl_assert(GIT_ATTR_FALSE(values[2]));
	cl_assert(GIT_ATTR_FALSE(values[3]));
	cl_assert(GIT_ATTR_UNSPECIFIED(values[4]));

	cl_git_pass(git_attr_get_many(values, g_repo, 0, "macro_test", 5, names2));

	cl_assert(GIT_ATTR_TRUE(values[0]));
	cl_assert(GIT_ATTR_TRUE(values[1]));
	cl_assert(GIT_ATTR_FALSE(values[2]));
	cl_assert(GIT_ATTR_UNSPECIFIED(values[3]));
	cl_assert_equal_s("77", values[4]);

	cl_git_pass(git_attr_get_many(values, g_repo, 0, "macro_test", 3, names3));

	cl_assert(GIT_ATTR_TRUE(values[0]));
	cl_assert(GIT_ATTR_FALSE(values[1]));
	cl_assert_equal_s("answer", values[2]);
}
Example #5
0
File: crlf.c Project: 0CV0/libgit2
static int crlf_load_attributes(struct crlf_attrs *ca, git_repository *repo, const char *path)
{
#define NUM_CONV_ATTRS 3

	static const char *attr_names[NUM_CONV_ATTRS] = {
		"crlf", "eol", "text",
	};

	const char *attr_vals[NUM_CONV_ATTRS];
	int error;

	error = git_attr_get_many(attr_vals,
		repo, 0, path, NUM_CONV_ATTRS, attr_names);

	if (error == GIT_ENOTFOUND) {
		ca->crlf_action = GIT_CRLF_GUESS;
		ca->eol = GIT_EOL_UNSET;
		return 0;
	}

	if (error == 0) {
		ca->crlf_action = check_crlf(attr_vals[2]); /* text */
		if (ca->crlf_action == GIT_CRLF_GUESS)
			ca->crlf_action = check_crlf(attr_vals[0]); /* clrf */

		ca->eol = check_eol(attr_vals[1]); /* eol */
		return 0;
	}

	return -1;
}
Example #6
0
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]);
}
Example #7
0
void test_attr_repo__bad_macros(void)
{
    const char *names[6] = { "rootattr", "positive", "negative",
                             "firstmacro", "secondmacro", "thirdmacro"
                           };
    const char *values[6];

    cl_git_pass(git_attr_get_many(values, g_repo, 0, "macro_bad", 6, names));

    /* these three just confirm that the "mymacro" rule ran */
    cl_assert(GIT_ATTR_UNSPECIFIED(values[0]));
    cl_assert(GIT_ATTR_TRUE(values[1]));
    cl_assert(GIT_ATTR_FALSE(values[2]));

    /* file contains:
     *     # let's try some malicious macro defs
     *     [attr]firstmacro -thirdmacro -secondmacro
     *     [attr]secondmacro firstmacro -firstmacro
     *     [attr]thirdmacro secondmacro=hahaha -firstmacro
     *     macro_bad firstmacro secondmacro thirdmacro
     *
     * firstmacro assignment list ends up with:
     *     -thirdmacro -secondmacro
     * secondmacro assignment list expands "firstmacro" and ends up with:
     *     -thirdmacro -secondmacro -firstmacro
     * thirdmacro assignment don't expand so list ends up with:
     *     secondmacro="hahaha"
     *
     * macro_bad assignment list ends up with:
     *     -thirdmacro -secondmacro firstmacro &&
     *     -thirdmacro -secondmacro -firstmacro secondmacro &&
     *     secondmacro="hahaha" thirdmacro
     *
     * so summary results should be:
     *     -firstmacro secondmacro="hahaha" thirdmacro
     */
    cl_assert(GIT_ATTR_FALSE(values[3]));
    cl_assert_equal_s("hahaha", values[4]);
    cl_assert(GIT_ATTR_TRUE(values[5]));
}