Exemplo n.º 1
0
int main(int argc, char **argv)
{
	git_repository *repo;
	describe_options opts;

	git_threads_init();

	check_lg2(git_repository_open_ext(&repo, ".", 0, NULL),
			"Could not open repository", NULL);

	describe_options_init(&opts);
	parse_options(&opts, argc, argv);

	do_describe(repo, &opts);

	git_repository_free(repo);
	git_threads_shutdown();

	return 0;
}
Exemplo n.º 2
0
void test_repo_open__gitlinked(void)
{
	/* need to have both repo dir and workdir set up correctly */
	git_repository *repo = cl_git_sandbox_init("empty_standard_repo");
	git_repository *repo2;

	cl_must_pass(p_mkdir("alternate", 0777));
	cl_git_mkfile("alternate/.git", "gitdir: ../empty_standard_repo/.git");

	cl_git_pass(git_repository_open(&repo2, "alternate"));

	cl_assert(git_repository_path(repo2) != NULL);
	cl_assert_(git__suffixcmp(git_repository_path(repo2), "empty_standard_repo/.git/") == 0, git_repository_path(repo2));
	cl_assert_equal_s(git_repository_path(repo), git_repository_path(repo2));

	cl_assert(git_repository_workdir(repo2) != NULL);
	cl_assert_(git__suffixcmp(git_repository_workdir(repo2), "alternate/") == 0, git_repository_workdir(repo2));

	git_repository_free(repo2);
}
Exemplo n.º 3
0
static void *delete_refs(void *arg)
{
	int i, error;
	struct th_data *data = (struct th_data *) arg;
	git_reference *ref;
	char name[128];
	git_repository *repo;

	cl_git_thread_pass(data, git_repository_open(&repo, data->path));

	for (i = 0; i < NREFS; ++i) {
		p_snprintf(
			name, sizeof(name), "refs/heads/thread-%03d-%02d", (data->id) & ~0x3, i);

		if (!git_reference_lookup(&ref, repo, name)) {
			do {
				error = git_reference_delete(ref);
			} while (error == GIT_ELOCKED);
			/* Sometimes we race with other deleter threads */
			if (error == GIT_ENOTFOUND)
				error = 0;

			cl_git_thread_pass(data, error);
			git_reference_free(ref);
		}

		if (concurrent_compress && i == NREFS/2) {
			git_refdb *refdb;
			cl_git_thread_pass(data, git_repository_refdb(&refdb, repo));
			do {
				error = git_refdb_compress(refdb);
			} while (error == GIT_ELOCKED);
			cl_git_thread_pass(data, error);
			git_refdb_free(refdb);
		}
	}

	git_repository_free(repo);
	git_error_clear();
	return arg;
}
Exemplo n.º 4
0
int
main (int    argc,
      char **argv)
{
  GError *local_error = NULL;
  GError **error = &local_error;
  struct EvTag self = { NULL, };
  
  /* avoid gvfs (http://bugzilla.gnome.org/show_bug.cgi?id=526454) */
  g_setenv ("GIO_USE_VFS", "local", TRUE);

#ifdef HAVE_GIT_LIBGIT2_INIT
  git_libgit2_init ();
#else
  git_threads_init ();
#endif

  if (!submain (&self, argc, argv, error))
    goto out;

 out:
  if (self.top_repo)
    git_repository_free (self.top_repo);
  if (self.checksum)
    g_checksum_free (self.checksum);
  if (local_error)
    {
      int is_tty = isatty (1);
      const char *prefix = "";
      const char *suffix = "";
      if (is_tty)
        {
          prefix = "\x1b[31m\x1b[1m"; /* red, bold */
          suffix = "\x1b[22m\x1b[0m"; /* bold off, color reset */
        }
      g_printerr ("%serror: %s%s\n", prefix, suffix, local_error->message);
      g_error_free (local_error);
      return 1;
    }
  return 0;
}
Exemplo n.º 5
0
void test_refs_unicode__create_and_lookup(void)
{
    git_reference *ref0, *ref1, *ref2;
    git_repository *repo2;

    const char *REFNAME = "refs/heads/" "\303\205" "ngstr" "\303\266" "m";
    const char *master = "refs/heads/master";

    /* Create the reference */
    cl_git_pass(git_reference_lookup(&ref0, repo, master));
    cl_git_pass(git_reference_create(
                    &ref1, repo, REFNAME, git_reference_target(ref0), 0));
    cl_assert_equal_s(REFNAME, git_reference_name(ref1));
    git_reference_free(ref0);

    /* Lookup the reference in a different instance of the repository */
    cl_git_pass(git_repository_open(&repo2, "testrepo.git"));

    cl_git_pass(git_reference_lookup(&ref2, repo2, REFNAME));
    cl_assert_equal_i(
        0, git_oid_cmp(git_reference_target(ref1), git_reference_target(ref2)));
    cl_assert_equal_s(REFNAME, git_reference_name(ref2));
    git_reference_free(ref2);

#if GIT_USE_ICONV
    /* Lookup reference by decomposed unicode name */

#define REFNAME_DECOMPOSED "refs/heads/" "A" "\314\212" "ngstro" "\314\210" "m"

    cl_git_pass(git_reference_lookup(&ref2, repo2, REFNAME_DECOMPOSED));
    cl_assert_equal_i(
        0, git_oid_cmp(git_reference_target(ref1), git_reference_target(ref2)));
    cl_assert_equal_s(REFNAME, git_reference_name(ref2));
    git_reference_free(ref2);
#endif

    /* Cleanup */

    git_reference_free(ref1);
    git_repository_free(repo2);
}
Exemplo n.º 6
0
Arquivo: tests.c Projeto: 1336/libgit2
void test_index_tests__preserves_case(void)
{
	git_repository *repo;
	git_index *index;
	const git_index_entry *entry;
	int index_caps;

	cl_set_cleanup(&cleanup_myrepo, NULL);

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

	index_caps = git_index_caps(index);

	cl_git_rewritefile("myrepo/test.txt", "hey there\n");
	cl_git_pass(git_index_add_bypath(index, "test.txt"));

	cl_git_pass(p_rename("myrepo/test.txt", "myrepo/TEST.txt"));
	cl_git_rewritefile("myrepo/TEST.txt", "hello again\n");
	cl_git_pass(git_index_add_bypath(index, "TEST.txt"));

	if (index_caps & GIT_INDEXCAP_IGNORE_CASE)
		cl_assert_equal_i(1, (int)git_index_entrycount(index));
	else
		cl_assert_equal_i(2, (int)git_index_entrycount(index));

	/* Test access by path instead of index */
	cl_assert((entry = git_index_get_bypath(index, "test.txt", 0)) != NULL);
	/* The path should *not* have changed without an explicit remove */
	cl_assert(git__strcmp(entry->path, "test.txt") == 0);

	cl_assert((entry = git_index_get_bypath(index, "TEST.txt", 0)) != NULL);
	if (index_caps & GIT_INDEXCAP_IGNORE_CASE)
		/* The path should *not* have changed without an explicit remove */
		cl_assert(git__strcmp(entry->path, "test.txt") == 0);
	else
		cl_assert(git__strcmp(entry->path, "TEST.txt") == 0);

	git_index_free(index);
	git_repository_free(repo);
}
Exemplo n.º 7
0
static void assert_ignore_case(
	bool should_ignore_case,
	int expected_lower_cased_file_status,
	int expected_camel_cased_file_status)
{
	unsigned int status;
	git_buf lower_case_path = GIT_BUF_INIT, camel_case_path = GIT_BUF_INIT;
	git_repository *repo, *repo2;

	repo = cl_git_sandbox_init("empty_standard_repo");
	cl_git_remove_placeholders(git_repository_path(repo), "dummy-marker.txt");

	cl_repo_set_bool(repo, "core.ignorecase", should_ignore_case);

	cl_git_pass(git_buf_joinpath(&lower_case_path,
		git_repository_workdir(repo), "plop"));

	cl_git_mkfile(git_buf_cstr(&lower_case_path), "");

	stage_and_commit(repo, "plop");

	cl_git_pass(git_repository_open(&repo2, "./empty_standard_repo"));

	cl_git_pass(git_status_file(&status, repo2, "plop"));
	cl_assert_equal_i(GIT_STATUS_CURRENT, status);

	cl_git_pass(git_buf_joinpath(&camel_case_path,
		git_repository_workdir(repo), "Plop"));

	cl_git_pass(p_rename(git_buf_cstr(&lower_case_path), git_buf_cstr(&camel_case_path)));

	cl_git_pass(git_status_file(&status, repo2, "plop"));
	cl_assert_equal_i(expected_lower_cased_file_status, status);

	cl_git_pass(git_status_file(&status, repo2, "Plop"));
	cl_assert_equal_i(expected_camel_cased_file_status, status);

	git_repository_free(repo2);
	git_buf_free(&lower_case_path);
	git_buf_free(&camel_case_path);
}
Exemplo n.º 8
0
void test_config_global__open_programdata(void)
{
	git_config *cfg;
	git_repository *repo;
	git_buf config_path = GIT_BUF_INIT;
	git_buf var_contents = GIT_BUF_INIT;

	if (cl_is_env_set("GITTEST_INVASIVE_FS_STRUCTURE"))
		cl_skip();

	cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH,
		GIT_CONFIG_LEVEL_PROGRAMDATA, &config_path));

	if (!git_path_isdir(config_path.ptr))
		cl_git_pass(p_mkdir(config_path.ptr, 0777));

	cl_git_pass(git_buf_puts(&config_path, "/config"));

	cl_git_pass(git_config_open_ondisk(&cfg, config_path.ptr));
	cl_git_pass(git_config_set_string(cfg, "programdata.var", "even higher level"));

	git_buf_free(&config_path);
	git_config_free(cfg);

	git_config_open_default(&cfg);
	cl_git_pass(git_config_get_string_buf(&var_contents, cfg, "programdata.var"));
	cl_assert_equal_s("even higher level", var_contents.ptr);

	git_config_free(cfg);
	git_buf_free(&var_contents);

	cl_git_pass(git_repository_init(&repo, "./foo.git", true));
	cl_git_pass(git_repository_config(&cfg, repo));
	cl_git_pass(git_config_get_string_buf(&var_contents, cfg, "programdata.var"));
	cl_assert_equal_s("even higher level", var_contents.ptr);

	git_config_free(cfg);
	git_buf_free(&var_contents);
	git_repository_free(repo);
	cl_fixture_cleanup("./foo.git");
}
Exemplo n.º 9
0
/**
 * Init a repository.
 *
 * @param path A path to where to init a git repository
 * @param bare If TRUE, a Git repository without a working directory
 * is created at the pointed path. If FALSE, provided path will be
 * considered as the working directory into which the .git directory
 * will be created.
 * @return R_NilValue
 */
SEXP git2r_repository_init(SEXP path, SEXP bare)
{
    int err;
    git_repository *repository = NULL;

    if (git2r_arg_check_string(path))
        git2r_error(git2r_err_string_arg, __func__, "path");
    if (git2r_arg_check_logical(bare))
        git2r_error(git2r_err_logical_arg, __func__, "bare");

    err = git_repository_init(&repository,
                              CHAR(STRING_ELT(path, 0)),
                              LOGICAL(bare)[0]);
    if (GIT_OK != err)
        git2r_error("Error in '%s': Unable to init repository", __func__, NULL);

    if (repository)
        git_repository_free(repository);

    return R_NilValue;
}
Exemplo n.º 10
0
/**
 * Apply a single stashed state from the stash list.
 *
 * @param repo S3 class git_repository that contains the stash
 * @param index The index to the stash. 0 is the most recent stash.
 * @return R_NilValue
 */
SEXP git2r_stash_apply(SEXP repo, SEXP index)
{
    int error;
    git_repository *repository = NULL;

    if (git2r_arg_check_integer_gte_zero(index))
        git2r_error(__func__, NULL, "'index'", git2r_err_integer_gte_zero_arg);

    repository = git2r_repository_open(repo);
    if (!repository)
        git2r_error(__func__, NULL, git2r_err_invalid_repository, NULL);

    error = git_stash_apply(repository, INTEGER(index)[0], NULL);
    if (error == GIT_ENOTFOUND)
        error = 0;
    git_repository_free(repository);
    if (error)
        git2r_error(__func__, GIT2R_ERROR_LAST(), NULL, NULL);

    return R_NilValue;
}
Exemplo n.º 11
0
void Book::download_progress(std::string remote_name)
{
  #if GIT_INSTALLED 
    progress_data d = {0};

    git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
    
    clone_opts.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
    clone_opts.checkout_opts.progress_cb = checkout_progress;
    clone_opts.checkout_opts.progress_payload = &d;
    // clone_opts.checkout_opts = checkout_opts; ?
    clone_opts.fetch_opts.callbacks.transfer_progress = fetch_progress;
    clone_opts.fetch_opts.callbacks.payload = &d;
    
    git_repository *repo = NULL;
    
    int error = git_clone(&repo, remote_name.c_str(), m_local_path.c_str(), &clone_opts);
    
    git_repository_free(repo);
  #endif
}
Exemplo n.º 12
0
void
do_clone_repo(char *url, char *path)
{
	git_repository *repo = NULL;
	git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
	git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;

	checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
	checkout_opts.progress_cb = checkout_progress;
	clone_opts.checkout_opts = checkout_opts;
	clone_opts.fetch_opts.callbacks.sideband_progress = sideband_progress;
	clone_opts.fetch_opts.callbacks.transfer_progress = &fetch_progress;

	int error = git_clone(&repo, url, path, &clone_opts);
	if (error != 0)
		git_error_handling();

out:
	if (repo)
		git_repository_free(repo);
}
Exemplo n.º 13
0
Arquivo: init.c Projeto: Arhzi/libgit2
void test_repo_init__reinit_overwrites_filemode(void)
{
	int expected = cl_is_chmod_supported(), current_value;

	/* Init a new repo */
	cl_set_cleanup(&cleanup_repository, "overwrite.git");
	cl_git_pass(git_repository_init(&_repo, "overwrite.git", 1));

	/* Change the "core.filemode" config value to something unlikely */
	cl_repo_set_bool(_repo, "core.filemode", !expected);

	git_repository_free(_repo);
	_repo = NULL;

	/* Reinit the repository */
	cl_git_pass(git_repository_init(&_repo, "overwrite.git", 1));

	/* Ensure the "core.filemode" config value has been reset */
	current_value = cl_repo_get_bool(_repo, "core.filemode");
	cl_assert_equal_i(expected, current_value);
}
Exemplo n.º 14
0
void test_repo_getters__head_orphan(void)
{
	git_repository *repo;
	git_reference *ref;

	cl_git_pass(git_repository_open(&repo, "testrepo.git"));

	cl_assert(git_repository_head_orphan(repo) == 0);

	/* orphan HEAD */
	cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/orphan", 1));
	cl_assert(git_repository_head_orphan(repo) == 1);
	git_reference_free(ref);

	/* take the reop back to it's original state */
	cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1));
	cl_assert(git_repository_head_orphan(repo) == 0);

	git_reference_free(ref);
	git_repository_free(repo);
}
Exemplo n.º 15
0
/**
 * Make the repository HEAD directly point to the commit.
 *
 * @param commit S4 class git_commit
 * @return R_NilValue
 */
SEXP git2r_repository_set_head_detached(SEXP commit)
{
    int err;
    SEXP sha;
    git_oid oid;
    git_commit *treeish = NULL;
    git_repository *repository = NULL;

    if (git2r_arg_check_commit(commit))
        git2r_error(git2r_err_commit_arg, __func__, "commit");

    repository = git2r_repository_open(GET_SLOT(commit, Rf_install("repo")));
    if (!repository)
        git2r_error(git2r_err_invalid_repository, __func__, NULL);

    sha = GET_SLOT(commit, Rf_install("sha"));
    err = git_oid_fromstr(&oid, CHAR(STRING_ELT(sha, 0)));
    if (GIT_OK != err)
        goto cleanup;

    err = git_commit_lookup(&treeish, repository, &oid);
    if (GIT_OK != err)
        goto cleanup;

    err = git_repository_set_head_detached(
        repository,
        git_commit_id(treeish));

cleanup:
    if (treeish)
        git_commit_free(treeish);

    if (repository)
        git_repository_free(repository);

    if (GIT_OK != err)
        git2r_error(git2r_err_from_libgit2, __func__, giterr_last()->message);

    return R_NilValue;
}
Exemplo n.º 16
0
int git_repository_open3(git_repository **repo_out,
		const char *git_dir,
		git_odb *object_database,
		const char *git_index_file,
		const char *git_work_tree)
{
	git_repository *repo;
	int error = GIT_SUCCESS;

	assert(repo_out);

	if (object_database == NULL)
		return GIT_ERROR;

	repo = repository_alloc();
	if (repo == NULL)
		return GIT_ENOMEM;

	error = assign_repository_dirs(repo, 
			git_dir, 
			NULL,
			git_index_file,
			git_work_tree);

	if (error < GIT_SUCCESS)
		goto cleanup;

	error = check_repository_dirs(repo);
	if (error < GIT_SUCCESS)
		goto cleanup;

	repo->db = object_database;

	*repo_out = repo;
	return GIT_SUCCESS;

cleanup:
	git_repository_free(repo);
	return error;
}
Exemplo n.º 17
0
void test_index_tests__add(void)
{
   git_index *index;
   git_filebuf file = GIT_FILEBUF_INIT;
   git_repository *repo;
   git_index_entry *entry;
   git_oid id1;

   /* Intialize a new repository */
   cl_git_pass(git_repository_init(&repo, "./myrepo", 0));

   /* Ensure we're the only guy in the room */
   cl_git_pass(git_repository_index(&index, repo));
   cl_assert(git_index_entrycount(index) == 0);

   /* Create a new file in the working directory */
   cl_git_pass(git_futils_mkpath2file("myrepo/test.txt", 0777));
   cl_git_pass(git_filebuf_open(&file, "myrepo/test.txt", 0));
   cl_git_pass(git_filebuf_write(&file, "hey there\n", 10));
   cl_git_pass(git_filebuf_commit(&file, 0666));

   /* Store the expected hash of the file/blob
   * This has been generated by executing the following
   * $ echo "hey there" | git hash-object --stdin
   */
   cl_git_pass(git_oid_fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6"));

   /* Add the new file to the index */
   cl_git_pass(git_index_add(index, "test.txt", 0));

   /* Wow... it worked! */
   cl_assert(git_index_entrycount(index) == 1);
   entry = git_index_get(index, 0);

   /* And the built-in hashing mechanism worked as expected */
   cl_assert(git_oid_cmp(&id1, &entry->oid) == 0);

   git_index_free(index);
   git_repository_free(repo);
}
Exemplo n.º 18
0
void GitWrapper::commitCreateBasket()
{
    GIT_RETURN_IF_DISABLED()
    QMutexLocker l(&gitMutex);
    git_repository* repo = openRepository();
    if(repo==0)
        return;

    const QDateTime gitdate = getLastCommitDate(repo);

    const QString basketxml = Global::savesFolder() + "baskets/baskets.xml";
    const QFileInfo basketxmlinfo(basketxml);

    if(gitdate <= basketxmlinfo.lastModified())
    {
        git_index *index = NULL;
        int error = git_repository_index(&index, repo);
        if(error < 0)
        {
            gitErrorHandling();
            return;
        }
        //this is kind of hacky because somebody could come in between and we still have stuff open
        //change basket.xml
        const QString basketxml("baskets/baskets.xml");
        QByteArray basketxmlba = basketxml.toUtf8();
        char *basketxmlCString = basketxmlba.data();
        error = git_index_add_bypath(index, basketxmlCString);
        if(error < 0)
        {
            gitErrorHandling();
            return;
        }

        bool result = commitIndex(repo,index);
        git_index_free(index);
    }

    git_repository_free(repo);
}
Exemplo n.º 19
0
/**
 * Updates some entries in the index from the HEAD commit tree.
 *
 * @param repo S3 class git_repository
 * @param path The paths to reset
 * @return R_NilValue
 */
SEXP git2r_reset_default(SEXP repo, SEXP path)
{
    int error = 0;
    git_strarray pathspec = {0};
    git_reference *head = NULL;
    git_object *head_commit = NULL;
    git_repository *repository = NULL;

    if (git2r_arg_check_string_vec(path))
        git2r_error(__func__, NULL, "'path'", git2r_err_string_vec_arg);

    repository = git2r_repository_open(repo);
    if (!repository)
        git2r_error(__func__, NULL, git2r_err_invalid_repository, NULL);

    error = git2r_copy_string_vec(&pathspec, path);
    if (error || !pathspec.count)
        goto cleanup;

    error = git_repository_head(&head, repository);
    if (error)
        goto cleanup;

    error = git_reference_peel(&head_commit, head, GIT2R_OBJECT_COMMIT);
    if (error)
        goto cleanup;

    error = git_reset_default(repository, head_commit, &pathspec);

cleanup:
    git_reference_free(head);
    git_object_free(head_commit);
    free(pathspec.strings);
    git_repository_free(repository);

    if (error)
        git2r_error(__func__, GIT2R_ERROR_LAST(), NULL, NULL);

    return R_NilValue;
}
Exemplo n.º 20
0
int git_repository_open2(git_repository **repo_out,
		const char *git_dir,
		const char *git_object_directory,
		const char *git_index_file,
		const char *git_work_tree)
{
	git_repository *repo;
	int error = GIT_SUCCESS;

	assert(repo_out);

	repo = repository_alloc();
	if (repo == NULL)
		return GIT_ENOMEM;

	error = assign_repository_dirs(repo,
			git_dir, 
			git_object_directory,
			git_index_file,
			git_work_tree);

	if (error < GIT_SUCCESS)
		goto cleanup;

	error = check_repository_dirs(repo);
	if (error < GIT_SUCCESS)
		goto cleanup;

	error = init_odb(repo);
	if (error < GIT_SUCCESS)
		goto cleanup;

	*repo_out = repo;
	return GIT_SUCCESS;

cleanup:
	git_repository_free(repo);
	return error;
}
Exemplo n.º 21
0
void test_odb_foreach__files_in_objects_dir(void)
{
	git_repository *repo;
	git_odb *odb;
	git_buf buf = GIT_BUF_INIT;
	int nobj = 0;

	cl_fixture_sandbox("testrepo.git");
	cl_git_pass(git_repository_open(&repo, "testrepo.git"));

	cl_git_pass(git_buf_printf(&buf, "%s/objects/somefile", git_repository_path(repo)));
	cl_git_mkfile(buf.ptr, "");
	git_buf_dispose(&buf);

	cl_git_pass(git_repository_odb(&odb, repo));
	cl_git_pass(git_odb_foreach(odb, foreach_cb, &nobj));
	cl_assert_equal_i(60 + 1640, nobj); /* count + in-pack */

	git_odb_free(odb);
	git_repository_free(repo);
	cl_fixture_cleanup("testrepo.git");
}
Exemplo n.º 22
0
Arquivo: init.c Projeto: Arhzi/libgit2
void test_repo_init__reinit_too_recent_bare_repo(void)
{
	git_config *config;

	/* Initialize the repository */
	cl_git_pass(git_repository_init(&_repo, "reinit.git", 1));
	git_repository_config(&config, _repo);

	/*
	 * Hack the config of the repository to make it look like it has
	 * been created by a recenter version of git/libgit2
	 */
	cl_git_pass(git_config_set_int32(config, "core.repositoryformatversion", 42));

	git_config_free(config);
	git_repository_free(_repo);

	/* Try to reinitialize the repository */
	cl_git_fail(git_repository_init(&_repo, "reinit.git", 1));

	cl_fixture_cleanup("reinit.git");
}
Exemplo n.º 23
0
Arquivo: clone.c Projeto: 1336/libgit2
int do_clone(git_repository *repo, int argc, char **argv)
{
	progress_data pd = {{0}};
	git_repository *cloned_repo = NULL;
	git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
	git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
	const char *url = argv[1];
	const char *path = argv[2];
	int error;

	(void)repo; // unused

	// Validate args
	if (argc < 3) {
		printf ("USAGE: %s <url> <path>\n", argv[0]);
		return -1;
	}

	// Set up options
	checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
	checkout_opts.progress_cb = checkout_progress;
	checkout_opts.progress_payload = &pd;
	clone_opts.checkout_opts = checkout_opts;
	clone_opts.fetch_opts.callbacks.sideband_progress = sideband_progress;
	clone_opts.fetch_opts.callbacks.transfer_progress = &fetch_progress;
	clone_opts.fetch_opts.callbacks.credentials = cred_acquire_cb;
	clone_opts.fetch_opts.callbacks.payload = &pd;

	// Do the clone
	error = git_clone(&cloned_repo, url, path, &clone_opts);
	printf("\n");
	if (error != 0) {
		const git_error *err = giterr_last();
		if (err) printf("ERROR %d: %s\n", err->klass, err->message);
		else printf("ERROR %d: no detailed info\n", error);
	}
	else if (cloned_repo) git_repository_free(cloned_repo);
	return error;
}
Exemplo n.º 24
0
bool QGit::gitRepositoryDefaultSignature(const QDir &path, QString &name, QString &email)
{
    git_repository *repo = nullptr;
    git_signature *me = nullptr;
    int result = 0;
    bool ret = false;

    result = git_repository_open(&repo, path.absolutePath().toUtf8().constData());
    if (result)
    {
        goto cleanup;
    }

    result = git_signature_default(&me, repo);
    if (result)
    {
        goto cleanup;
    }

    name = me->name;
    email = me->email;

    ret = true;

cleanup:
    if (me)
    {
        git_signature_free(me);
        me = nullptr;
    }

    if (repo)
    {
        git_repository_free(repo);
        repo = nullptr;
    }

    return ret;
}
Exemplo n.º 25
0
/**
 * Make the repository HEAD point to the specified reference.
 *
 * @param repo S4 class git_repository
 * @param ref_name Canonical name of the reference the HEAD should point at
 * @return R_NilValue
 */
SEXP git2r_repository_set_head(SEXP repo, SEXP ref_name)
{
    int err;
    git_repository *repository = NULL;

    if (git2r_arg_check_string(ref_name))
        git2r_error(git2r_err_string_arg, __func__, "ref_name");

    repository = git2r_repository_open(repo);
    if (!repository)
        git2r_error(git2r_err_invalid_repository, __func__, NULL);

    err = git_repository_set_head(repository, CHAR(STRING_ELT(ref_name, 0)));

    if (repository)
        git_repository_free(repository);

    if (GIT_OK != err)
        git2r_error(git2r_err_from_libgit2, __func__, giterr_last()->message);

    return R_NilValue;
}
Exemplo n.º 26
0
int main (int argc, char** argv)
{
	git_index_matched_path_cb matched_cb = NULL;
	git_repository *repo = NULL;
	git_index *index;
	git_strarray array = {0};
	int options = 0, count = 0;
	struct print_payload payload = {0};

	git_threads_init();

	parse_opts(&options, &count, argc, argv);

	init_array(&array, argc-count, argv+count);

	check_lg2(git_repository_open(&repo, "."), "No git repository", NULL);
	check_lg2(git_repository_index(&index, repo), "Could not open repository index", NULL);

	if (options&VERBOSE || options&SKIP) {
		matched_cb = &print_matched_cb;
	}

	payload.options = options;
	payload.repo = repo;

	if (options&UPDATE) {
		git_index_update_all(index, &array, matched_cb, &payload);
	} else {
		git_index_add_all(index, &array, 0, matched_cb, &payload);
	}

	git_index_write(index);
	git_index_free(index);
	git_repository_free(repo);

	git_threads_shutdown();

	return 0;
}
Exemplo n.º 27
0
/**
 * Check if repository is bare.
 *
 * @param repo S4 class git_repository
 * @return TRUE if bare else FALSE
 */
SEXP git2r_repository_is_bare(SEXP repo)
{
    SEXP result;
    int is_bare;
    git_repository *repository;

    repository= git2r_repository_open(repo);
    if (!repository)
        git2r_error(git2r_err_invalid_repository, __func__, NULL);

    is_bare = git_repository_is_bare(repository);
    git_repository_free(repository);

    PROTECT(result = allocVector(LGLSXP, 1));
    if (1 == is_bare)
        LOGICAL(result)[0] = 1;
    else
        LOGICAL(result)[0] = 0;
    UNPROTECT(1);

    return result;
}
Exemplo n.º 28
0
void test_repo_open__open_with_discover(void)
{
	static const char *variants[] = {
		"attr", "attr/", "attr/.git", "attr/.git/",
		"attr/sub", "attr/sub/", "attr/sub/sub", "attr/sub/sub/",
		NULL
	};
	git_repository *repo;
	const char **scan;

	cl_fixture_sandbox("attr");
	cl_git_pass(p_rename("attr/.gitted", "attr/.git"));

	for (scan = variants; *scan != NULL; scan++) {
		cl_git_pass(git_repository_open_ext(&repo, *scan, 0, NULL));
		cl_assert(git__suffixcmp(git_repository_path(repo), "attr/.git/") == 0);
		cl_assert(git__suffixcmp(git_repository_workdir(repo), "attr/") == 0);
		git_repository_free(repo);
	}

	cl_fixture_cleanup("attr");
}
Exemplo n.º 29
0
/**
 * Remove an existing remote
 *
 * All remote-tracking branches and configuration settings for the
 * remote will be removed.
 * @param repo S4 class git_repository
 * @param name The name of the remote to remove
 * @return R_NilValue
 */
SEXP git2r_remote_remove(SEXP repo, SEXP name)
{
    int err;
    git_repository *repository = NULL;

    if (git2r_arg_check_string(name))
        git2r_error(__func__, NULL, "'name'", git2r_err_string_arg);

    repository = git2r_repository_open(repo);
    if (!repository)
        git2r_error(__func__, NULL, git2r_err_invalid_repository, NULL);

    err = git_remote_delete(repository, CHAR(STRING_ELT(name, 0)));

    if (repository)
	git_repository_free(repository);

    if (err)
	git2r_error(__func__, giterr_last(), NULL, NULL);

    return R_NilValue;
}
Exemplo n.º 30
0
/**
 * Check if valid repository.
 *
 * @param path The path to the potential repository
 * @return TRUE if the repository can be opened else FALSE
 */
SEXP git2r_repository_can_open(SEXP path)
{
    SEXP result;
    int can_open;
    git_repository *repository = NULL;

    if (git2r_arg_check_string(path))
        git2r_error(git2r_err_string_arg, __func__, "path");

    can_open = git_repository_open(&repository, CHAR(STRING_ELT(path, 0)));
    if (repository)
        git_repository_free(repository);

    PROTECT(result = allocVector(LGLSXP, 1));
    if (0 != can_open)
        LOGICAL(result)[0] = 0;
    else
        LOGICAL(result)[0] = 1;
    UNPROTECT(1);

    return result;
}