Exemplo n.º 1
0
QString QGitConfig::findGlobal()
{
    char buffer[GIT_PATH_MAX];
    qGitThrow( git_config_find_global(buffer, GIT_PATH_MAX) );

    return QFile::decodeName(buffer);
}
Exemplo n.º 2
0
int git_config_open_global(git_config **out)
{
	int error;
	char global_path[GIT_PATH_MAX];

	if ((error = git_config_find_global(global_path)) < GIT_SUCCESS)
		return error;

	return git_config_open_ondisk(out, global_path);
}
Exemplo n.º 3
0
/**
 * ggit_config_find_global:
 *
 * Find the file representing the users global git configuration. This file
 * is usually located at $HOME/.gitconfig. This function will try to guess
 * the full path to that file, if the file exists. The returned file may then
 * be used with #ggit_config_new_from_file or #ggit_config_add_file. This
 * function returns %NULL if the global config could not be found.
 *
 * Returns: (transfer full): a #GFile or %NULL if the global config could not be found.
 *
 **/
GFile *
ggit_config_find_global (void)
{
	gchar path[GIT_PATH_MAX];

	if (git_config_find_global (path, GIT_PATH_MAX) != GIT_OK)
	{
		return NULL;
	}
	else
	{
		return g_file_new_for_path (path);
	}
}
Exemplo n.º 4
0
PyObject *
Config_get_global_config(void)
{
    char path[GIT_PATH_MAX];
    int err;

    err = git_config_find_global(path, GIT_PATH_MAX);
    if (err < 0) {
        if (err == GIT_ENOTFOUND) {
            PyErr_SetString(PyExc_IOError, "Global config file not found.");
            return NULL;
        }
        return Error_set(err);
    }

    return Config_open(path);
}
Exemplo n.º 5
0
int git_repository_config__weakptr(git_config **out, git_repository *repo)
{
	int error = 0;

	if (repo->_config == NULL) {
		git_buf global_buf = GIT_BUF_INIT;
		git_buf xdg_buf = GIT_BUF_INIT;
		git_buf system_buf = GIT_BUF_INIT;
		git_config *config;

		git_config_find_global(&global_buf);
		git_config_find_xdg(&xdg_buf);
		git_config_find_system(&system_buf);

		/* If there is no global file, open a backend for it anyway */
		if (git_buf_len(&global_buf) == 0)
			git_config__global_location(&global_buf);

		error = load_config(
			&config, repo,
			path_unless_empty(&global_buf),
			path_unless_empty(&xdg_buf),
			path_unless_empty(&system_buf));
		if (!error) {
			GIT_REFCOUNT_OWN(config, repo);

			config = (git_config*) git__compare_and_swap(&repo->_config, NULL, config);
			if (config != NULL) {
				GIT_REFCOUNT_OWN(config, NULL);
				git_config_free(config);
			}
		}

		git_buf_free(&global_buf);
		git_buf_free(&xdg_buf);
		git_buf_free(&system_buf);
	}

	*out = repo->_config;
	return error;
}
Exemplo n.º 6
0
int
create_repo(const char *repo_name)
{
	int r;

	git_repository *repo;
	git_oid blob_id;
	git_oid oid;
	git_oid tree_id;
	git_signature *author;
	git_time_t time;
	git_config *config;
	git_index *index;
	git_tree *tree;
	git_treebuilder *tree_builder;
	git_treebuilder *empty_tree_builder;
	char global_config_path[GIT_PATH_MAX];
	
	// create the repository
	r = git_repository_init(&repo, repo_name, 1);
	if (r)
		printf("error in creating repository\n");
	printf("Repo created\n");
	
	// set the repository config
	git_config_new(&config);
	git_config_find_global(global_config_path, GIT_PATH_MAX);
	git_config_add_file_ondisk(config, global_config_path, 1);
	//git_config_set_string(config, "name", "Varun Agrawal");
	//git_config_set_string(config, "email", "*****@*****.**");
	git_repository_set_config(repo, config);
	printf("Repo config set\n");

	// create a treebuilder
	r = git_treebuilder_create(&tree_builder, NULL);
	if (r)
		printf("error in creting treebuilder\n");
	printf("Tree builder created\n");

	// ADDING FIRST FILE
	// create a blob
	r = git_blob_create_fromdisk(&blob_id, repo, "test1");
	if (r)
		printf("error in creating blob from disk\n");
	printf("Blob created\n");

	// insert into tree
	r = git_treebuilder_insert(NULL, tree_builder, "test1", &blob_id, 0100644);
	if (r)
		printf("error in inserting into treebuilder\n");
	printf("Insert into treebuilder successful\n");

	// ADDING SECOND FILE
	// create a blob
	r = git_blob_create_fromdisk(&blob_id, repo, "test2");
	if (r)
		printf("error in creating blob from disk\n");
	printf("Blob created\n");

	// insert into tree
	r = git_treebuilder_insert(NULL, tree_builder, "test2", &blob_id, 0100644);
	if (r)
		printf("error in inserting into treebuilder\n");
	printf("Insert into treebuilder successful\n");

	// ADDING A EMPTY FOLDER
	// create a empty tree
	r = git_treebuilder_create(&empty_tree_builder, NULL);
	if (r)
		printf("error in creting empty treebuilder\n");
	printf("Empty Tree builder created\n");
	
	// write the empty tree to the repo
	r = git_treebuilder_write(&tree_id, repo, empty_tree_builder);
	if (r)
		printf("error in writing the empty tree to the repo\n");
	printf("Writing the empty tree to repo successful\n");


	// insert empty tree into the tree
	r = git_treebuilder_insert(NULL, tree_builder, "test_dir", &tree_id, 0040000);
	if (r)
		printf("error in inserting into treebuilder\n");
	printf("Insert into treebuilder successful\n");

	// write the tree to the repo
	r = git_treebuilder_write(&oid, repo, tree_builder);
	if (r)
		printf("error in writing the tree to the repo\n");
	printf("Writing the tree to repo successful\n");

	// tree lookup
	r = git_tree_lookup(&tree, repo, &oid);
	if (r)
		printf("error in tree lookup\n");
	printf("Tree lookup done\n");
	
	// create a author
	time = get_time();
	r = git_signature_new(&author, "Varun Agrawal", "*****@*****.**", time, -300);
	if (r)
		printf("error in creating signature\n");
	printf("Author signature created\n");

	// create a commit
	r = git_commit_create(  &oid, // object id
				repo, // repository
				"HEAD", // update reference, this will update the HEAD to this commit
				author, // author
				author, // committer
				NULL, // message encoding, by default UTF-8 is used
				"first commit", // message for the commit
				tree, // the git_tree object which will be used as the tree for this commit. don't know if NULL is valid
				0, // number of parents. Don't know what value should be used here
				NULL); // array of pointers to the parents(git_commit *parents[])
	if (r)
		printf("error in creating a commit\n");
	printf("Commit created\n");
	
	git_repository_free(repo);
	return 0;
}
Exemplo n.º 7
0
std::string Config::findGlobal()
{
    char buffer[GIT_PATH_MAX];
    Exception::assert(git_config_find_global(buffer, GIT_PATH_MAX) );
    return std::string(buffer);
}