void test_status_worktree__new_staged_file_must_handle_crlf(void) { git_repository *repo; git_index *index; git_config *config; unsigned int status; cl_git_pass(git_repository_init(&repo, "getting_started", 0)); // Ensure that repo has core.autocrlf=true cl_git_pass(git_repository_config(&config, repo)); cl_git_pass(git_config_set_bool(config, "core.autocrlf", true)); cl_git_mkfile("getting_started/testfile.txt", "content\r\n"); // Content with CRLF cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_index_add_from_workdir(index, "testfile.txt")); cl_git_pass(git_index_write(index)); cl_git_pass(git_status_file(&status, repo, "testfile.txt")); cl_assert_equal_i(GIT_STATUS_INDEX_NEW, status); git_config_free(config); git_index_free(index); git_repository_free(repo); }
void test_status_worktree__first_commit_in_progress(void) { git_repository *repo; git_index *index; status_entry_single result; cl_git_pass(git_repository_init(&repo, "getting_started", 0)); cl_git_mkfile("getting_started/testfile.txt", "content\n"); memset(&result, 0, sizeof(result)); cl_git_pass(git_status_foreach(repo, cb_status__single, &result)); cl_assert_equal_i(1, result.count); cl_assert(result.status == GIT_STATUS_WT_NEW); cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_index_add_from_workdir(index, "testfile.txt")); cl_git_pass(git_index_write(index)); memset(&result, 0, sizeof(result)); cl_git_pass(git_status_foreach(repo, cb_status__single, &result)); cl_assert_equal_i(1, result.count); cl_assert(result.status == GIT_STATUS_INDEX_NEW); git_index_free(index); git_repository_free(repo); }
void test_index_rename__single_file(void) { git_repository *repo; git_index *index; int position; git_oid expected; const git_index_entry *entry; p_mkdir("rename", 0700); cl_git_pass(git_repository_init(&repo, "./rename", 0)); cl_git_pass(git_repository_index(&index, repo)); cl_assert(git_index_entrycount(index) == 0); cl_git_mkfile("./rename/lame.name.txt", "new_file\n"); /* This should add a new blob to the object database in 'd4/fa8600b4f37d7516bef4816ae2c64dbf029e3a' */ cl_git_pass(git_index_add_from_workdir(index, "lame.name.txt")); cl_assert(git_index_entrycount(index) == 1); cl_git_pass(git_oid_fromstr(&expected, "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a")); position = git_index_find(index, "lame.name.txt"); entry = git_index_get_byindex(index, position); cl_assert(git_oid_cmp(&expected, &entry->oid) == 0); /* This removes the entry from the index, but not from the object database */ cl_git_pass(git_index_remove(index, "lame.name.txt", 0)); cl_assert(git_index_entrycount(index) == 0); p_rename("./rename/lame.name.txt", "./rename/fancy.name.txt"); cl_git_pass(git_index_add_from_workdir(index, "fancy.name.txt")); cl_assert(git_index_entrycount(index) == 1); position = git_index_find(index, "fancy.name.txt"); entry = git_index_get_byindex(index, position); cl_assert(git_oid_cmp(&expected, &entry->oid) == 0); git_index_free(index); git_repository_free(repo); cl_fixture_cleanup("rename"); }
static void assert_proper_normalization(git_index *index, const char *filename, const char *expected_sha) { int index_pos; git_index_entry *entry; add_to_workdir(filename, CONTENT); cl_git_pass(git_index_add_from_workdir(index, filename)); index_pos = git_index_find(index, filename); cl_assert(index_pos >= 0); entry = git_index_get_byindex(index, index_pos); cl_assert_equal_i(0, git_oid_streq(&entry->oid, expected_sha)); }
void test_stash_save__cannot_stash_when_there_are_no_local_change(void) { git_index *index; git_oid commit_oid, stash_tip_oid; cl_git_pass(git_repository_index(&index, repo)); /* * 'what' and 'who' are being committed. * 'when' remain untracked. */ cl_git_pass(git_index_add_from_workdir(index, "what")); cl_git_pass(git_index_add_from_workdir(index, "who")); cl_git_pass(git_index_write(index)); commit_staged_files(&commit_oid, index, signature); git_index_free(index); cl_assert_equal_i(GIT_ENOTFOUND, git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT)); p_unlink("stash/when"); cl_assert_equal_i(GIT_ENOTFOUND, git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED)); }
PyObject * Index_add(Index *self, PyObject *args) { int err; const char *path; if (!PyArg_ParseTuple(args, "s", &path)) return NULL; err = git_index_add_from_workdir(self->index, path); if (err < 0) return Error_set_str(err, path); Py_RETURN_NONE; }
void test_status_worktree__space_in_filename(void) { git_repository *repo; git_index *index; status_entry_single result; unsigned int status_flags; #define FILE_WITH_SPACE "LICENSE - copy.md" cl_git_pass(git_repository_init(&repo, "with_space", 0)); cl_git_mkfile("with_space/" FILE_WITH_SPACE, "I have a space in my name\n"); /* file is new to working directory */ memset(&result, 0, sizeof(result)); cl_git_pass(git_status_foreach(repo, cb_status__single, &result)); cl_assert_equal_i(1, result.count); cl_assert(result.status == GIT_STATUS_WT_NEW); cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_SPACE)); cl_assert(status_flags == GIT_STATUS_WT_NEW); /* ignore the file */ cl_git_rewritefile("with_space/.gitignore", "*.md\n.gitignore\n"); memset(&result, 0, sizeof(result)); cl_git_pass(git_status_foreach(repo, cb_status__single, &result)); cl_assert_equal_i(2, result.count); cl_assert(result.status == GIT_STATUS_IGNORED); cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_SPACE)); cl_assert(status_flags == GIT_STATUS_IGNORED); /* don't ignore the file */ cl_git_rewritefile("with_space/.gitignore", ".gitignore\n"); memset(&result, 0, sizeof(result)); cl_git_pass(git_status_foreach(repo, cb_status__single, &result)); cl_assert_equal_i(2, result.count); cl_assert(result.status == GIT_STATUS_WT_NEW); cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_SPACE)); cl_assert(status_flags == GIT_STATUS_WT_NEW); /* add the file to the index */ cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_index_add_from_workdir(index, FILE_WITH_SPACE)); cl_git_pass(git_index_write(index)); memset(&result, 0, sizeof(result)); cl_git_pass(git_status_foreach(repo, cb_status__single, &result)); cl_assert_equal_i(2, result.count); cl_assert(result.status == GIT_STATUS_INDEX_NEW); cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_SPACE)); cl_assert(status_flags == GIT_STATUS_INDEX_NEW); git_index_free(index); git_repository_free(repo); }
void test_status_worktree__bracket_in_filename(void) { git_repository *repo; git_index *index; status_entry_single result; unsigned int status_flags; int error; #define FILE_WITH_BRACKET "LICENSE[1].md" #define FILE_WITHOUT_BRACKET "LICENSE1.md" cl_git_pass(git_repository_init(&repo, "with_bracket", 0)); cl_git_mkfile("with_bracket/" FILE_WITH_BRACKET, "I have a bracket in my name\n"); /* file is new to working directory */ memset(&result, 0, sizeof(result)); cl_git_pass(git_status_foreach(repo, cb_status__single, &result)); cl_assert_equal_i(1, result.count); cl_assert(result.status == GIT_STATUS_WT_NEW); cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_BRACKET)); cl_assert(status_flags == GIT_STATUS_WT_NEW); /* ignore the file */ cl_git_rewritefile("with_bracket/.gitignore", "*.md\n.gitignore\n"); memset(&result, 0, sizeof(result)); cl_git_pass(git_status_foreach(repo, cb_status__single, &result)); cl_assert_equal_i(2, result.count); cl_assert(result.status == GIT_STATUS_IGNORED); cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_BRACKET)); cl_assert(status_flags == GIT_STATUS_IGNORED); /* don't ignore the file */ cl_git_rewritefile("with_bracket/.gitignore", ".gitignore\n"); memset(&result, 0, sizeof(result)); cl_git_pass(git_status_foreach(repo, cb_status__single, &result)); cl_assert_equal_i(2, result.count); cl_assert(result.status == GIT_STATUS_WT_NEW); cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_BRACKET)); cl_assert(status_flags == GIT_STATUS_WT_NEW); /* add the file to the index */ cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_index_add_from_workdir(index, FILE_WITH_BRACKET)); cl_git_pass(git_index_write(index)); memset(&result, 0, sizeof(result)); cl_git_pass(git_status_foreach(repo, cb_status__single, &result)); cl_assert_equal_i(2, result.count); cl_assert(result.status == GIT_STATUS_INDEX_NEW); cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_BRACKET)); cl_assert(status_flags == GIT_STATUS_INDEX_NEW); /* Create file without bracket */ cl_git_mkfile("with_bracket/" FILE_WITHOUT_BRACKET, "I have no bracket in my name!\n"); cl_git_pass(git_status_file(&status_flags, repo, FILE_WITHOUT_BRACKET)); cl_assert(status_flags == GIT_STATUS_WT_NEW); cl_git_pass(git_status_file(&status_flags, repo, "LICENSE\\[1\\].md")); cl_assert(status_flags == GIT_STATUS_INDEX_NEW); error = git_status_file(&status_flags, repo, FILE_WITH_BRACKET); cl_git_fail(error); cl_assert_equal_i(GIT_EAMBIGUOUS, error); git_index_free(index); git_repository_free(repo); }