Beispiel #1
0
 void Index::add_all(git_strarray const & pathspec, matched_path_callback_t cb, unsigned int flags)
 {
     int res = cb
                   ? git_index_add_all(index_.get(), &pathspec, flags, &apply_callback, &cb)
                   : git_index_add_all(index_.get(), &pathspec, flags, nullptr, nullptr);
     assert(res == 0);
 }
Beispiel #2
0
bool GitWrapper::commitPattern(git_repository* repo, QString pattern, QString message)
{
    git_index *index = NULL;
    int error = git_repository_index(&index, repo);
    if(error < 0)
    {
        gitErrorHandling();
        return false;
    }


    QByteArray patternba = pattern.toUtf8();
    char *patternCString = patternba.data();
    git_strarray arr = { &patternCString, 1};
    error = git_index_add_all(index, &arr, 0, 0, 0);
    if(error < 0)
    {
        gitErrorHandling();
        return false;
    }

    bool result = commitIndex(repo,index, message);

    git_index_free(index);

    return true;
}
Beispiel #3
0
void test_index_addall__removes_deleted_conflicted_files(void)
{
	git_index *index;
	git_reference *ref;
	git_annotated_commit *annotated;

	g_repo = cl_git_sandbox_init("merge-resolve");
	cl_git_pass(git_repository_index(&index, g_repo));

	check_status(g_repo, 0, 0, 0, 0, 0, 0, 0, 0);

	cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/branch"));
	cl_git_pass(git_annotated_commit_from_ref(&annotated, g_repo, ref));

	cl_git_pass(git_merge(g_repo, &annotated, 1, NULL, NULL));
	check_status(g_repo, 0, 1, 2, 0, 0, 0, 0, 1);

	cl_git_rmfile("merge-resolve/conflicting.txt");

	cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL));
	check_status(g_repo, 0, 2, 2, 0, 0, 0, 0, 0);

	git_annotated_commit_free(annotated);
	git_reference_free(ref);
	git_index_free(index);
}
Beispiel #4
0
void test_index_addall__files_in_folders(void)
{
	git_index *index;
	git_strarray paths = { NULL, 0 };

	addall_create_test_repo(true);

	cl_git_pass(git_repository_index(&index, g_repo));

	cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL));
	check_stat_data(index, TEST_DIR "/file.bar", true);
	check_status(g_repo, 2, 0, 0, 0, 0, 0, 1, 0);

	cl_must_pass(p_mkdir(TEST_DIR "/subdir", 0777));
	cl_git_mkfile(TEST_DIR "/subdir/file", "hello!\n");
	check_status(g_repo, 2, 0, 0, 1, 0, 0, 1, 0);

	cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL));
	check_status(g_repo, 3, 0, 0, 0, 0, 0, 1, 0);

	git_index_free(index);
}
Beispiel #5
0
static int git_add(char *path)
{
	git_index *index;
	char *file;

	file = get_file(path);

	char *paths[] = {file};
	git_strarray array = {paths, 1};
	git_repository_index(&index, repo);

	git_index_add_all(index, &array, 0, NULL, NULL);
	git_index_write(index);
	git_index_free(index);

	return 0;
}
Beispiel #6
0
PyObject *
Index_add_all(Index *self, PyObject *pylist)
{
    int err;
    git_strarray pathspec;

    if (get_strarraygit_from_pylist(&pathspec, pylist) < 0)
        return NULL;

    err = git_index_add_all(self->index, &pathspec, 0, NULL, NULL);
    git_strarray_free(&pathspec);

    if (err < 0) {
        Error_set(err);
        return NULL;
    }

    Py_RETURN_NONE;
}
Beispiel #7
0
/**
 * Creates a git tree object representing the state of the working directory.
 */
static int sync_workdir_tree(git_oid *out,
                             git_repository *repo)
{
    int e = 0;
    git_index *index = NULL;

    git_check(git_repository_index(&index, repo));
    git_check(git_index_clear(index));
    git_strarray paths = {NULL, 0};
    git_check(git_index_add_all(index, &paths, 0, NULL, NULL));
    git_check(git_index_write_tree(out, index));
    if (!git_repository_is_bare(repo))
    {
        git_check(git_index_write(index));
    }

exit:
    if (index)          git_index_free(index);
    return e;
}
Beispiel #8
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;
}
Beispiel #9
0
/*
 *  call-seq:
 *    index.add_all(pathspec = [][, options])                            -> nil
 *    index.add_all(pathspec = [][, options]) { |path, pathspec| block } -> nil
 *
 *  Add or update index entries matching files in the working directory.
 *
 *  Searches the working directory for files that +pathspec+ and adds them
 *  to +index+ (by updating an existing entry or adding a new entry).
 *
 *  +pathspec+ can either be a String, or an Array of Strings.
 *  If +pathspec+ is empty, all entries in the index will be matched.
 *
 *  Files that are ignored due to +.gitignore+ rules will be skipped,
 *  unless they're already have an entry in +index+.
 *
 *  Files that are marked as the result of a merge request, will have this
 *  marking removed and the merge conflict information will be moved into the
 *  "resolve undo" (REUC) section of +index+.
 *
 *  If a block is given, each matched +path+ and the +pathspec+ that matched
 *  it will be passed to the block. If the return value of +block+ is
 *  falsy, the matching item will not be added to the index.
 *
 *  This method will fail in bare index instances.
 *
 *  The following options can be passed in the +options+ Hash:
 *
 *  :force ::
 *    If +true+, any +.gitignore+ rules will be ignored.
 *
 *  :disable_pathspec_match ::
 *    If +true+, glob expansion will be disabled and exact matching will be forced.
 *
 *  :check_pathspec ::
 *    If +true+, and the +:force+ options is +false+ or not given, exact matches
 *    of ignored files or files that are not already in +index+ will raise a
 *    Rugged::InvalidError. This emulates <code>git add -A</code>.
 */
static VALUE rb_git_index_add_all(int argc, VALUE *argv, VALUE self)
{
	VALUE rb_pathspecs, rb_options;

	git_index *index;
	git_strarray pathspecs;
	int error, exception = 0;
	unsigned int flags = GIT_INDEX_ADD_DEFAULT;

	Data_Get_Struct(self, git_index, index);

	if (rb_scan_args(argc, argv, "02", &rb_pathspecs, &rb_options) > 1) {
		Check_Type(rb_options, T_HASH);

		if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("force"))))
			flags |= GIT_INDEX_ADD_FORCE;

		if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("disable_pathspec_match"))))
			flags |= GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH;

		if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("check_pathspec"))))
			flags |= GIT_INDEX_ADD_CHECK_PATHSPEC;
	}

	rugged_rb_ary_to_strarray(rb_pathspecs, &pathspecs);

	error = git_index_add_all(index, &pathspecs, flags,
		rb_block_given_p() ? rugged__index_matched_path_cb : NULL, &exception);

	xfree(pathspecs.strings);

	if (exception)
		rb_jump_tag(exception);

	rugged_exception_check(error);
	return Qnil;
}
Beispiel #10
0
void MainWindow::on_pushButtonCommit_clicked()
{
    if (repo != NULL)
    {
        QString filepath = ui->textRepoLocation->text();
        QFile myfile(filepath+ "/test.txt");
        if (myfile.open(QFile::WriteOnly))
        {
            QTextStream out(&myfile);
            out << ui->textContent->toPlainText();
        }

        //add to index
        git_strarray array = {0};
        git_index* index;
        struct print_payload payload;
        git_repository_index(&index, repo);
        git_index_add_all(index, &array, 0, NULL, &payload);

        git_index_write(index);
        //note2self: the above simply writes

        //now, do a commit!


        //random: list references
        git_strarray refs = {0};
        int error = git_reference_list(&refs, repo);
        for (int i=0; i<refs.count; i++)
        {
            qDebug() << "ref " <<i<<" = "<< refs.strings[i];
        }
        //end random: list references

        //for a commit, we need:
        // -repo (obviously)
        // - name of ref (usually "HEAD")
        // - author commiter sig
        // - encoding+ message
        // - root tree (pointer
        // - parent count+parents (why? can have multiple parents)

        git_tree *tree;
        git_oid tree_id, parent_id, commit_id;



        error = git_index_write_tree(&tree_id, index); //we need to put index into a tree object for commit
        error = git_tree_lookup(&tree, repo, &tree_id);

        //tree_id = *git_object_id((git_object*)tree);
        git_commit *parent;

        //get HEAD and use it as parent of commit, put it in parent
        error  = git_reference_name_to_id(&parent_id, repo, "HEAD");
        error = git_commit_lookup(&parent, repo, &parent_id);


        //do commit
        git_signature* sig;
        git_signature_now(&sig, "johnty", "*****@*****.**");

        const char* msg = "Test Commit Message";

        git_commit_create_v(
                    &commit_id,
                    repo,
                    "HEAD",
                    sig,
                    sig,
                    NULL,
                    msg,
                    tree,
                    1,
                    parent
                    );


        git_index_free(index);
        git_signature_free(sig);
        git_tree_free(tree);
        git_commit_free(parent);
        //QMessageBox::information(this, tr("commit"), tr("commit successful"));
    }
}
Beispiel #11
0
void test_index_addall__callback_filtering(void)
{
	git_index *index;

	addall_create_test_repo(false);

	cl_git_pass(git_repository_index(&index, g_repo));

	cl_git_pass(
		git_index_add_all(index, NULL, 0, addall_match_prefix, "file."));
	check_stat_data(index, TEST_DIR "/file.bar", true);
	check_status(g_repo, 1, 0, 0, 1, 0, 0, 1);

	cl_git_mkfile(TEST_DIR "/file.zzz", "yet another one");
	cl_git_mkfile(TEST_DIR "/more.zzz", "yet another one");
	cl_git_mkfile(TEST_DIR "/other.zzz", "yet another one");

	cl_git_pass(git_index_update_all(index, NULL, NULL, NULL));
	check_stat_data(index, TEST_DIR "/file.bar", true);
	check_status(g_repo, 1, 0, 0, 4, 0, 0, 1);

	cl_git_pass(
		git_index_add_all(index, NULL, 0, addall_match_prefix, "other"));
	check_stat_data(index, TEST_DIR "/other.zzz", true);
	check_status(g_repo, 2, 0, 0, 3, 0, 0, 1);

	cl_git_pass(
		git_index_add_all(index, NULL, 0, addall_match_suffix, ".zzz"));
	check_status(g_repo, 4, 0, 0, 1, 0, 0, 1);

	cl_git_pass(
		git_index_remove_all(index, NULL, addall_match_suffix, ".zzz"));
	check_status(g_repo, 1, 0, 0, 4, 0, 0, 1);

	cl_git_fail_with(
		git_index_add_all(index, NULL, 0, addall_cancel_at, "more.zzz"), -123);
	check_status(g_repo, 3, 0, 0, 2, 0, 0, 1);

	cl_git_fail_with(
		git_index_add_all(index, NULL, 0, addall_cancel_at, "other.zzz"), -123);
	check_status(g_repo, 4, 0, 0, 1, 0, 0, 1);

	cl_git_pass(
		git_index_add_all(index, NULL, 0, addall_match_suffix, ".zzz"));
	check_status(g_repo, 5, 0, 0, 0, 0, 0, 1);

	cl_must_pass(p_unlink(TEST_DIR "/file.zzz"));
	cl_must_pass(p_unlink(TEST_DIR "/more.zzz"));
	cl_must_pass(p_unlink(TEST_DIR "/other.zzz"));

	cl_git_fail_with(
		git_index_update_all(index, NULL, addall_cancel_at, "more.zzz"), -123);
	/* file.zzz removed from index (so Index Adds 5 -> 4) and
	 * more.zzz + other.zzz removed (so Worktree Dels 0 -> 2) */
	check_status(g_repo, 4, 0, 0, 0, 2, 0, 1);

	cl_git_fail_with(
		git_index_update_all(index, NULL, addall_cancel_at, "other.zzz"), -123);
	/* more.zzz removed from index (so Index Adds 4 -> 3) and
	 * Just other.zzz removed (so Worktree Dels 2 -> 1) */
	check_status(g_repo, 3, 0, 0, 0, 1, 0, 1);

	git_index_free(index);
}
Beispiel #12
0
void test_index_addall__repo_lifecycle(void)
{
	int error;
	git_index *index;
	git_strarray paths = { NULL, 0 };
	char *strs[1];

	addall_create_test_repo(true);

	cl_git_pass(git_repository_index(&index, g_repo));

	strs[0] = "file.*";
	paths.strings = strs;
	paths.count   = 1;

	cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL));
	check_stat_data(index, TEST_DIR "/file.bar", true);
	check_status(g_repo, 1, 0, 0, 1, 0, 0, 1);

	cl_git_rewritefile(TEST_DIR "/file.bar", "new content for file");
	check_stat_data(index, TEST_DIR "/file.bar", false);
	check_status(g_repo, 1, 0, 0, 1, 0, 1, 1);

	cl_git_mkfile(TEST_DIR "/file.zzz", "yet another one");
	cl_git_mkfile(TEST_DIR "/other.zzz", "yet another one");
	cl_git_mkfile(TEST_DIR "/more.zzz", "yet another one");
	check_status(g_repo, 1, 0, 0, 4, 0, 1, 1);

	cl_git_pass(git_index_update_all(index, NULL, NULL, NULL));
	check_stat_data(index, TEST_DIR "/file.bar", true);
	check_status(g_repo, 1, 0, 0, 4, 0, 0, 1);

	cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL));
	check_stat_data(index, TEST_DIR "/file.zzz", true);
	check_status(g_repo, 2, 0, 0, 3, 0, 0, 1);

	cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "first commit");
	check_status(g_repo, 0, 0, 0, 3, 0, 0, 1);

	/* attempt to add an ignored file - does nothing */
	strs[0] = "file.foo";
	cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL));
	check_status(g_repo, 0, 0, 0, 3, 0, 0, 1);

	/* add with check - should generate error */
	error = git_index_add_all(
		index, &paths, GIT_INDEX_ADD_CHECK_PATHSPEC, NULL, NULL);
	cl_assert_equal_i(GIT_EINVALIDSPEC, error);
	check_status(g_repo, 0, 0, 0, 3, 0, 0, 1);

	/* add with force - should allow */
	cl_git_pass(git_index_add_all(
		index, &paths, GIT_INDEX_ADD_FORCE, NULL, NULL));
	check_stat_data(index, TEST_DIR "/file.foo", true);
	check_status(g_repo, 1, 0, 0, 3, 0, 0, 0);

	/* now it's in the index, so regular add should work */
	cl_git_rewritefile(TEST_DIR "/file.foo", "new content for file");
	check_stat_data(index, TEST_DIR "/file.foo", false);
	check_status(g_repo, 1, 0, 0, 3, 0, 1, 0);

	cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL));
	check_stat_data(index, TEST_DIR "/file.foo", true);
	check_status(g_repo, 1, 0, 0, 3, 0, 0, 0);

	cl_git_pass(git_index_add_bypath(index, "more.zzz"));
	check_stat_data(index, TEST_DIR "/more.zzz", true);
	check_status(g_repo, 2, 0, 0, 2, 0, 0, 0);

	cl_git_rewritefile(TEST_DIR "/file.zzz", "new content for file");
	check_status(g_repo, 2, 0, 0, 2, 0, 1, 0);

	cl_git_pass(git_index_add_bypath(index, "file.zzz"));
	check_stat_data(index, TEST_DIR "/file.zzz", true);
	check_status(g_repo, 2, 0, 1, 2, 0, 0, 0);

	strs[0] = "*.zzz";
	cl_git_pass(git_index_remove_all(index, &paths, NULL, NULL));
	check_status(g_repo, 1, 1, 0, 4, 0, 0, 0);

	cl_git_pass(git_index_add_bypath(index, "file.zzz"));
	check_status(g_repo, 1, 0, 1, 3, 0, 0, 0);

	cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "second commit");
	check_status(g_repo, 0, 0, 0, 3, 0, 0, 0);

	cl_must_pass(p_unlink(TEST_DIR "/file.zzz"));
	check_status(g_repo, 0, 0, 0, 3, 1, 0, 0);

	/* update_all should be able to remove entries */
	cl_git_pass(git_index_update_all(index, NULL, NULL, NULL));
	check_status(g_repo, 0, 1, 0, 3, 0, 0, 0);

	strs[0] = "*";
	cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL));
	check_status(g_repo, 3, 1, 0, 0, 0, 0, 0);

	/* must be able to remove at any position while still updating other files */
	cl_must_pass(p_unlink(TEST_DIR "/.gitignore"));
	cl_git_rewritefile(TEST_DIR "/file.zzz", "reconstructed file");
	cl_git_rewritefile(TEST_DIR "/more.zzz", "altered file reality");
	check_status(g_repo, 3, 1, 0, 1, 1, 1, 0);

	cl_git_pass(git_index_update_all(index, NULL, NULL, NULL));
	check_status(g_repo, 2, 1, 0, 1, 0, 0, 0);
	/* this behavior actually matches 'git add -u' where "file.zzz" has
	 * been removed from the index, so when you go to update, even though
	 * it exists in the HEAD, it is not re-added to the index, leaving it
	 * as a DELETE when comparing HEAD to index and as an ADD comparing
	 * index to worktree
	 */

	git_index_free(index);
}
Beispiel #13
0
void GitWrapper::commitBasket(BasketScene *basket)
{
    GIT_RETURN_IF_DISABLED()
    QMutexLocker l(&gitMutex);
    git_repository* repo = openRepository();
    if(repo==0)
        return;

    const QDateTime gitdate = getLastCommitDate(repo);

    const QString fullpath = basket->fullPath();
    const QDir basketdir(fullpath);
    bool changed = false;
    QDirIterator it(basketdir);
    while(!changed && it.hasNext())
    {
        const QFileInfo file(it.next());
        if(file.fileName() != ".basket")
        {
            if(file.lastModified() >= gitdate)
                changed = true;
        }
    }

    if(changed)
    {
        git_index *index = NULL;

        int error = git_repository_index(&index, repo);
        if(error < 0)
        {
            gitErrorHandling();
            return;
        }

        const QString pattern("baskets/" + basket->folderName() + "*");

        QByteArray patternba = pattern.toUtf8();
        char *patternCString = patternba.data();
        git_strarray arr = { &patternCString, 1};
        error = git_index_add_all(index, &arr, 0, 0, 0);
        if(error < 0)
        {
            gitErrorHandling();
            return;
        }
        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;
        }

        removeDeletedFromIndex(repo,index);

        bool result = commitIndex(repo,index);

        git_index_free(index);
    }

    git_repository_free(repo);
}