Ejemplo n.º 1
0
Archivo: nsec.c Proyecto: Dipti126/git
void test_index_nsec__staging_maintains_other_nanos(void)
{
	const git_index_entry *entry;
	bool expect_nsec, test_file_has_nsec;

    expect_nsec = should_expect_nsecs();
	test_file_has_nsec = try_create_file_with_nsec_timestamp("nsecs/a.txt");

	cl_assert_equal_b(expect_nsec, test_file_has_nsec);

	cl_git_pass(git_index_add_bypath(repo_index, "a.txt"));
	cl_git_pass(git_index_write(repo_index));

	cl_git_pass(git_index_write(repo_index));

	git_index_read(repo_index, 1);
	cl_assert_equal_b(true, has_nsecs());

	cl_assert((entry = git_index_get_bypath(repo_index, "a.txt", 0)));

	/* if we are writing nanoseconds to the index, expect them to be
	 * nonzero.
	 */
	if (expect_nsec) {
		cl_assert(entry->ctime.nanoseconds != 0);
		cl_assert(entry->mtime.nanoseconds != 0);
	} else {
		cl_assert_equal_i(0, entry->ctime.nanoseconds);
		cl_assert_equal_i(0, entry->mtime.nanoseconds);
	}
}
Ejemplo n.º 2
0
Archivo: init.c Proyecto: Arhzi/libgit2
static void assert_mode_seems_okay(
	const char *base, const char *path,
	git_filemode_t expect_mode, bool expect_setgid, bool core_filemode)
{
	git_buf full = GIT_BUF_INIT;
	struct stat st;

	cl_git_pass(git_buf_joinpath(&full, base, path));
	cl_git_pass(git_path_lstat(full.ptr, &st));
	git_buf_free(&full);

	if (!core_filemode) {
		CLEAR_FOR_CORE_FILEMODE(expect_mode);
		CLEAR_FOR_CORE_FILEMODE(st.st_mode);
		expect_setgid = false;
	}

	if (S_ISGID != 0)
		cl_assert_equal_b(expect_setgid, (st.st_mode & S_ISGID) != 0);

	cl_assert_equal_b(
		GIT_PERMS_IS_EXEC(expect_mode), GIT_PERMS_IS_EXEC(st.st_mode));

	cl_assert_equal_i_fmt(
		GIT_MODE_TYPE(expect_mode), GIT_MODE_TYPE(st.st_mode), "%07o");
}
Ejemplo n.º 3
0
Archivo: new.c Proyecto: 1336/libgit2
void test_repo_new__is_bare_until_workdir_set(void)
{
	git_repository *repo;

	cl_git_pass(git_repository_new(&repo));
	cl_assert_equal_b(true, git_repository_is_bare(repo));

	cl_git_pass(git_repository_set_workdir(repo, clar_sandbox_path(), 0));
	cl_assert_equal_b(false, git_repository_is_bare(repo));

	git_repository_free(repo);
}
Ejemplo n.º 4
0
static void check_some_bits(git_bitvec *bv, size_t length)
{
	size_t i;

	for (i = 0; i < length; ++i)
		cl_assert_equal_b(i % 3 == 0 || i % 7 == 0, git_bitvec_get(bv, i));
}
Ejemplo n.º 5
0
static void check_stat_data(git_index *index, const char *path, bool match)
{
	const git_index_entry *entry;
	struct stat st;

	cl_must_pass(p_lstat(path, &st));

	/* skip repo base dir name */
	while (*path != '/')
		++path;
	++path;

	entry = git_index_get_bypath(index, path, 0);
	cl_assert(entry);

	if (match) {
		cl_assert(st.st_ctime == entry->ctime.seconds);
		cl_assert(st.st_mtime == entry->mtime.seconds);
		cl_assert(st.st_size == entry->file_size);
		cl_assert(st.st_uid  == entry->uid);
		cl_assert(st.st_gid  == entry->gid);
		cl_assert_equal_i_fmt(
			GIT_MODE_TYPE(st.st_mode), GIT_MODE_TYPE(entry->mode), "%07o");
		if (cl_is_chmod_supported())
			cl_assert_equal_b(
				GIT_PERMS_IS_EXEC(st.st_mode), GIT_PERMS_IS_EXEC(entry->mode));
	} else {
		/* most things will still match */
		cl_assert(st.st_size != entry->file_size);
		/* would check mtime, but with second resolution it won't work :( */
	}
}
Ejemplo n.º 6
0
void assert_is_ignored(bool expected, const char *filepath)
{
	int is_ignored;

	cl_git_pass(git_ignore_path_is_ignored(&is_ignored, g_repo, filepath));
	cl_assert_equal_b(expected, is_ignored);
}
Ejemplo n.º 7
0
/*
 * At the beginning of the test, config18 has:
 *	int32global = 28
 *	int64global = 9223372036854775803
 *	boolglobal = true
 *	stringglobal = I'm a global config value!
 *
 * And config19 has:
 *	int32global = -1
 *	int64global = -2
 *	boolglobal = false
 *	stringglobal = don't find me!
 *
 */
void test_config_read__simple_read_from_specific_level(void)
{
	git_config *cfg, *cfg_specific;
	int i;
	int64_t l, expected = +9223372036854775803;

	cl_git_pass(git_config_new(&cfg));
	cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
		GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
	cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"),
		GIT_CONFIG_LEVEL_SYSTEM, NULL, 0));

	cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL));

	cl_git_pass(git_config_get_int32(&i, cfg_specific, "core.int32global"));
	cl_assert_equal_i(28, i);
	cl_git_pass(git_config_get_int64(&l, cfg_specific, "core.int64global"));
	cl_assert(l == expected);
	cl_git_pass(git_config_get_bool(&i, cfg_specific, "core.boolglobal"));
	cl_assert_equal_b(true, i);
	cl_git_pass(git_config_get_string_buf(&buf, cfg_specific, "core.stringglobal"));
	cl_assert_equal_s("I'm a global config value!", git_buf_cstr(&buf));

	git_config_free(cfg_specific);
	git_config_free(cfg);
}
Ejemplo n.º 8
0
Archivo: nsec.c Proyecto: Dipti126/git
static bool try_create_file_with_nsec_timestamp(const char *path)
{
	struct stat st;
	int try;

	/* retry a few times to avoid nanos *actually* equal 0 race condition */
	for (try = 0; try < 3; try++) {
		cl_git_mkfile(path, "This is hopefully a file with nanoseconds!");

		cl_must_pass(p_stat(path, &st));

		if (st.st_ctime_nsec && st.st_mtime_nsec)
			return true;
	}

	return false;
}

/* try to determine if the underlying filesystem supports a resolution
 * higher than a single second.  (i'm looking at you, hfs+)
 */
static bool should_expect_nsecs(void)
{
	git_buf nsec_path = GIT_BUF_INIT;
	bool expect;

	git_buf_joinpath(&nsec_path, clar_sandbox_path(), "nsec_test");

	expect = try_create_file_with_nsec_timestamp(nsec_path.ptr);

	p_unlink(nsec_path.ptr);

	git_buf_clear(&nsec_path);

	return expect;
}

static bool has_nsecs(void)
{
	const git_index_entry *entry;
	size_t i;
	bool has_nsecs = false;

	for (i = 0; i < git_index_entrycount(repo_index); i++) {
		entry = git_index_get_byindex(repo_index, i);

		if (entry->ctime.nanoseconds || entry->mtime.nanoseconds) {
			has_nsecs = true;
			break;
		}
	}

	return has_nsecs;
}

void test_index_nsec__has_nanos(void)
{
	cl_assert_equal_b(true, has_nsecs());
}
Ejemplo n.º 9
0
void test_sample__3(void)
{
	const char *actual = "expected";
	int value = 100;

	cl_assert_equal_s("expected", actual);
	cl_assert_equal_i(100, value);
	cl_assert_equal_b(1, value);       /* equal as booleans */
	cl_assert_equal_p(actual, actual); /* pointers to same object */
}
Ejemplo n.º 10
0
Archivo: new.c Proyecto: 1336/libgit2
void test_repo_new__has_nothing(void)
{
	git_repository *repo;

	cl_git_pass(git_repository_new(&repo));
	cl_assert_equal_b(true, git_repository_is_bare(repo));
	cl_assert_equal_p(NULL, git_repository_path(repo));
	cl_assert_equal_p(NULL, git_repository_workdir(repo));
	git_repository_free(repo);
}
Ejemplo n.º 11
0
void test_core_path__13_cannot_prettify_a_non_existing_file(void)
{
	git_buf p = GIT_BUF_INIT;

	cl_assert_equal_b(git_path_exists(NON_EXISTING_FILEPATH), false);
	cl_assert_equal_i(GIT_ENOTFOUND, git_path_prettify(&p, NON_EXISTING_FILEPATH, NULL));
	cl_assert_equal_i(GIT_ENOTFOUND, git_path_prettify(&p, NON_EXISTING_FILEPATH "/so-do-i", NULL));

	git_buf_dispose(&p);
}
Ejemplo n.º 12
0
Archivo: nsec.c Proyecto: Dipti126/git
void test_index_nsec__status_doesnt_clear_nsecs(void)
{
	git_status_list *statuslist;

	cl_git_pass(git_status_list_new(&statuslist, repo, NULL));

	git_index_read(repo_index, 1);
	cl_assert_equal_b(true, has_nsecs());

	git_status_list_free(statuslist);
}
Ejemplo n.º 13
0
Archivo: apply.c Proyecto: 1336/libgit2
void test_stash_apply__executes_notify_cb(void)
{
	git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT;
	struct seen_paths seen_paths = {0};

	opts.checkout_options.notify_cb = checkout_notify;
	opts.checkout_options.notify_flags = GIT_CHECKOUT_NOTIFY_ALL;
	opts.checkout_options.notify_payload = &seen_paths;

	cl_git_pass(git_stash_apply(repo, 0, &opts));

	cl_assert_equal_i(git_index_has_conflicts(repo_index), 0);
	assert_status(repo, "what", GIT_STATUS_WT_MODIFIED);
	assert_status(repo, "how", GIT_STATUS_CURRENT);
	assert_status(repo, "who", GIT_STATUS_WT_MODIFIED);
	assert_status(repo, "when", GIT_STATUS_WT_NEW);

	cl_assert_equal_b(true, seen_paths.what);
	cl_assert_equal_b(false, seen_paths.how);
	cl_assert_equal_b(true, seen_paths.who);
	cl_assert_equal_b(true, seen_paths.when);
}
Ejemplo n.º 14
0
void test_config_read__lone_variable_with_trailing_whitespace(void)
{
	git_config *cfg;
	int b;

	cl_set_cleanup(&clean_test_config, NULL);
	cl_git_mkfile("./testconfig", "[foo]\n    lonevariable   \n");
	cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig"));

	cl_git_pass(git_config_get_bool(&b, cfg, "foo.lonevariable"));
	cl_assert_equal_b(true, b);

	git_config_free(cfg);
}
Ejemplo n.º 15
0
void test_network_remote_remotes__add_pushspec(void)
{
	size_t size;

	size = git_remote_refspec_count(_remote);

	cl_git_pass(git_remote_add_push(_repo, "test", "refs/*:refs/*"));
	size++;

	git_remote_free(_remote);
	cl_git_pass(git_remote_lookup(&_remote, _repo, "test"));

	cl_assert_equal_i((int)size, (int)git_remote_refspec_count(_remote));

	_refspec = git_remote_get_refspec(_remote, size - 1);
	cl_assert_equal_s(git_refspec_src(_refspec), "refs/*");
	cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*");
	cl_assert_equal_s(git_refspec_string(_refspec), "refs/*:refs/*");

	cl_assert_equal_b(_refspec->push, true);
}
Ejemplo n.º 16
0
void test_network_remote_remotes__add_fetchspec(void)
{
	size_t size;

	size = git_remote_refspec_count(_remote);

	cl_git_pass(git_remote_add_fetch(_repo, "test", "refs/*:refs/*"));
	size++;

	git_remote_free(_remote);
	cl_git_pass(git_remote_lookup(&_remote, _repo, "test"));

	cl_assert_equal_i((int)size, (int)git_remote_refspec_count(_remote));

	_refspec = git_remote_get_refspec(_remote, size - 1);
	cl_assert_equal_s(git_refspec_src(_refspec), "refs/*");
	cl_assert_equal_s(git_refspec_dst(_refspec), "refs/*");
	cl_assert_equal_s(git_refspec_string(_refspec), "refs/*:refs/*");
	cl_assert_equal_b(_refspec->push, false);

	cl_git_fail_with(GIT_EINVALIDSPEC, git_remote_add_fetch(_repo, "test", "refs/*/foo/*:refs/*"));
}
Ejemplo n.º 17
0
void test_config_write__add_value_at_specific_level(void)
{
	git_config *cfg, *cfg_specific;
	int i;
	int64_t l, expected = +9223372036854775803;
	git_buf buf = GIT_BUF_INIT;

	// open config15 as global level config file
	cl_git_pass(git_config_new(&cfg));
	cl_git_pass(git_config_add_file_ondisk(cfg, "config9",
		GIT_CONFIG_LEVEL_LOCAL, 0));
	cl_git_pass(git_config_add_file_ondisk(cfg, "config15",
		GIT_CONFIG_LEVEL_GLOBAL, 0));

	cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL));

	cl_git_pass(git_config_set_int32(cfg_specific, "core.int32global", 28));
	cl_git_pass(git_config_set_int64(cfg_specific, "core.int64global", expected));
	cl_git_pass(git_config_set_bool(cfg_specific, "core.boolglobal", true));
	cl_git_pass(git_config_set_string(cfg_specific, "core.stringglobal", "I'm a global config value!"));
	git_config_free(cfg_specific);
	git_config_free(cfg);

	// open config15 as local level config file
	cl_git_pass(git_config_open_ondisk(&cfg, "config15"));

	cl_git_pass(git_config_get_int32(&i, cfg, "core.int32global"));
	cl_assert_equal_i(28, i);
	cl_git_pass(git_config_get_int64(&l, cfg, "core.int64global"));
	cl_assert(l == expected);
	cl_git_pass(git_config_get_bool(&i, cfg, "core.boolglobal"));
	cl_assert_equal_b(true, i);
	cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.stringglobal"));
	cl_assert_equal_s("I'm a global config value!", git_buf_cstr(&buf));

	git_buf_free(&buf);
	git_config_free(cfg);
}