Exemplo n.º 1
0
void test_merge_driver__shutdown_is_called(void)
{
    test_driver_custom.initialized = 0;
    test_driver_custom.shutdown = 0;
    test_driver_wildcard.initialized = 0;
    test_driver_wildcard.shutdown = 0;
    
    /* run the merge with the custom driver */
    set_gitattributes_to("custom");
    merge_branch();
    
	/* unregister the drivers, ensure their shutdown function is called */
	test_drivers_unregister();

    /* since the `custom` driver was used, it should have been initialized and
     * shutdown, but the wildcard driver was not used at all and should not
     * have been initialized or shutdown.
     */
	cl_assert(test_driver_custom.initialized);
	cl_assert(test_driver_custom.shutdown);
	cl_assert(!test_driver_wildcard.initialized);
	cl_assert(!test_driver_wildcard.shutdown);

	test_drivers_register();
}
Exemplo n.º 2
0
static int merge_differently_filtered_files(char *files[])
{
	git_reference *head;
	git_object *head_object;
	int error;

	cl_git_pass(git_repository_head(&head, repo));
	cl_git_pass(git_reference_peel(&head_object, head, GIT_OBJ_COMMIT));
	cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL));

	/* Emulate checkout with a broken or misconfigured filter:  modify some
	 * files on-disk and then update the index with the updated file size
	 * and time, as if some filter applied them.  These files should not be
	 * treated as dirty since we created them.
	 *
	 * (Make sure to update the index stamp to defeat racy-git protections
	 * trying to sanity check the files in the index; those would rehash the
	 * files, showing them as dirty, the exact mechanism we're trying to avoid.)
	 */

	write_files(files);
	hack_index(files);

	cl_git_pass(git_index_write(repo_index));

	error = merge_branch();

	git_object_free(head_object);
	git_reference_free(head);

	return error;
}
Exemplo n.º 3
0
void test_merge_driver__wildcard(void)
{
	const char *expected = "This is the `foobar` driver.\n";
	set_gitattributes_to("foobar");
	merge_branch();

	cl_assert_equal_file(expected, strlen(expected),
		TEST_REPO_PATH "/applied.txt");
}
Exemplo n.º 4
0
void test_merge_driver__honors_custom_mergedefault(void)
{
	const char *expected = "This is the `custom` driver.\n";

	cl_repo_set_string(repo, "merge.default", "custom");
	merge_branch();

	cl_assert_equal_file(expected, strlen(expected),
		TEST_REPO_PATH "/applied.txt");
}
Exemplo n.º 5
0
void test_merge_driver__honors_builtin_mergedefault(void)
{
	const git_index_entry *ancestor, *ours, *theirs;

	cl_repo_set_string(repo, "merge.default", "binary");
	merge_branch();

	cl_git_pass(git_index_conflict_get(&ancestor, &ours, &theirs,
		repo_index, "automergeable.txt"));
}
Exemplo n.º 6
0
void test_merge_driver__unset_forces_binary(void)
{
	const git_index_entry *ancestor, *ours, *theirs;

	/* `-merge` without specifying a driver indicates `binary` */
	set_gitattributes_to(NULL);
	cl_repo_set_string(repo, "merge.default", "custom");

	merge_branch();

	cl_git_pass(git_index_conflict_get(&ancestor, &ours, &theirs,
		repo_index, "automergeable.txt"));
}
Exemplo n.º 7
0
void test_merge_driver__set_forces_text(void)
{
	const git_index_entry *idx;

	/* `merge` without specifying a driver indicates `text` */
	set_gitattributes_to("");
	cl_repo_set_string(repo, "merge.default", "custom");

	merge_branch();

	cl_assert((idx = git_index_get_bypath(repo_index, "automergeable.txt", 0)));
	cl_assert_equal_oid(&automergeable_id, &idx->id);
}
Exemplo n.º 8
0
Arquivo: dirty.c Projeto: 1336/libgit2
void test_merge_workdir_dirty__identical_staged_files_allowed(void)
{
	char **content;
	size_t i;

	set_core_autocrlf_to(repo, false);
	
	for (i = 0, content = result_contents[i]; content[0]; content = result_contents[++i]) {
		stage_content(content);

		git_index_write(repo_index);
		cl_git_pass(merge_branch());
	}
}
Exemplo n.º 9
0
void test_merge_driver__mergedefault_deferring_falls_back_to_text(void)
{
	const git_index_entry *idx;

	cl_git_pass(git_merge_driver_register("defer",
		&test_driver_defer_apply.base));

	cl_repo_set_string(repo, "merge.default", "defer");
	merge_branch();

	cl_assert((idx = git_index_get_bypath(repo_index, "automergeable.txt", 0)));
	cl_assert_equal_oid(&automergeable_id, &idx->id);

	git_merge_driver_unregister("defer");
}
Exemplo n.º 10
0
void test_merge_driver__apply_can_conflict(void)
{
	const git_index_entry *ancestor, *ours, *theirs;

	cl_git_pass(git_merge_driver_register("conflict",
		&test_driver_conflict_apply.base));

    set_gitattributes_to("conflict");
    merge_branch();

	cl_git_pass(git_index_conflict_get(&ancestor, &ours, &theirs,
		repo_index, "automergeable.txt"));

	git_merge_driver_unregister("conflict");
}
Exemplo n.º 11
0
void test_merge_driver__apply_can_defer(void)
{
	const git_index_entry *idx;

	cl_git_pass(git_merge_driver_register("defer",
		&test_driver_defer_apply.base));

    set_gitattributes_to("defer");
    merge_branch();

	cl_assert((idx = git_index_get_bypath(repo_index, "automergeable.txt", 0)));
	cl_assert_equal_oid(&automergeable_id, &idx->id);

	git_merge_driver_unregister("defer");
}
Exemplo n.º 12
0
Arquivo: dirty.c Projeto: 1336/libgit2
void test_merge_workdir_dirty__unstaged_deletes_maintained(void)
{
	git_reference *head;
	git_object *head_object;

	cl_git_pass(git_repository_head(&head, repo));
	cl_git_pass(git_reference_peel(&head_object, head, GIT_OBJ_COMMIT));
	cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL));

	cl_git_pass(p_unlink("merge-resolve/unchanged.txt"));

	cl_git_pass(merge_branch());

	git_object_free(head_object);
	git_reference_free(head);
}
Exemplo n.º 13
0
void test_merge_driver__not_configured_driver_falls_back(void)
{
	const git_index_entry *idx;

	test_drivers_unregister();

	/* `merge` without specifying a driver indicates `text` */
	set_gitattributes_to("notfound");

	merge_branch();

	cl_assert((idx = git_index_get_bypath(repo_index, "automergeable.txt", 0)));
	cl_assert_equal_oid(&automergeable_id, &idx->id);

	test_drivers_register();
}
Exemplo n.º 14
0
Arquivo: dirty.c Projeto: 1336/libgit2
static int merge_dirty_files(char *dirty_files[])
{
	git_reference *head;
	git_object *head_object;
	int error;

	cl_git_pass(git_repository_head(&head, repo));
	cl_git_pass(git_reference_peel(&head_object, head, GIT_OBJ_COMMIT));
	cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL));

	write_files(dirty_files);

	error = merge_branch();

	git_object_free(head_object);
	git_reference_free(head);

	return error;
}
Exemplo n.º 15
0
Arquivo: dirty.c Projeto: 1336/libgit2
static int merge_staged_files(char *staged_files[])
{	
	stage_random_files(staged_files);
	return merge_branch();
}