コード例 #1
0
ファイル: tests.c プロジェクト: 1336/libgit2
void test_index_tests__remove_entry(void)
{
	git_repository *repo;
	git_index *index;

	p_mkdir("index_test", 0770);

	cl_git_pass(git_repository_init(&repo, "index_test", 0));
	cl_git_pass(git_repository_index(&index, repo));
	cl_assert(git_index_entrycount(index) == 0);

	cl_git_mkfile("index_test/hello", NULL);
	cl_git_pass(git_index_add_bypath(index, "hello"));
	cl_git_pass(git_index_write(index));

	cl_git_pass(git_index_read(index, true)); /* reload */
	cl_assert(git_index_entrycount(index) == 1);
	cl_assert(git_index_get_bypath(index, "hello", 0) != NULL);

	cl_git_pass(git_index_remove(index, "hello", 0));
	cl_git_pass(git_index_write(index));

	cl_git_pass(git_index_read(index, true)); /* reload */
	cl_assert(git_index_entrycount(index) == 0);
	cl_assert(git_index_get_bypath(index, "hello", 0) == NULL);

	git_index_free(index);
	git_repository_free(repo);
	cl_fixture_cleanup("index_test");
}
コード例 #2
0
ファイル: tests.c プロジェクト: 1336/libgit2
void test_index_tests__remove_directory(void)
{
	git_repository *repo;
	git_index *index;

	p_mkdir("index_test", 0770);

	cl_git_pass(git_repository_init(&repo, "index_test", 0));
	cl_git_pass(git_repository_index(&index, repo));
	cl_assert_equal_i(0, (int)git_index_entrycount(index));

	p_mkdir("index_test/a", 0770);
	cl_git_mkfile("index_test/a/1.txt", NULL);
	cl_git_mkfile("index_test/a/2.txt", NULL);
	cl_git_mkfile("index_test/a/3.txt", NULL);
	cl_git_mkfile("index_test/b.txt", NULL);

	cl_git_pass(git_index_add_bypath(index, "a/1.txt"));
	cl_git_pass(git_index_add_bypath(index, "a/2.txt"));
	cl_git_pass(git_index_add_bypath(index, "a/3.txt"));
	cl_git_pass(git_index_add_bypath(index, "b.txt"));
	cl_git_pass(git_index_write(index));

	cl_git_pass(git_index_read(index, true)); /* reload */
	cl_assert_equal_i(4, (int)git_index_entrycount(index));
	cl_assert(git_index_get_bypath(index, "a/1.txt", 0) != NULL);
	cl_assert(git_index_get_bypath(index, "a/2.txt", 0) != NULL);
	cl_assert(git_index_get_bypath(index, "b.txt", 0) != NULL);

	cl_git_pass(git_index_remove(index, "a/1.txt", 0));
	cl_git_pass(git_index_write(index));

	cl_git_pass(git_index_read(index, true)); /* reload */
	cl_assert_equal_i(3, (int)git_index_entrycount(index));
	cl_assert(git_index_get_bypath(index, "a/1.txt", 0) == NULL);
	cl_assert(git_index_get_bypath(index, "a/2.txt", 0) != NULL);
	cl_assert(git_index_get_bypath(index, "b.txt", 0) != NULL);

	cl_git_pass(git_index_remove_directory(index, "a", 0));
	cl_git_pass(git_index_write(index));

	cl_git_pass(git_index_read(index, true)); /* reload */
	cl_assert_equal_i(1, (int)git_index_entrycount(index));
	cl_assert(git_index_get_bypath(index, "a/1.txt", 0) == NULL);
	cl_assert(git_index_get_bypath(index, "a/2.txt", 0) == NULL);
	cl_assert(git_index_get_bypath(index, "b.txt", 0) != NULL);

	git_index_free(index);
	git_repository_free(repo);
	cl_fixture_cleanup("index_test");
}
コード例 #3
0
ファイル: tests.c プロジェクト: 1336/libgit2
void test_index_tests__reload_from_disk(void)
{
	git_repository *repo;
	git_index *read_index;
	git_index *write_index;

	cl_set_cleanup(&cleanup_myrepo, NULL);

	cl_git_pass(git_futils_mkdir("./myrepo", NULL, 0777, GIT_MKDIR_PATH));
	cl_git_mkfile("./myrepo/a.txt", "a\n");
	cl_git_mkfile("./myrepo/b.txt", "b\n");

	cl_git_pass(git_repository_init(&repo, "./myrepo", 0));
	cl_git_pass(git_repository_index(&write_index, repo));
	cl_assert_equal_i(false, write_index->on_disk);

	cl_git_pass(git_index_open(&read_index, write_index->index_file_path));
	cl_assert_equal_i(false, read_index->on_disk);

	/* Stage two new files against the write_index */
	cl_git_pass(git_index_add_bypath(write_index, "a.txt"));
	cl_git_pass(git_index_add_bypath(write_index, "b.txt"));

	cl_assert_equal_sz(2, git_index_entrycount(write_index));

	/* Persist the index changes to disk */
	cl_git_pass(git_index_write(write_index));
	cl_assert_equal_i(true, write_index->on_disk);

	/* Sync the changes back into the read_index */
	cl_assert_equal_sz(0, git_index_entrycount(read_index));

	cl_git_pass(git_index_read(read_index, true));
	cl_assert_equal_i(true, read_index->on_disk);

	cl_assert_equal_sz(2, git_index_entrycount(read_index));

	/* Remove the index file from the filesystem */
	cl_git_pass(p_unlink(write_index->index_file_path));

	/* Sync the changes back into the read_index */
	cl_git_pass(git_index_read(read_index, true));
	cl_assert_equal_i(false, read_index->on_disk);
	cl_assert_equal_sz(0, git_index_entrycount(read_index));

	git_index_free(read_index);
	git_index_free(write_index);
	git_repository_free(repo);
}
コード例 #4
0
ファイル: nsec.c プロジェクト: 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);
	}
}
コード例 #5
0
ファイル: names.c プロジェクト: DaneTheory/libgit2
void test_index_names__roundtrip(void)
{
	const git_index_name_entry *conflict_name;

	cl_git_pass(git_index_name_add(repo_index, "ancestor", "ours", "theirs"));
	cl_git_pass(git_index_name_add(repo_index, "ancestor2", "ours2", NULL));
	cl_git_pass(git_index_name_add(repo_index, "ancestor3", NULL, "theirs3"));

	cl_git_pass(git_index_write(repo_index));
	git_index_clear(repo_index);
	cl_assert(git_index_name_entrycount(repo_index) == 0);

	cl_git_pass(git_index_read(repo_index, true));
	cl_assert(git_index_name_entrycount(repo_index) == 3);

	conflict_name = git_index_name_get_byindex(repo_index, 0);
	cl_assert(strcmp(conflict_name->ancestor, "ancestor") == 0);
	cl_assert(strcmp(conflict_name->ours, "ours") == 0);
	cl_assert(strcmp(conflict_name->theirs, "theirs") == 0);

	conflict_name = git_index_name_get_byindex(repo_index, 1);
	cl_assert(strcmp(conflict_name->ancestor, "ancestor2") == 0);
	cl_assert(strcmp(conflict_name->ours, "ours2") == 0);
	cl_assert(conflict_name->theirs == NULL);

	conflict_name = git_index_name_get_byindex(repo_index, 2);
	cl_assert(strcmp(conflict_name->ancestor, "ancestor3") == 0);
	cl_assert(conflict_name->ours == NULL);
	cl_assert(strcmp(conflict_name->theirs, "theirs3") == 0);
}
コード例 #6
0
ファイル: index.c プロジェクト: boyski/libgit2
static int index_initialize(git_index **index_out, git_repository *owner, const char *index_path)
{
	git_index *index;

	assert(index_out && index_path);

	index = git__malloc(sizeof(git_index));
	if (index == NULL)
		return GIT_ENOMEM;

	memset(index, 0x0, sizeof(git_index));

	index->index_file_path = git__strdup(index_path);
	if (index->index_file_path == NULL) {
		free(index);
		return GIT_ENOMEM;
	}

	index->repository = owner;

	git_vector_init(&index->entries, 32, index_cmp);

	/* Check if index file is stored on disk already */
	if (git_futils_exists(index->index_file_path) == 0)
		index->on_disk = 1;

	*index_out = index;
	return git_index_read(index);
}
コード例 #7
0
ファイル: index.cpp プロジェクト: AndreyG/libgit2cpp
 Index::Index(const char * dir)
 {
     git_index * index;
     if (git_index_open(&index, dir))
         throw index_open_error();
     index_.reset(index);
     git_index_read(index, true);
 }
コード例 #8
0
ファイル: tests.c プロジェクト: 1336/libgit2
void test_index_tests__reload_while_ignoring_case(void)
{
	git_index *index;
	unsigned int caps;

	cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
	cl_git_pass(git_vector_verify_sorted(&index->entries));

	caps = git_index_caps(index);
	cl_git_pass(git_index_set_caps(index, caps &= ~GIT_INDEXCAP_IGNORE_CASE));
	cl_git_pass(git_index_read(index, true));
	cl_git_pass(git_vector_verify_sorted(&index->entries));

	cl_git_pass(git_index_set_caps(index, caps | GIT_INDEXCAP_IGNORE_CASE));
	cl_git_pass(git_index_read(index, true));
	cl_git_pass(git_vector_verify_sorted(&index->entries));

	git_index_free(index);
}
コード例 #9
0
ファイル: checkout_helpers.c プロジェクト: Angeldude/sonic-pi
void tick_index(git_index *index)
{
	struct timespec ts;
	struct p_timeval times[2];

	cl_assert(index->on_disk);
	cl_assert(git_index_path(index));

	cl_git_pass(git_index_read(index, true));
	ts = index->stamp.mtime;

	times[0].tv_sec = ts.tv_sec;
	times[0].tv_usec = ts.tv_nsec / 1000;
	times[1].tv_sec = ts.tv_sec + 5;
	times[1].tv_usec = ts.tv_nsec / 1000;

	cl_git_pass(p_utimes(git_index_path(index), times));
	cl_git_pass(git_index_read(index, true));
}
コード例 #10
0
ファイル: nsec.c プロジェクト: 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);
}
コード例 #11
0
ファイル: index.c プロジェクト: guocb/pygit2
PyObject *
Index_read(Index *self)
{
    int err;

    err = git_index_read(self->index);
    if (err < GIT_OK)
        return Error_set(err);

    Py_RETURN_NONE;
}
コード例 #12
0
ファイル: rugged_index.c プロジェクト: mkanoor/rugged
/*
 *  call-seq:
 *    index.reload -> nil
 *
 *  Reloads the index contents from the disk, discarding any changes that
 *  have not been saved through #write.
 */
static VALUE rb_git_index_read(VALUE self)
{
	git_index *index;
	int error;

	Data_Get_Struct(self, git_index, index);

	error = git_index_read(index, 0);
	rugged_exception_check(error);

	return Qnil;
}
コード例 #13
0
ファイル: showindex.c プロジェクト: ralpheav/PM_GIT
int main (int argc, char** argv)
{
	git_repository *repo;
	git_index *index;
	unsigned int i, ecount;
	char *dir = ".";
	char out[41];
	out[40] = '\0';

	if (argc > 1)
		dir = argv[1];
	if (argc > 2) {
		fprintf(stderr, "usage: showindex [<repo-dir>]\n");
		return 1;
	}

	if (git_repository_open_ext(&repo, dir, 0, NULL) < 0) {
		fprintf(stderr, "could not open repository: %s\n", dir);
		return 1;
	}

	git_repository_index(&index, repo);
	git_index_read(index);

	ecount = git_index_entrycount(index);
	if (!ecount)
		printf("Empty index\n");

	for (i = 0; i < ecount; ++i) {
		const git_index_entry *e = git_index_get_byindex(index, i);

		git_oid_fmt(out, &e->oid);

		printf("File Path: %s\n", e->path);
		printf("    Stage: %d\n", git_index_entry_stage(e));
		printf(" Blob SHA: %s\n", out);
		printf("File Size: %d\n", (int)e->file_size);
		printf("   Device: %d\n", (int)e->dev);
		printf("    Inode: %d\n", (int)e->ino);
		printf("      UID: %d\n", (int)e->uid);
		printf("      GID: %d\n", (int)e->gid);
		printf("    ctime: %d\n", (int)e->ctime.seconds);
		printf("    mtime: %d\n", (int)e->mtime.seconds);
		printf("\n");
	}

	git_index_free(index);
	git_repository_free(repo);

	return 0;
}
コード例 #14
0
ファイル: index.c プロジェクト: flowroute/pygit2
PyObject *
Index_read(Index *self, PyObject *args)
{
    int err, force = 1;

    if (!PyArg_ParseTuple(args, "|i", &force))
        return NULL;

    err = git_index_read(self->index, force);
    if (err < GIT_OK)
        return Error_set(err);

    Py_RETURN_NONE;
}
コード例 #15
0
ファイル: racy.c プロジェクト: ethomson/libgit2
void test_index_racy__write_index_just_after_file(void)
{
	git_index *index;
	git_diff *diff;
	git_buf path = GIT_BUF_INIT;
	struct p_timeval times[2];

	/* Make sure we do have a timestamp */
	cl_git_pass(git_repository_index(&index, g_repo));
	cl_git_pass(git_index_write(index));

	cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A"));
	cl_git_mkfile(path.ptr, "A");
	/* Force the file's timestamp to be a second after we wrote the index */
	times[0].tv_sec = index->stamp.mtime.tv_sec + 1;
	times[0].tv_usec = index->stamp.mtime.tv_nsec / 1000;
	times[1].tv_sec = index->stamp.mtime.tv_sec + 1;
	times[1].tv_usec = index->stamp.mtime.tv_nsec / 1000;
	cl_git_pass(p_utimes(path.ptr, times));

	/*
	 * Put 'A' into the index, the size field will be filled,
	 * because the index' on-disk timestamp does not match the
	 * file's timestamp.
	 */
	cl_git_pass(git_index_add_bypath(index, "A"));
	cl_git_pass(git_index_write(index));

	cl_git_mkfile(path.ptr, "B");
	/*
	 * Pretend this index' modification happened a second after the
	 * file update, and rewrite the file in that same second.
	 */
	times[0].tv_sec = index->stamp.mtime.tv_sec + 2;
	times[0].tv_usec = index->stamp.mtime.tv_nsec / 1000;
	times[1].tv_sec = index->stamp.mtime.tv_sec + 2;
	times[0].tv_usec = index->stamp.mtime.tv_nsec / 1000;

	cl_git_pass(p_utimes(git_index_path(index), times));
	cl_git_pass(p_utimes(path.ptr, times));

	cl_git_pass(git_index_read(index, true));

	cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, index, NULL));
	cl_assert_equal_i(1, git_diff_num_deltas(diff));

	git_buf_dispose(&path);
	git_diff_free(diff);
	git_index_free(index);
}
コード例 #16
0
ファイル: level1.c プロジェクト: Posnet/gpu-cuda
static int prepare_index(git_index *index, char* msg){
    git_oid index_tree;
    git_tree *head_obj;
    git_reference *head;
    char tree_str[GIT_OID_HEXSZ+1], parent_str[GIT_OID_HEXSZ+1];

    // Get the head OID
    git_repository_head(&head, repo);
    git_reference_peel((git_object**)&head_obj, head, GIT_OBJ_COMMIT);
    git_oid_tostr(parent_str, GIT_OID_HEXSZ+1,
                   git_tree_id(head_obj));

    git_reference_free(head);
    git_object_free((git_object*)head_obj);

    // Write the coin
    // TODO: Use C for this?
    system("perl -i -pe 's/(null:)(\\d+)/$1 . ($2+1)/e' LEDGER.txt");
    system("grep -q \"null\" LEDGER.txt || echo \"null:1\" >> LEDGER.txt");

    // Update the index
    check_lg2(git_index_read(index, 0),
              "Could not re-read index from disk", NULL);

    check_lg2(git_index_add_bypath(index, "LEDGER.txt"),
              "Could not add to index", "LEDGER.txt");

    // Write the index and get the tree OID
    git_index_write_tree(&index_tree, index);
    git_oid_tostr(tree_str, GIT_OID_HEXSZ+1, &index_tree);

    snprintf(msg, BUFFER_LENGTH,
             "commit %d%c"
             "tree %s\n"
             "parent %s\n"
             "author null           <*****@*****.**> %d +0000\n"
             "committer null           <*****@*****.**> %d +0000\n"
             "\n"
             "coins now"
             "\x01\x01\x01\x01"
             "\x01\x01\x01\x01"
             "\x01\x01\x01", // Align 32 bit words on GPU
             MSG_LENGTH, 0, tree_str, parent_str,
             (int)time(NULL), (int)time(NULL));
    pad_message(msg, COMMIT_LENGTH, BUFFER_LENGTH);

    return 0;
}
コード例 #17
0
ファイル: worktree.c プロジェクト: azyx3/libgit2
void test_status_worktree__update_index_with_symlink_doesnt_change_mode(void)
{
	git_repository *repo = cl_git_sandbox_init("testrepo");
	git_reference *head;
	git_object *head_object;
	git_index *index;
	const git_index_entry *idx_entry;
	git_status_options opts = GIT_STATUS_OPTIONS_INIT;
	status_entry_counts counts = {0};
	const char *expected_paths[] = { "README" };
	const unsigned int expected_statuses[] = {GIT_STATUS_WT_NEW};

	opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
	opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_UPDATE_INDEX;

	cl_git_pass(git_repository_head(&head, repo));
	cl_git_pass(git_reference_peel(&head_object, head, GIT_OBJ_COMMIT));

	cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL));

	cl_git_rewritefile("testrepo/README", "This was rewritten.");

	/* this status rewrites the index because we have changed the
	 * contents of a tracked file
	 */
	counts.expected_entry_count = 1;
	counts.expected_paths = expected_paths;
	counts.expected_statuses = expected_statuses;

	cl_git_pass(
		git_status_foreach_ext(repo, &opts, cb_status__normal, &counts));
	cl_assert_equal_i(1, counts.entry_count);

	/* now ensure that the status's rewrite of the index did not screw
	 * up the mode of the symlink `link_to_new.txt`, particularly
	 * on platforms that don't support symlinks
	 */
	cl_git_pass(git_repository_index(&index, repo));
	cl_git_pass(git_index_read(index, true));

	cl_assert(idx_entry = git_index_get_bypath(index, "link_to_new.txt", 0));
	cl_assert(S_ISLNK(idx_entry->mode));

	git_index_free(index);
	git_object_free(head_object);
	git_reference_free(head);
}
コード例 #18
0
bool AddProgressCommand::SetFileMode(uint32_t mode)
{
	CAutoRepository repo(g_Git.GetGitRepository());
	if (!repo)
	{
		MessageBox(nullptr, g_Git.GetLibGit2LastErr(L"Could not open repository."), L"TortoiseGit", MB_ICONERROR);
		return false;
	}

	CAutoIndex index;
	if (git_repository_index(index.GetPointer(), repo))
	{
		MessageBox(nullptr, g_Git.GetLibGit2LastErr(L"Could not get index."), L"TortoiseGit", MB_ICONERROR);
		return false;
	}
	if (git_index_read(index, true))
	{
		MessageBox(nullptr, g_Git.GetLibGit2LastErr(L"Could not read index."), L"TortoiseGit", MB_ICONERROR);
		return false;
	}

	for (int i = 0; i < m_targetPathList.GetCount(); ++i)
	{
		if (m_targetPathList[i].IsDirectory())
			continue;
		CStringA filePathA = CUnicodeUtils::GetMulti(m_targetPathList[i].GetGitPathString(), CP_UTF8).TrimRight(L'/');
		auto entry = const_cast<git_index_entry*>(git_index_get_bypath(index, filePathA, 0));
		entry->mode = mode;
		if (git_index_add(index, entry))
		{
			MessageBox(nullptr, g_Git.GetLibGit2LastErr(L"Could not update index."), L"TortoiseGit", MB_ICONERROR);
			return false;
		}
	}

	if (git_index_write(index))
	{
		MessageBox(nullptr, g_Git.GetLibGit2LastErr(L"Could not write index."), L"TortoiseGit", MB_ICONERROR);
		return false;
	}

	return true;
}
コード例 #19
0
//diffs workdir and index - ie unstaged changes
//equivalent to `git diff` - WORKS
int diff(git_repository* repo) {
  git_diff_list* diff;

  git_index* index;  

  git_reference* ref_head;
  git_commit* head;
  git_tree* head_tree;


  git_repository_index(&index, repo);
  git_index_read(index);

  git_repository_head(&ref_head, repo);
  git_reference_peel((git_object**) &head, ref_head, GIT_OBJ_COMMIT);
  git_commit_tree(&head_tree, head);
	git_diff_index_to_workdir(&diff, repo, index, NULL);

  print_diff(diff);

  return 0;
}
コード例 #20
0
ファイル: reuc.c プロジェクト: jmendeth/node-gitteh
void test_index_reuc__write(void)
{
	git_oid ancestor_oid, our_oid, their_oid;
	const git_index_reuc_entry *reuc;

	git_index_clear(repo_index);

	/* Write out of order to ensure sorting is correct */
	git_oid_fromstr(&ancestor_oid, TWO_ANCESTOR_OID);
	git_oid_fromstr(&our_oid, TWO_OUR_OID);
	git_oid_fromstr(&their_oid, TWO_THEIR_OID);

	cl_git_pass(git_index_reuc_add(repo_index, "two.txt",
		0100644, &ancestor_oid,
		0100644, &our_oid,
		0100644, &their_oid));

	git_oid_fromstr(&ancestor_oid, ONE_ANCESTOR_OID);
	git_oid_fromstr(&our_oid, ONE_OUR_OID);
	git_oid_fromstr(&their_oid, ONE_THEIR_OID);

	cl_git_pass(git_index_reuc_add(repo_index, "one.txt",
		0100644, &ancestor_oid,
		0100644, &our_oid,
		0100644, &their_oid));

	cl_git_pass(git_index_write(repo_index));

	cl_git_pass(git_index_read(repo_index));
	cl_assert_equal_i(2, git_index_reuc_entrycount(repo_index));

	/* ensure sort order was round-tripped correct */
	cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 0));
	cl_assert(strcmp(reuc->path, "one.txt") == 0);
	
	cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 1));
	cl_assert(strcmp(reuc->path, "two.txt") == 0);
}
コード例 #21
0
ファイル: racy.c プロジェクト: ethomson/libgit2
void test_index_racy__reading_clears_uptodate_bit(void)
{
	git_index *index;
	const git_index_entry *entry;

	setup_uptodate_files();

	cl_git_pass(git_repository_index(&index, g_repo));
	cl_git_pass(git_index_write(index));

	cl_git_pass(git_index_read(index, true));

	/* ensure that no files are uptodate */
	cl_assert((entry = git_index_get_bypath(index, "A", 0)));
	cl_assert_equal_i(0, (entry->flags_extended & GIT_INDEX_ENTRY_UPTODATE));

	cl_assert((entry = git_index_get_bypath(index, "B", 0)));
	cl_assert_equal_i(0, (entry->flags_extended & GIT_INDEX_ENTRY_UPTODATE));

	cl_assert((entry = git_index_get_bypath(index, "C", 0)));
	cl_assert_equal_i(0, (entry->flags_extended & GIT_INDEX_ENTRY_UPTODATE));

	git_index_free(index);
}
コード例 #22
0
bool AddProgressCommand::Run(CGitProgressList* list, CString& sWindowTitle, int& m_itemCountTotal, int& m_itemCount)
{
	ATLASSERT(!(m_bExecutable && m_bSymlink));
	list->SetWindowTitle(IDS_PROGRS_TITLE_ADD, g_Git.CombinePath(m_targetPathList.GetCommonRoot().GetUIPathString()), sWindowTitle);
	list->SetBackgroundImage(IDI_ADD_BKG);
	if (m_bExecutable)
		list->ReportCmd(CString(MAKEINTRESOURCE(IDS_STATUSLIST_CONTEXT_ADD_EXE)));
	else if (m_bSymlink)
		list->ReportCmd(CString(MAKEINTRESOURCE(IDS_STATUSLIST_CONTEXT_ADD_LINK)));
	else
		list->ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD)));

	m_itemCountTotal = m_targetPathList.GetCount();

	if (g_Git.UsingLibGit2(CGit::GIT_CMD_ADD))
	{
		CAutoRepository repo(g_Git.GetGitRepository());
		if (!repo)
		{
			list->ReportGitError();
			return false;
		}

		CAutoIndex index;
		if (git_repository_index(index.GetPointer(), repo))
		{
			list->ReportGitError();
			return false;
		}
		if (git_index_read(index, true))
		{
			list->ReportGitError();
			return false;
		}

		for (m_itemCount = 0; m_itemCount < m_itemCountTotal; ++m_itemCount)
		{
			CStringA filePathA = CUnicodeUtils::GetMulti(m_targetPathList[m_itemCount].GetGitPathString(), CP_UTF8).TrimRight(L'/');
			if (git_index_add_bypath(index, filePathA))
			{
				list->ReportGitError();
				return false;
			}

			if (!m_targetPathList[m_itemCount].IsDirectory() && (m_bExecutable || m_bSymlink))
			{
				auto entry = const_cast<git_index_entry*>(git_index_get_bypath(index, filePathA, 0));
				if (m_bExecutable)
					entry->mode = GIT_FILEMODE_BLOB_EXECUTABLE;
				else if (m_bSymlink)
					entry->mode = GIT_FILEMODE_LINK;
				if (git_index_add(index, entry))
				{
					list->ReportGitError();
					return false;
				}
			}

			list->AddNotify(new CGitProgressList::WC_File_NotificationData(m_targetPathList[m_itemCount], CGitProgressList::WC_File_NotificationData::git_wc_notify_add));

			if (list->IsCancelled() == TRUE)
			{
				list->ReportUserCanceled();
				return false;
			}
		}

		if (git_index_write(index))
		{
			list->ReportGitError();
			return false;
		}
	}
	else
	{
		CMassiveGitTask mgt(L"add -f");
		if (!mgt.ExecuteWithNotify(&m_targetPathList, list->m_bCancelled, CGitProgressList::WC_File_NotificationData::git_wc_notify_add, list))
			return false;
		if (m_bExecutable)
		{
			if (!SetFileMode(GIT_FILEMODE_BLOB_EXECUTABLE))
				return false;
		}
		else if (m_bSymlink)
		{
			if (!SetFileMode(GIT_FILEMODE_LINK))
				return false;
		}
	}

	CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);

	m_PostCmdCallback = [this](DWORD status, PostCmdList& postCmdList)
	{
		if (status)
			return;

		if (m_bShowCommitButtonAfterAdd)
			postCmdList.emplace_back(IDI_COMMIT, IDS_MENUCOMMIT, []
			{
				CString sCmd;
				sCmd.Format(L"/command:commit /path:\"%s\"", static_cast<LPCTSTR>(g_Git.m_CurrentDir));
				CAppUtils::RunTortoiseGitProc(sCmd);
			});
		if (!(m_bExecutable || m_bSymlink))
		{
			postCmdList.emplace_back(IDI_ADD, IDS_STATUSLIST_CONTEXT_ADD_EXE, [this] {
				SetFileMode(GIT_FILEMODE_BLOB_EXECUTABLE);
			});
			postCmdList.emplace_back(IDI_ADD, IDS_STATUSLIST_CONTEXT_ADD_LINK, [this] {
				SetFileMode(GIT_FILEMODE_LINK);
			});
		}
	};

	return true;
}
コード例 #23
0
ファイル: index.cpp プロジェクト: computernerd90/libgit2pp
void Index::read() const
{
    Exception::git2_assert(git_index_read(data(), 1));
}
コード例 #24
0
ファイル: notesmodel.cpp プロジェクト: khertan/sparkleNotes
void NotesModel::updateGitStatus() {
    git_repository *repo = NULL;
    git_index *idx = NULL;
    git_signature *me = NULL;

    try {
        e(git_repository_open(&repo, notesFolder().absolutePath().toUtf8().constData()));

        /* Each repository owns an index */
        e(git_repository_index(&idx, repo));

        /* Read index from disk : FIXME Necessary ?*/
        e(git_index_read(idx, true));


        /* Set Option for git status */
        git_status_options opts = { 1, GIT_STATUS_SHOW_INDEX_AND_WORKDIR,
                                    GIT_STATUS_OPT_INCLUDE_UNTRACKED |
                                    //     GIT_STATUS_OPT_INCLUDE_UNMODIFIED |
                                    GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS };
        //status_data d;
        int state = git_repository_state(repo);

        git_status_list *statuses = NULL;
        e(git_status_list_new(&statuses, repo, &opts));


        size_t count = git_status_list_entrycount(statuses);
        if ((count == 0) && (GIT_REPOSITORY_STATE_MERGE != state)) {
            return; // No modified file, exit
        }
        for (size_t i=0; i<count; ++i) {
            const git_status_entry *entry = git_status_byindex(statuses, i);

            /* For each new file add it to the index */
            if ((entry->status & GIT_STATUS_WT_MODIFIED) || (entry->status & GIT_STATUS_WT_RENAMED) || (entry->status & GIT_STATUS_WT_TYPECHANGE) || entry->status == GIT_STATUS_WT_NEW) {
                e(git_index_add_bypath(idx, entry->index_to_workdir->new_file.path));
            }
            else if (entry->status & GIT_STATUS_WT_DELETED) {
                e(git_index_remove_bypath(idx, entry->index_to_workdir->old_file.path));
            }
        }

        e(git_index_write(idx));


        /* Write the index contents to the ODB as a tree */
        git_oid new_tree_id;
        e(git_index_write_tree(&new_tree_id, idx));

        /* Create signature */
        e(git_signature_now(&me, "sparkleNotes", "*****@*****.**"));


        /* Get tree ref */
        git_tree *tree;
        e(git_tree_lookup(&tree, repo, &new_tree_id));

        /* Get parent commit */
        git_oid parentCommitId;
        git_commit *parent;
        int nparents;
        int err;
        err = git_reference_name_to_id( &parentCommitId, repo, "HEAD" );
        if (err == -3) {
            nparents = 0;
        }
        else {
            e(git_commit_lookup( &parent, repo, &parentCommitId ));
            nparents = 1;
        }
        const git_commit *parents [1] = { parent };

        git_oid new_commit_id;
        e(git_commit_create(
              &new_commit_id,
              repo,
              "HEAD",                      /* name of ref to update */
              me,                          /* author */
              me,                          /* committer */
              "UTF-8",                     /* message encoding */
              "Modif on notes",            /* message */
              tree,                        /* root tree */
              nparents,                    /* parent count */
              parents));                    /* parents */


        if(nparents > 0)
            git_commit_free (parent);
        git_checkout_index (repo, idx, NULL);
        git_signature_free(me);
        git_index_free(idx);
        git_repository_free(repo);
    }
    catch (int error) {
        const git_error *err = giterr_last();
        if (err != NULL)
            qDebug() << QString::number(err->klass) + "\t" + QString(err->message);
        giterr_clear();
        git_signature_free(me);
        git_index_free(idx);
        git_repository_free(repo);
    }


}
コード例 #25
0
ファイル: git-checkout.c プロジェクト: chris-y/git2
int cmd_checkout(int argc, const char **argv) 
{
	/* Delete the following line once gits tests pass
	please_git_do_it_for_me();

	if (argc != 1)
		please_git_do_it_for_me();
	*/
	git_index *index;
	git_repository *repo;
	git_index_entry *index_entry;
	git_oid id;
	
	 /* Open the repository */
	if (git_repository_open(&repo, ".git")) {
		libgit_error();
	}

	/* Get the Index file of a Git repository */
	if (git_repository_index(&index,repo)) {
		libgit_error();
	}
	
	/* Find the first index of any entries which point to given path in the Git index */
	if (git_index_find (index, ".git")) {
		libgit_error();
	}

	int i = 0;

	/* get a pointer to one of the entries in the index */
	index_entry = git_index_get(index, i);
	if (index_entry == NULL)
		printf("Out of bound");
	else
		id = index_entry->oid;
	(void)id;
	
	git_reference *symbolic_ref;
	if (git_reference_lookup(&symbolic_ref, repo, "HEAD"))
		libgit_error();

	git_reference *direct_ref;
	if (git_reference_resolve(&direct_ref, symbolic_ref))
		libgit_error();

	const git_oid *oid;
	oid = git_reference_oid(direct_ref);
	if (oid == NULL) {
		printf("Internal error: reference is not direct\n");
		return EXIT_FAILURE;
	}
	
	git_tree *tree;
	/* Lookup a tree object from the repository */
	if (git_tree_lookup(&tree, repo, oid))
		libgit_error();
	
	/* Update the index ?? */
	if (git_index_read(index))
		libgit_error();
	
	git_index_free(index);
	git_tree_close(tree);
	
	return EXIT_SUCCESS;
}