Пример #1
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]);
}
Пример #2
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]);
}
Пример #3
0
static int filter_check(
	git_filter				*self,
	void					**payload, /* points to NULL ptr on entry, may be set */
	const git_filter_source	*src,
	const char				**attr_values)
{
	GIT_UNUSED(self);
	GIT_UNUSED(src);

	if (GIT_ATTR_UNSPECIFIED(attr_values[0]))
		return GIT_PASSTHROUGH;

	if (GIT_ATTR_FALSE(attr_values[0]))
		return GIT_PASSTHROUGH;

	if (GIT_ATTR_TRUE(attr_values[0]))
		return GIT_PASSTHROUGH;
	
	*payload = git__strdup(attr_values[0]);
	if (!*payload)
	{
		giterr_set_oom();
		return -1;
	}

	return 0;
}
Пример #4
0
int git_diff_driver_lookup(
	git_diff_driver **out, git_repository *repo, const char *path)
{
	int error = 0;
	const char *value;

	assert(out);
	*out = NULL;

	if (!repo || !path || !strlen(path))
		/* just use the auto value */;
	else if ((error = git_attr_get(&value, repo, 0, path, "diff")) < 0)
		/* return error below */;
	else if (GIT_ATTR_UNSPECIFIED(value))
		/* just use the auto value */;
	else if (GIT_ATTR_FALSE(value))
		*out = &global_drivers[DIFF_DRIVER_BINARY];
	else if (GIT_ATTR_TRUE(value))
		*out = &global_drivers[DIFF_DRIVER_TEXT];

	/* otherwise look for driver information in config and build driver */
	else if ((error = git_diff_driver_load(out, repo, value)) < 0) {
		if (error == GIT_ENOTFOUND) {
			error = 0;
			giterr_clear();
		}
	}

	if (!*out)
		*out = &global_drivers[DIFF_DRIVER_AUTO];

	return error;
}
Пример #5
0
void test_attr_repo__manpage_example(void)
{
	const char *value;

	cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "foo"));
	cl_assert(GIT_ATTR_TRUE(value));

	cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "bar"));
	cl_assert(GIT_ATTR_UNSPECIFIED(value));

	cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "baz"));
	cl_assert(GIT_ATTR_FALSE(value));

	cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "merge"));
	cl_assert_equal_s("filfre", value);

	cl_git_pass(git_attr_get(&value, g_repo, 0, "sub/abc", "frotz"));
	cl_assert(GIT_ATTR_UNSPECIFIED(value));
}
Пример #6
0
static int check_eol(const char *value)
{
	if (GIT_ATTR_UNSPECIFIED(value))
		return GIT_EOL_UNSET;

	if (strcmp(value, "lf") == 0)
		return GIT_EOL_LF;

	if (strcmp(value, "crlf") == 0)
		return GIT_EOL_CRLF;

	return GIT_EOL_UNSET;
}
Пример #7
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]);
}
Пример #8
0
static int check_crlf(const char *value)
{
	if (GIT_ATTR_TRUE(value))
		return GIT_CRLF_TEXT;

	if (GIT_ATTR_FALSE(value))
		return GIT_CRLF_BINARY;

	if (GIT_ATTR_UNSPECIFIED(value))
		return GIT_CRLF_GUESS;

	if (strcmp(value, "input") == 0)
		return GIT_CRLF_INPUT;

	if (strcmp(value, "auto") == 0)
		return GIT_CRLF_AUTO;

	return GIT_CRLF_GUESS;
}
Пример #9
0
void test_attr_file__check_attr_examples(void)
{
	git_attr_file *file;
	git_attr_rule *rule;
	git_attr_assignment *assign;

	cl_git_pass(git_attr_file__new_and_load(&file, cl_fixture("attr/attr3")));
	cl_assert_equal_s(cl_fixture("attr/attr3"), file->key + 2);
	cl_assert(file->rules.length == 3);

	rule = get_rule(0);
	cl_assert_equal_s("*.java", rule->match.pattern);
	cl_assert(rule->assigns.length == 3);
	assign = git_attr_rule__lookup_assignment(rule, "diff");
	cl_assert_equal_s("diff", assign->name);
	cl_assert_equal_s("java", assign->value);
	assign = git_attr_rule__lookup_assignment(rule, "crlf");
	cl_assert_equal_s("crlf", assign->name);
	cl_assert(GIT_ATTR_FALSE(assign->value));
	assign = git_attr_rule__lookup_assignment(rule, "myAttr");
	cl_assert_equal_s("myAttr", assign->name);
	cl_assert(GIT_ATTR_TRUE(assign->value));
	assign = git_attr_rule__lookup_assignment(rule, "missing");
	cl_assert(assign == NULL);

	rule = get_rule(1);
	cl_assert_equal_s("NoMyAttr.java", rule->match.pattern);
	cl_assert(rule->assigns.length == 1);
	assign = get_assign(rule, 0);
	cl_assert_equal_s("myAttr", assign->name);
	cl_assert(GIT_ATTR_UNSPECIFIED(assign->value));

	rule = get_rule(2);
	cl_assert_equal_s("README", rule->match.pattern);
	cl_assert(rule->assigns.length == 1);
	assign = get_assign(rule, 0);
	cl_assert_equal_s("caveat", assign->name);
	cl_assert_equal_s("unspecified", assign->value);

	git_attr_file__free(file);
}
Пример #10
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]));
}