Ejemplo n.º 1
0
Archivo: attr.c Proyecto: basilgor/git
static const char *get_home_gitattributes(void)
{
	if (!git_attributes_file)
		git_attributes_file = xdg_config_home("attributes");

	return git_attributes_file;
}
Ejemplo n.º 2
0
void test_xdg_config_home(void **param)
{
	//return XDG_CONFIG_HOME if defined
	setenv("XDG_CONFIG_HOME", "/tmp/", 1);
	assert_string_equal(xdg_config_home(), "/tmp/");

	setenv("XDG_CONFIG_HOME", "/tmp", 1);
	assert_string_equal(xdg_config_home(), "/tmp/");

	//return $HOME/.local/share if not
	setenv("XDG_CONFIG_HOME", "", 1);
	setenv("HOME", ".", 1);
	assert_string_equal(xdg_config_home(), "./" DEFAULT_XDG_CONFIG_HOME);
	unsetenv("XDG_CONFIG_HOME");
	assert_string_equal(xdg_config_home(), "./" DEFAULT_XDG_CONFIG_HOME);
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
	const char * const usage[] = {
		"git credential-store [<options>] <action>",
		NULL
	};
	const char *op;
	struct credential c = CREDENTIAL_INIT;
	struct string_list fns = STRING_LIST_INIT_DUP;
	char *file = NULL;
	struct option options[] = {
		OPT_STRING(0, "file", &file, "path",
			   "fetch and store credentials in <path>"),
		OPT_END()
	};

	umask(077);

	argc = parse_options(argc, (const char **)argv, NULL, options, usage, 0);
	if (argc != 1)
		usage_with_options(usage, options);
	op = argv[0];

	if (file) {
		string_list_append(&fns, file);
	} else {
		if ((file = expand_user_path("~/.git-credentials")))
			string_list_append_nodup(&fns, file);
		file = xdg_config_home("credentials");
		if (file)
			string_list_append_nodup(&fns, file);
	}
	if (!fns.nr)
		die("unable to set up default path; use --file");

	if (credential_read(&c, stdin) < 0)
		die("unable to read credential");

	if (!strcmp(op, "get"))
		lookup_credential(&fns, &c);
	else if (!strcmp(op, "erase"))
		remove_credential(&fns, &c);
	else if (!strcmp(op, "store"))
		store_credential(&fns, &c);
	else
		; /* Ignore unknown operation. */

	string_list_clear(&fns, 0);
	return 0;
}
Ejemplo n.º 4
0
void setup_standard_excludes(struct dir_struct *dir)
{
	const char *path;

	dir->exclude_per_dir = ".gitignore";

	/* core.excludefile defaulting to $XDG_HOME/git/ignore */
	if (!excludes_file)
		excludes_file = xdg_config_home("ignore");
	if (excludes_file && !access_or_warn(excludes_file, R_OK, 0))
		add_excludes_from_file(dir, excludes_file);

	/* per repository user preference */
	path = git_path("info/exclude");
	if (!access_or_warn(path, R_OK, 0))
		add_excludes_from_file(dir, path);
}
Ejemplo n.º 5
0
void test_create_xdg_dirs_when_dotlocal_and_dotconfig_have_not_been_created(void **param)
{
	//set temporary directory as HOME in order to ensure that .local and .config do not exist
	char *previous_home_dir = strdup(getenv("HOME"));
	char temp_home_dir[] = "/tmp/flybyXXXXXXXX";
	mkdtemp(temp_home_dir);
	setenv("HOME", temp_home_dir, 1);
	assert_true(directory_exists(temp_home_dir));

	//ensure XDG_*_HOME are empty
	setenv("XDG_DATA_HOME", "", 1);
	setenv("XDG_CONFIG_HOME", "", 1);

	char *data_home_path = xdg_data_home();
	char *config_home_path = xdg_config_home();
	assert_false(directory_exists(data_home_path));
	assert_false(directory_exists(config_home_path));

	//ensure that XDG_DATA_HOME and XDG_CONFIG_HOME are as expected
	char *expected_data_home_path = add_to_path(temp_home_dir, DEFAULT_XDG_DATA_HOME);
	char *expected_config_home_path = add_to_path(temp_home_dir, DEFAULT_XDG_CONFIG_HOME);
	assert_string_equal(data_home_path, expected_data_home_path);
	assert_string_equal(config_home_path, expected_config_home_path);

	free(expected_data_home_path);
	free(expected_config_home_path);

	//test directory creation
	test_create_xdg_dirs();

	//revert HOME variable
	setenv("HOME", previous_home_dir, 1);
	free(previous_home_dir);

	//clean up directories
	char *data_home_base_path = add_to_path(temp_home_dir, DEFAULT_XDG_DATA_HOME_BASE); //corresponds to (...)/.local
	rmdir(data_home_path);
	rmdir(data_home_base_path);
	rmdir(config_home_path);
	rmdir(temp_home_dir);
	assert_false(directory_exists(temp_home_dir));

	free(data_home_base_path);
	free(data_home_path);
	free(config_home_path);
}
Ejemplo n.º 6
0
/**
 * Check that full flyby config/data directories (XDG_DATA_HOME/flyby/tles,
 * XDG_CONFIG_HOME/flyby) can be created given the current definitions of
 * XDG_DATA_HOME and XDG_CONFIG_HOME and remove the directories again. Called
 * from the test_create_xdg_dirs_when_*-functions.
 **/
void test_create_xdg_dirs()
{
	//construct expected paths
	char *xdg_data_home_basepath = xdg_data_home();
	char *xdg_config_home_basepath = xdg_config_home();
	char *flyby_config_dir = add_to_path(xdg_config_home_basepath, FLYBY_RELATIVE_ROOT_PATH);
	char *flyby_data_dir = add_to_path(xdg_data_home_basepath, FLYBY_RELATIVE_ROOT_PATH);
	char *flyby_tle_dir = add_to_path(xdg_data_home_basepath, TLE_RELATIVE_DIR_PATH);

	//check that paths do not exist yet
	assert_false(directory_exists(flyby_config_dir));
	assert_false(directory_exists(flyby_data_dir));
	assert_false(directory_exists(flyby_tle_dir));

	create_xdg_dirs();

	//check that paths have been created
	assert_true(directory_exists(flyby_config_dir));
	assert_true(directory_exists(flyby_data_dir));
	assert_true(directory_exists(flyby_tle_dir));

	//cleanup
	rmdir(flyby_tle_dir);
	rmdir(flyby_data_dir);
	rmdir(flyby_config_dir);
	
	assert_false(directory_exists(flyby_config_dir));
	assert_false(directory_exists(flyby_data_dir));
	assert_false(directory_exists(flyby_tle_dir));

	free(flyby_config_dir);
	free(flyby_data_dir);
	free(flyby_tle_dir);

	free(xdg_data_home_basepath);
	free(xdg_config_home_basepath);
}