void test_status_worktree__simple_delete(void) { git_repository *repo = cl_git_sandbox_init("renames"); git_status_options opts = GIT_STATUS_OPTIONS_INIT; int count; opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH | GIT_STATUS_OPT_EXCLUDE_SUBMODULES | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS; count = 0; cl_git_pass( git_status_foreach_ext(repo, &opts, cb_status__count, &count) ); cl_assert_equal_i(0, count); cl_must_pass(p_unlink("renames/untimely.txt")); count = 0; cl_git_pass( git_status_foreach_ext(repo, &opts, cb_status__count, &count) ); cl_assert_equal_i(1, count); }
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); }
void test_status_ignore__negative_ignores_inside_ignores(void) { static const char *test_files[] = { "empty_standard_repo/top/mid/btm/tracked", "empty_standard_repo/top/mid/btm/untracked", NULL }; make_test_data("empty_standard_repo", test_files); cl_git_mkfile( "empty_standard_repo/.gitignore", "top\n!top/mid/btm\n"); add_one_to_index("top/mid/btm/tracked"); { git_status_options opts = GIT_STATUS_OPTIONS_INIT; status_entry_counts counts; static const char *files[] = { ".gitignore", "top/mid/btm/tracked", "top/mid/btm/untracked", }; static const unsigned int statuses[] = { GIT_STATUS_WT_NEW, GIT_STATUS_INDEX_NEW, GIT_STATUS_WT_NEW, }; memset(&counts, 0x0, sizeof(status_entry_counts)); counts.expected_entry_count = 3; counts.expected_paths = files; counts.expected_statuses = statuses; opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_INCLUDE_IGNORED | GIT_STATUS_OPT_RECURSE_IGNORED_DIRS; cl_git_pass(git_status_foreach_ext( g_repo, &opts, cb_status__normal, &counts)); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); } refute_is_ignored("top/mid/btm/tracked"); refute_is_ignored("top/mid/btm/untracked"); }
void test_status_worktree__filemode_changes(void) { git_repository *repo = cl_git_sandbox_init("filemodes"); status_entry_counts counts; git_status_options opts; git_config *cfg; /* overwrite stored filemode with platform appropriate value */ cl_git_pass(git_repository_config(&cfg, repo)); if (cl_is_chmod_supported()) cl_git_pass(git_config_set_bool(cfg, "core.filemode", true)); else { int i; cl_git_pass(git_config_set_bool(cfg, "core.filemode", false)); /* won't trust filesystem mode diffs, so these will appear unchanged */ for (i = 0; i < filemode_count; ++i) if (filemode_statuses[i] == GIT_STATUS_WT_MODIFIED) filemode_statuses[i] = GIT_STATUS_CURRENT; } memset(&opts, 0, sizeof(opts)); opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_INCLUDE_IGNORED | GIT_STATUS_OPT_INCLUDE_UNMODIFIED; memset(&counts, 0, sizeof(counts)); counts.expected_entry_count = filemode_count; counts.expected_paths = filemode_paths; counts.expected_statuses = filemode_statuses; cl_git_pass( git_status_foreach_ext(repo, &opts, cb_status__normal, &counts) ); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); git_config_free(cfg); }
void test_status_worktree__within_subdir(void) { status_entry_counts counts; git_repository *repo = cl_git_sandbox_init("status"); git_status_options opts = GIT_STATUS_OPTIONS_INIT; char *paths[] = { "zzz_new_dir" }; git_strarray pathsArray; /* first alter the contents of the worktree */ cl_git_mkfile("status/.new_file", "dummy"); cl_git_pass(git_futils_mkdir_r("status/zzz_new_dir", 0777)); cl_git_mkfile("status/zzz_new_dir/new_file", "dummy"); cl_git_mkfile("status/zzz_new_file", "dummy"); cl_git_mkfile("status/wut", "dummy"); stage_and_commit(repo, "zzz_new_dir/new_file"); /* now get status */ memset(&counts, 0x0, sizeof(status_entry_counts)); counts.expected_entry_count = entry_count4; counts.expected_paths = entry_paths4; counts.expected_statuses = entry_statuses4; counts.debug = true; opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS | GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH; pathsArray.count = 1; pathsArray.strings = paths; opts.pathspec = pathsArray; // We committed zzz_new_dir/new_file above. It shouldn't be reported. cl_git_pass( git_status_foreach_ext(repo, &opts, cb_status__normal, &counts) ); cl_assert_equal_i(0, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); }
void test_status_ignore__subdirectories_not_at_root(void) { git_status_options opts = GIT_STATUS_OPTIONS_INIT; status_entry_counts counts; static const char *paths_1[] = { "dir/.gitignore", "dir/a/ignore_me", "dir/b/ignore_me", "dir/ignore_me", "ignore_also/file", "ignore_me", "test/.gitignore", "test/ignore_me/and_me/file", "test/ignore_me/file", "test/ignore_me/file2", }; static const unsigned int statuses_1[] = { GIT_STATUS_WT_NEW, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW, GIT_STATUS_IGNORED, GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW, }; make_test_data(test_repo_1, test_files_1); cl_git_rewritefile("empty_standard_repo/dir/.gitignore", "ignore_me\n/ignore_also\n"); cl_git_rewritefile("empty_standard_repo/test/.gitignore", "and_me\n"); memset(&counts, 0x0, sizeof(status_entry_counts)); counts.expected_entry_count = 10; counts.expected_paths = paths_1; counts.expected_statuses = statuses_1; opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_RECURSE_IGNORED_DIRS; cl_git_pass(git_status_foreach_ext( g_repo, &opts, cb_status__normal, &counts)); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); }
void test_submodule_status__iterator(void) { git_iterator *iter; const git_index_entry *entry; size_t i; static const char *expected[] = { ".gitmodules", "just_a_dir/", "just_a_dir/contents", "just_a_file", "not", "not-submodule", "README.txt", "sm_added_and_uncommited", "sm_changed_file", "sm_changed_head", "sm_changed_index", "sm_changed_untracked_file", "sm_missing_commits", "sm_unchanged", NULL }; submodule_expectations exp = { 0, expected }; git_status_options opts = GIT_STATUS_OPTIONS_INIT; cl_git_pass(git_iterator_for_workdir(&iter, g_repo, GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES, NULL, NULL)); for (i = 0; !git_iterator_advance(&entry, iter); ++i) cl_assert_equal_s(expected[i], entry->path); git_iterator_free(iter); opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_INCLUDE_UNMODIFIED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS; cl_git_pass(git_status_foreach_ext( g_repo, &opts, confirm_submodule_status, &exp)); }
/* this test is similar to t18-status.c:statuscb3 */ void test_status_worktree__swap_subdir_and_file(void) { status_entry_counts counts; git_repository *repo = cl_git_sandbox_init("status"); git_index *index; git_status_options opts; bool ignore_case; cl_git_pass(git_repository_index(&index, repo)); ignore_case = index->ignore_case; git_index_free(index); /* first alter the contents of the worktree */ cl_git_pass(p_rename("status/current_file", "status/swap")); cl_git_pass(p_rename("status/subdir", "status/current_file")); cl_git_pass(p_rename("status/swap", "status/subdir")); cl_git_mkfile("status/.HEADER", "dummy"); cl_git_mkfile("status/42-is-not-prime.sigh", "dummy"); cl_git_mkfile("status/README.md", "dummy"); /* now get status */ memset(&counts, 0x0, sizeof(status_entry_counts)); counts.expected_entry_count = entry_count3; counts.expected_paths = ignore_case ? entry_paths3_icase : entry_paths3; counts.expected_statuses = ignore_case ? entry_statuses3_icase : entry_statuses3; memset(&opts, 0, sizeof(opts)); opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_INCLUDE_IGNORED; cl_git_pass( git_status_foreach_ext(repo, &opts, cb_status__normal, &counts) ); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); }
void test_status_ignore__contained_dir_with_matching_name(void) { static const char *test_files[] = { "empty_standard_repo/subdir_match/aaa/subdir_match/file", "empty_standard_repo/subdir_match/zzz_ignoreme", NULL }; static const char *expected_paths[] = { "subdir_match/.gitignore", "subdir_match/aaa/subdir_match/file", "subdir_match/zzz_ignoreme", }; static const unsigned int expected_statuses[] = { GIT_STATUS_WT_NEW, GIT_STATUS_WT_NEW, GIT_STATUS_IGNORED }; git_status_options opts = GIT_STATUS_OPTIONS_INIT; status_entry_counts counts; make_test_data("empty_standard_repo", test_files); cl_git_mkfile( "empty_standard_repo/subdir_match/.gitignore", "*_ignoreme\n"); refute_is_ignored("subdir_match/aaa/subdir_match/file"); assert_is_ignored("subdir_match/zzz_ignoreme"); memset(&counts, 0x0, sizeof(status_entry_counts)); counts.expected_entry_count = 3; counts.expected_paths = expected_paths; counts.expected_statuses = expected_statuses; opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_RECURSE_IGNORED_DIRS; cl_git_pass(git_status_foreach_ext( g_repo, &opts, cb_status__normal, &counts)); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); }
void Gitarre::DisplayRepo(int i) { Repository *repo = Repos[i]; QTreeWidgetItem *item = new QTreeWidgetItem (QStringList (repo->GetName())); RepoView->insertTopLevelItem(i, item); if (repo->GetGitRepo ()) { StatusCbData cbData = { this, i, Gitarre::Add }; git_strarray *pathspec = pathspecAll (); git_status_options cbOptns = { 1, GIT_STATUS_SHOW_INDEX_AND_WORKDIR, GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_INCLUDE_IGNORED | GIT_STATUS_OPT_INCLUDE_UNMODIFIED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS | GIT_STATUS_OPT_RECURSE_IGNORED_DIRS, *pathspec }; git_status_foreach_ext (repo->GetGitRepo(), &cbOptns, Gitarre::sStatusCb, (void *)&cbData); git_strarray_free (pathspec); // AddSubfolders (i, item, repo->GetDir()); } else item->setForeground(0, QBrush (QColor(Qt::red))); update (); }
void test_status_worktree__unreadable(void) { #ifndef GIT_WIN32 const char *expected_paths[] = { "no_permission/foo" }; const unsigned int expected_statuses[] = {GIT_STATUS_WT_UNREADABLE}; git_repository *repo = cl_git_sandbox_init("empty_standard_repo"); git_status_options opts = GIT_STATUS_OPTIONS_INIT; status_entry_counts counts = {0}; if (geteuid() == 0) cl_skip(); /* Create directory with no read permission */ cl_git_pass(git_futils_mkdir_r("empty_standard_repo/no_permission", 0777)); cl_git_mkfile("empty_standard_repo/no_permission/foo", "dummy"); p_chmod("empty_standard_repo/no_permission", 0644); counts.expected_entry_count = 1; counts.expected_paths = expected_paths; counts.expected_statuses = expected_statuses; opts.show = GIT_STATUS_SHOW_WORKDIR_ONLY; opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_INCLUDE_UNREADABLE; cl_git_pass( git_status_foreach_ext(repo, &opts, cb_status__normal, &counts) ); /* Restore permissions so we can cleanup :) */ p_chmod("empty_standard_repo/no_permission", 0777); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); #else cl_skip(); #endif }
void assert_show(const int entry_counts, const char *entry_paths[], const unsigned int entry_statuses[], git_status_show_t show) { status_entry_counts counts; git_repository *repo = cl_git_sandbox_init("status"); git_status_options opts = GIT_STATUS_OPTIONS_INIT; memset(&counts, 0x0, sizeof(status_entry_counts)); counts.expected_entry_count = entry_counts; counts.expected_paths = entry_paths; counts.expected_statuses = entry_statuses; opts.flags = GIT_STATUS_OPT_DEFAULTS; opts.show = show; cl_git_pass( git_status_foreach_ext(repo, &opts, cb_status__normal, &counts) ); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); }
emacs_value egit_status_foreach(emacs_env *env, emacs_value _repo, emacs_value function, emacs_value show, emacs_value flags, emacs_value pathspec, emacs_value baseline) { EGIT_ASSERT_REPOSITORY(_repo); EM_ASSERT_FUNCTION(function); git_status_options options; git_status_init_options(&options, GIT_STATUS_OPTIONS_VERSION); if (!convert_show_option(&options.show, env, show)) { return em_nil; } if (!convert_flags_option(&options.flags, env, flags)) { return em_nil; } if (!egit_strarray_from_list(&options.pathspec, env, pathspec)) { return em_nil; } if (!convert_baseline_option(&options.baseline, env, baseline)) { egit_strarray_dispose(&options.pathspec); return em_nil; } git_repository *repo = EGIT_EXTRACT(_repo); egit_generic_payload ctx = {.env = env, .func = function}; int rv = git_status_foreach_ext(repo, &options, &foreach_callback, (void *)(&ctx)); egit_strarray_dispose(&options.pathspec); if (rv != GIT_EUSER) { EGIT_CHECK_ERROR(rv); } return em_nil; }
void CGitStatus::Load() { GitStatus status; CriticalSection lock(this->m_critSec); status = this->GetStatus(); if (status == GS_NOTLOADED || status == GS_INVALIDATED) { this->m_waitHandle = CreateEvent(NULL, TRUE, FALSE, NULL); SetStatus(GS_LOADING); } lock.Unlock(); if (status == GS_LOADED || status == GS_ERROR) { return; } // If it is loading just wait for it to complete. if (status == GS_LOADING) { _ASSERT(this->m_waitHandle.IsValid()); WaitForSingleObject(this->m_waitHandle, INFINITE); return; } git_buf buf; git_repository *repo = NULL; wstring_convert<codecvt_utf8<wchar_t>> converter; InitState(); if (!GetRepoRootInternal(this->m_startDir, this->m_repoRoot, buf, repo)) { Logger::LogWarning(_T("Unable to open git repository")); SetStatus(GS_ERROR); ::SetEvent(this->m_waitHandle); return; } // This is temporary. CMutexLock mutexLock(&m_mutex); this->m_gitDir = MyUtils::NormalizePath(converter.from_bytes(buf.ptr)); // Get current state of repo. (merge/rebase in progress etc) this->m_repoState = git_repository_state(repo); // Get branch info. git_reference *ref; if (git_repository_head(&ref, repo)) { Logger::LogError(_T("Unable to retrieve branch")); SetStatus(GS_ERROR); ::SetEvent(this->m_waitHandle); return; } const char* headName = git_reference_shorthand(ref); this->m_branch = converter.from_bytes(headName); // Get the status of the repo. git_status_options opts; git_status_init_options(&opts, GIT_STATUS_OPTIONS_VERSION); opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_EXCLUDE_SUBMODULES; git_status_foreach_ext(repo, &opts, &GitStatus_Callack, this); // Free stuff git_buf_free(&buf); git_repository_free(repo); this->SetStatus(GS_LOADED); ::SetEvent(this->m_waitHandle); // Start monitoring for changes. this->MonitorForChanges(); return; }
void test_status_ignore__subdirectories_recursion(void) { /* Let's try again with recursing into ignored dirs turned on */ git_status_options opts = GIT_STATUS_OPTIONS_INIT; status_entry_counts counts; static const char *paths_r[] = { ".gitignore", "ignore_also/file", "ignore_me", "test/ignore_me/and_me/file", "test/ignore_me/file", "test/ignore_me/file2", }; static const unsigned int statuses_r[] = { GIT_STATUS_WT_NEW, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, }; static const char *paths_nr[] = { ".gitignore", "ignore_also/", "ignore_me", "test/ignore_me/", }; static const unsigned int statuses_nr[] = { GIT_STATUS_WT_NEW, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, GIT_STATUS_IGNORED, }; g_repo = cl_git_sandbox_init("empty_standard_repo"); cl_git_rewritefile("empty_standard_repo/.gitignore", "ignore_me\n/ignore_also\n"); cl_git_mkfile( "empty_standard_repo/ignore_me", "I'm going to be ignored!"); cl_git_pass(git_futils_mkdir_r( "empty_standard_repo/test/ignore_me", NULL, 0775)); cl_git_mkfile( "empty_standard_repo/test/ignore_me/file", "I'm going to be ignored!"); cl_git_mkfile( "empty_standard_repo/test/ignore_me/file2", "Me, too!"); cl_git_pass(git_futils_mkdir_r( "empty_standard_repo/test/ignore_me/and_me", NULL, 0775)); cl_git_mkfile( "empty_standard_repo/test/ignore_me/and_me/file", "Deeply ignored"); cl_git_pass(git_futils_mkdir_r( "empty_standard_repo/ignore_also", NULL, 0775)); cl_git_mkfile( "empty_standard_repo/ignore_also/file", "I'm going to be ignored!"); memset(&counts, 0x0, sizeof(status_entry_counts)); counts.expected_entry_count = 6; counts.expected_paths = paths_r; counts.expected_statuses = statuses_r; opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_RECURSE_IGNORED_DIRS; cl_git_pass(git_status_foreach_ext( g_repo, &opts, cb_status__normal, &counts)); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); memset(&counts, 0x0, sizeof(status_entry_counts)); counts.expected_entry_count = 4; counts.expected_paths = paths_nr; counts.expected_statuses = statuses_nr; opts.flags = GIT_STATUS_OPT_DEFAULTS; cl_git_pass(git_status_foreach_ext( g_repo, &opts, cb_status__normal, &counts)); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); }
static gboolean submain (struct EvTag *self, int argc, char **argv, GError **error) { gboolean ret = FALSE; git_status_options statusopts = GIT_STATUS_OPTIONS_INIT; GCancellable *cancellable = NULL; const char *command_name = NULL; Subcommand *command; char *prgname = NULL; int in, out; int r; /* * Parse the global options. We rearrange the options as * necessary, in order to pass relevant options through * to the commands, but also have them take effect globally. */ for (in = 1, out = 1; in < argc; in++, out++) { /* The non-option is the command, take it out of the arguments */ if (argv[in][0] != '-') { if (command_name == NULL) { command_name = argv[in]; out--; continue; } } else if (g_str_equal (argv[in], "--")) { break; } argv[out] = argv[in]; } argc = out; command = commands; while (command->name) { if (g_strcmp0 (command_name, command->name) == 0) break; command++; } if (!command->fn) { GOptionContext *context; char *help; context = option_context_new_with_commands (commands); /* This will not return for some options (e.g. --version). */ if (option_context_parse (context, NULL, &argc, &argv, cancellable, error)) { if (command_name == NULL) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No command specified"); } else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unknown command '%s'", command_name); } } help = g_option_context_get_help (context, FALSE, NULL); g_printerr ("%s", help); g_option_context_free (context); goto out; } prgname = g_strdup_printf ("%s %s", g_get_prgname (), command_name); g_set_prgname (prgname); r = git_repository_open_ext (&self->top_repo, ".", 0, NULL); if (!handle_libgit_ret (r, error)) goto out; r = git_status_init_options (&statusopts, GIT_STATUS_OPTIONS_VERSION); if (!handle_libgit_ret (r, error)) goto out; { struct TreeWalkData twdata = { FALSE, self, self->top_repo, NULL, cancellable, error }; r = git_status_foreach_ext (self->top_repo, &statusopts, status_cb, &twdata); if (twdata.caught_error) goto out; if (!handle_libgit_ret (r, error)) goto out; } self->checksum = g_checksum_new (G_CHECKSUM_SHA512); if (!command->fn (self, argc, argv, cancellable, error)) goto out; ret = TRUE; out: return ret; }
void test_status_worktree__sorting_by_case(void) { git_repository *repo = cl_git_sandbox_init("icase"); git_index *index; git_status_options opts = GIT_STATUS_OPTIONS_INIT; bool native_ignore_case; status_entry_counts counts; cl_git_pass(git_repository_index(&index, repo)); native_ignore_case = (git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0; git_index_free(index); memset(&counts, 0, sizeof(counts)); counts.expected_entry_count = 0; counts.expected_paths = NULL; counts.expected_statuses = NULL; cl_git_pass( git_status_foreach_ext(repo, &opts, cb_status__normal, &counts)); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); cl_git_rewritefile("icase/B", "new stuff"); cl_must_pass(p_unlink("icase/c")); cl_git_rewritefile("icase/g", "new stuff"); cl_must_pass(p_unlink("icase/H")); memset(&counts, 0, sizeof(counts)); counts.expected_entry_count = 4; if (native_ignore_case) { counts.expected_paths = icase_paths; counts.expected_statuses = icase_statuses; } else { counts.expected_paths = case_paths; counts.expected_statuses = case_statuses; } cl_git_pass( git_status_foreach_ext(repo, &opts, cb_status__normal, &counts)); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); opts.flags = GIT_STATUS_OPT_SORT_CASE_SENSITIVELY; memset(&counts, 0, sizeof(counts)); counts.expected_entry_count = 4; counts.expected_paths = case_paths; counts.expected_statuses = case_statuses; cl_git_pass( git_status_foreach_ext(repo, &opts, cb_status__normal, &counts)); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); opts.flags = GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY; memset(&counts, 0, sizeof(counts)); counts.expected_entry_count = 4; counts.expected_paths = icase_paths; counts.expected_statuses = icase_statuses; cl_git_pass( git_status_foreach_ext(repo, &opts, cb_status__normal, &counts)); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); }
void test_status_ignore__issue_1766_negated_ignores(void) { unsigned int status; g_repo = cl_git_sandbox_init("empty_standard_repo"); cl_git_pass(git_futils_mkdir_r( "empty_standard_repo/a", 0775)); cl_git_mkfile( "empty_standard_repo/a/.gitignore", "*\n!.gitignore\n"); cl_git_mkfile( "empty_standard_repo/a/ignoreme", "I should be ignored\n"); refute_is_ignored("a/.gitignore"); assert_is_ignored("a/ignoreme"); cl_git_pass(git_futils_mkdir_r( "empty_standard_repo/b", 0775)); cl_git_mkfile( "empty_standard_repo/b/.gitignore", "*\n!.gitignore\n"); cl_git_mkfile( "empty_standard_repo/b/ignoreme", "I should be ignored\n"); refute_is_ignored("b/.gitignore"); assert_is_ignored("b/ignoreme"); /* shouldn't have changed results from first couple either */ refute_is_ignored("a/.gitignore"); assert_is_ignored("a/ignoreme"); /* status should find the two ignore files and nothing else */ cl_git_pass(git_status_file(&status, g_repo, "a/.gitignore")); cl_assert_equal_i(GIT_STATUS_WT_NEW, (int)status); cl_git_pass(git_status_file(&status, g_repo, "a/ignoreme")); cl_assert_equal_i(GIT_STATUS_IGNORED, (int)status); cl_git_pass(git_status_file(&status, g_repo, "b/.gitignore")); cl_assert_equal_i(GIT_STATUS_WT_NEW, (int)status); cl_git_pass(git_status_file(&status, g_repo, "b/ignoreme")); cl_assert_equal_i(GIT_STATUS_IGNORED, (int)status); { git_status_options opts = GIT_STATUS_OPTIONS_INIT; status_entry_counts counts; static const char *paths[] = { "a/.gitignore", "a/ignoreme", "b/.gitignore", "b/ignoreme", }; static const unsigned int statuses[] = { GIT_STATUS_WT_NEW, GIT_STATUS_IGNORED, GIT_STATUS_WT_NEW, GIT_STATUS_IGNORED, }; memset(&counts, 0x0, sizeof(status_entry_counts)); counts.expected_entry_count = 4; counts.expected_paths = paths; counts.expected_statuses = statuses; opts.flags = GIT_STATUS_OPT_DEFAULTS; cl_git_pass(git_status_foreach_ext( g_repo, &opts, cb_status__normal, &counts)); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); } }