rename.c 2.41 KB
Newer Older
1
#include "clar_libgit2.h"
2 3 4 5 6 7
#include "posix.h"

void test_index_rename__single_file(void)
{
	git_repository *repo;
	git_index *index;
8
	size_t position;
9
	git_oid expected;
Ben Straub committed
10
	const git_index_entry *entry;
11 12 13 14 15 16 17 18

	p_mkdir("rename", 0700);

	cl_git_pass(git_repository_init(&repo, "./rename", 0));
	cl_git_pass(git_repository_index(&index, repo));

	cl_assert(git_index_entrycount(index) == 0);

19
	cl_git_mkfile("./rename/lame.name.txt", "new_file\n");
20 21

	/* This should add a new blob to the object database in 'd4/fa8600b4f37d7516bef4816ae2c64dbf029e3a' */
22
	cl_git_pass(git_index_add_bypath(index, "lame.name.txt"));
23 24 25 26
	cl_assert(git_index_entrycount(index) == 1);

	cl_git_pass(git_oid_fromstr(&expected, "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a"));

27
	cl_assert(!git_index_find(&position, index, "lame.name.txt"));
28

Edward Thomson committed
29
	entry = git_index_get_byindex(index, position);
30
	cl_assert_equal_oid(&expected, &entry->id);
31 32

	/* This removes the entry from the index, but not from the object database */
Edward Thomson committed
33
	cl_git_pass(git_index_remove(index, "lame.name.txt", 0));
34 35 36 37
	cl_assert(git_index_entrycount(index) == 0);

	p_rename("./rename/lame.name.txt", "./rename/fancy.name.txt");

38
	cl_git_pass(git_index_add_bypath(index, "fancy.name.txt"));
39 40
	cl_assert(git_index_entrycount(index) == 1);

41
	cl_assert(!git_index_find(&position, index, "fancy.name.txt"));
42

Edward Thomson committed
43
	entry = git_index_get_byindex(index, position);
44
	cl_assert_equal_oid(&expected, &entry->id);
45 46 47 48 49 50

	git_index_free(index);
	git_repository_free(repo);

	cl_fixture_cleanup("rename");
}
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

void test_index_rename__casechanging(void)
{
	git_repository *repo;
	git_index *index;
	const git_index_entry *entry;
	git_index_entry new = {{0}};

	p_mkdir("rename", 0700);

	cl_git_pass(git_repository_init(&repo, "./rename", 0));
	cl_git_pass(git_repository_index(&index, repo));

	cl_git_mkfile("./rename/lame.name.txt", "new_file\n");

	cl_git_pass(git_index_add_bypath(index, "lame.name.txt"));
	cl_assert_equal_i(1, git_index_entrycount(index));
	cl_assert((entry = git_index_get_bypath(index, "lame.name.txt", 0)));

	memcpy(&new, entry, sizeof(git_index_entry));
	new.path = "LAME.name.TXT";

	cl_git_pass(git_index_add(index, &new));
	cl_assert((entry = git_index_get_bypath(index, "LAME.name.TXT", 0)));

	if (cl_repo_get_bool(repo, "core.ignorecase"))
		cl_assert_equal_i(1, git_index_entrycount(index));
	else
		cl_assert_equal_i(2, git_index_entrycount(index));
Carlos Martín Nieto committed
80 81 82 83 84

	git_index_free(index);
	git_repository_free(repo);

	cl_fixture_cleanup("rename");
85 86
}