static void ensure_repository_init( const char *working_directory, int is_bare, const char *expected_path_repository, const char *expected_working_directory) { const char *workdir; cl_assert(!git_path_isdir(working_directory)); cl_git_pass(git_repository_init(&_repo, working_directory, is_bare)); workdir = git_repository_workdir(_repo); if (workdir != NULL || expected_working_directory != NULL) { cl_assert( git__suffixcmp(workdir, expected_working_directory) == 0 ); } cl_assert( git__suffixcmp(git_repository_path(_repo), expected_path_repository) == 0 ); cl_assert(git_repository_is_bare(_repo) == is_bare); #ifdef GIT_WIN32 if (!is_bare) { DWORD fattrs = GetFileAttributes(git_repository_path(_repo)); cl_assert((fattrs & FILE_ATTRIBUTE_HIDDEN) != 0); } #endif cl_assert(git_repository_is_empty(_repo)); }
void test_repo_init__relative_gitdir(void) { git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; git_buf dot_git_content = GIT_BUF_INIT; opts.workdir_path = "../c_wd"; opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_RELATIVE_GITLINK | GIT_REPOSITORY_INIT_NO_DOTGIT_DIR; /* make the directory first, then it should succeed */ cl_git_pass(git_repository_init_ext(&_repo, "root/b/my_repository", &opts)); cl_assert(!git__suffixcmp(git_repository_workdir(_repo), "root/b/c_wd/")); cl_assert(!git__suffixcmp(git_repository_path(_repo), "root/b/my_repository/")); cl_assert(!git_repository_is_bare(_repo)); cl_assert(git_repository_is_empty(_repo)); /* Verify that the gitlink and worktree entries are relative */ /* Verify worktree */ assert_config_entry_value(_repo, "core.worktree", "../c_wd/"); /* Verify gitlink */ cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git")); cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr); git_buf_free(&dot_git_content); cleanup_repository("root"); }
void test_submodule_modify__init(void) { git_config *cfg; const char *str; /* erase submodule data from .git/config */ cl_git_pass(git_repository_config(&cfg, g_repo)); cl_git_pass( git_config_foreach_match(cfg, "submodule\\..*", delete_one_config, cfg)); git_config_free(cfg); /* confirm no submodule data in config */ cl_git_pass(git_repository_config(&cfg, g_repo)); cl_git_fail(git_config_get_string(&str, cfg, "submodule.sm_unchanged.url")); cl_git_fail(git_config_get_string(&str, cfg, "submodule.sm_changed_head.url")); cl_git_fail(git_config_get_string(&str, cfg, "submodule.sm_added_and_uncommited.url")); git_config_free(cfg); /* call init and see that settings are copied */ cl_git_pass(git_submodule_foreach(g_repo, init_one_submodule, NULL)); git_submodule_reload_all(g_repo); /* confirm submodule data in config */ cl_git_pass(git_repository_config(&cfg, g_repo)); cl_git_pass(git_config_get_string(&str, cfg, "submodule.sm_unchanged.url")); cl_assert(git__suffixcmp(str, "/submod2_target") == 0); cl_git_pass(git_config_get_string(&str, cfg, "submodule.sm_changed_head.url")); cl_assert(git__suffixcmp(str, "/submod2_target") == 0); cl_git_pass(git_config_get_string(&str, cfg, "submodule.sm_added_and_uncommited.url")); cl_assert(git__suffixcmp(str, "/submod2_target") == 0); git_config_free(cfg); }
void test_repo_open__standard_empty_repo_through_workdir(void) { git_repository *repo = cl_git_sandbox_init("empty_standard_repo"); cl_assert(git_repository_path(repo) != NULL); cl_assert(git__suffixcmp(git_repository_path(repo), "/") == 0); cl_assert(git_repository_workdir(repo) != NULL); cl_assert(git__suffixcmp(git_repository_workdir(repo), "/") == 0); }
static void env_pass_(const char *path, const char *file, int line) { git_repository *repo; cl_git_expect(git_repository_open_ext(NULL, path, GIT_REPOSITORY_OPEN_FROM_ENV, NULL), 0, file, line); cl_git_expect(git_repository_open_ext(&repo, path, GIT_REPOSITORY_OPEN_FROM_ENV, NULL), 0, file, line); cl_assert_at_line(git__suffixcmp(git_repository_path(repo), "attr/.git/") == 0, file, line); cl_assert_at_line(git__suffixcmp(git_repository_workdir(repo), "attr/") == 0, file, line); cl_assert_at_line(!git_repository_is_bare(repo), file, line); git_repository_free(repo); }
void test_submodule_lookup__accessors(void) { git_submodule *sm; const char *oid = "480095882d281ed676fe5b863569520e54a7d5c0"; cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged")); cl_assert(git_submodule_owner(sm) == g_repo); cl_assert_equal_s("sm_unchanged", git_submodule_name(sm)); cl_assert(git__suffixcmp(git_submodule_path(sm), "sm_unchanged") == 0); cl_assert(git__suffixcmp(git_submodule_url(sm), "/submod2_target") == 0); cl_assert(git_oid_streq(git_submodule_index_id(sm), oid) == 0); cl_assert(git_oid_streq(git_submodule_head_id(sm), oid) == 0); cl_assert(git_oid_streq(git_submodule_wd_id(sm), oid) == 0); cl_assert(git_submodule_ignore(sm) == GIT_SUBMODULE_IGNORE_NONE); cl_assert(git_submodule_update(sm) == GIT_SUBMODULE_UPDATE_CHECKOUT); git_submodule_free(sm); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head")); cl_assert_equal_s("sm_changed_head", git_submodule_name(sm)); cl_assert(git_oid_streq(git_submodule_index_id(sm), oid) == 0); cl_assert(git_oid_streq(git_submodule_head_id(sm), oid) == 0); cl_assert(git_oid_streq(git_submodule_wd_id(sm), "3d9386c507f6b093471a3e324085657a3c2b4247") == 0); git_submodule_free(sm); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited")); cl_assert_equal_s("sm_added_and_uncommited", git_submodule_name(sm)); cl_assert(git_oid_streq(git_submodule_index_id(sm), oid) == 0); cl_assert(git_submodule_head_id(sm) == NULL); cl_assert(git_oid_streq(git_submodule_wd_id(sm), oid) == 0); git_submodule_free(sm); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_missing_commits")); cl_assert_equal_s("sm_missing_commits", git_submodule_name(sm)); cl_assert(git_oid_streq(git_submodule_index_id(sm), oid) == 0); cl_assert(git_oid_streq(git_submodule_head_id(sm), oid) == 0); cl_assert(git_oid_streq(git_submodule_wd_id(sm), "5e4963595a9774b90524d35a807169049de8ccad") == 0); git_submodule_free(sm); }
void test_repo_open__standard_empty_repo_through_gitdir(void) { git_repository *repo; cl_git_pass(git_repository_open(&repo, cl_fixture("empty_standard_repo/.gitted"))); cl_assert(git_repository_path(repo) != NULL); cl_assert(git__suffixcmp(git_repository_path(repo), "/") == 0); cl_assert(git_repository_workdir(repo) != NULL); cl_assert(git__suffixcmp(git_repository_workdir(repo), "/") == 0); git_repository_free(repo); }
END_TEST #define STANDARD_REPOSITORY 0 #define BARE_REPOSITORY 1 static int ensure_repository_init( const char *working_directory, int repository_kind, const char *expected_path_index, const char *expected_path_repository, const char *expected_working_directory) { char path_odb[GIT_PATH_MAX]; git_repository *repo; if (gitfo_isdir(working_directory) == GIT_SUCCESS) return GIT_ERROR; git__joinpath(path_odb, expected_path_repository, GIT_OBJECTS_DIR); if (git_repository_init(&repo, working_directory, repository_kind) < GIT_SUCCESS) return GIT_ERROR; if (repo->path_workdir != NULL || expected_working_directory != NULL) { if (git__suffixcmp(repo->path_workdir, expected_working_directory) != 0) goto cleanup; } if (git__suffixcmp(repo->path_odb, path_odb) != 0) goto cleanup; if (git__suffixcmp(repo->path_repository, expected_path_repository) != 0) goto cleanup; if (repo->path_index != NULL || expected_path_index != NULL) { if (git__suffixcmp(repo->path_index, expected_path_index) != 0) goto cleanup; } git_repository_free(repo); rmdir_recurs(working_directory); return GIT_SUCCESS; cleanup: git_repository_free(repo); rmdir_recurs(working_directory); return GIT_ERROR; }
static int packfile_load__cb(void *data, git_buf *path) { struct pack_backend *backend = (pack_backend*) data; struct git_pack_file *pack; const char *path_str = git_buf_cstr(path); size_t i, cmp_len = git_buf_len(path); int error; if (cmp_len <= strlen(".idx") || git__suffixcmp(path_str, ".idx") != 0) return 0; /* not an index */ cmp_len -= strlen(".idx"); for (i = 0; i < backend->packs.length; ++i) { struct git_pack_file *p = (git_pack_file*) git_vector_get(&backend->packs, i); if (memcmp(p->pack_name, path_str, cmp_len) == 0) return 0; } error = git_mwindow_get_pack(&pack, path->ptr); /* ignore missing .pack file as git does */ if (error == GIT_ENOTFOUND) { giterr_clear(); return 0; } if (!error) error = git_vector_insert(&backend->packs, pack); return error; }
static int scan_one_pack(void *state, char *name) { struct scanned_pack **ret = state, *r; char *s = strrchr(name, '/'), *d; if (git__prefixcmp(s + 1, "pack-") || git__suffixcmp(s, ".pack") || strlen(s + 1) != GIT_PACK_NAME_MAX + 4) return 0; d = strrchr(s + 1, '.'); strcpy(d + 1, "idx"); /* "pack-abc.pack" -> "pack-abc.idx" */ if (gitfo_exists(name)) return 0; if ((r = git__malloc(sizeof(*r))) == NULL) return GIT_ERROR; *d = '\0'; /* "pack-abc.pack" -_> "pack-abc" */ if ((r->pack = alloc_pack(s + 1)) == NULL) { free(r); return GIT_ERROR; } r->next = *ret; *ret = r; return 0; }
void test_repo_init__bare_repo_escaping_current_workdir(void) { git_buf path_repository = GIT_BUF_INIT; git_buf path_current_workdir = GIT_BUF_INIT; cl_git_pass(git_path_prettify_dir(&path_current_workdir, ".", NULL)); cl_git_pass(git_buf_joinpath(&path_repository, git_buf_cstr(&path_current_workdir), "a/b/c")); cl_git_pass(git_futils_mkdir_r(git_buf_cstr(&path_repository), GIT_DIR_MODE)); /* Change the current working directory */ cl_git_pass(chdir(git_buf_cstr(&path_repository))); /* Initialize a bare repo with a relative path escaping out of the current working directory */ cl_git_pass(git_repository_init(&_repo, "../d/e.git", 1)); cl_git_pass(git__suffixcmp(git_repository_path(_repo), "/a/b/d/e.git/")); git_repository_free(_repo); /* Open a bare repo with a relative path escaping out of the current working directory */ cl_git_pass(git_repository_open(&_repo, "../d/e.git")); cl_git_pass(chdir(git_buf_cstr(&path_current_workdir))); git_buf_free(&path_current_workdir); git_buf_free(&path_repository); cleanup_repository("a"); }
void test_repo_init__extended_with_template_and_shared_mode(void) { git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; int filemode = true; const char *repo_path = NULL; cl_set_cleanup(&cleanup_repository, "init_shared_from_tpl"); template_sandbox("template"); opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE; opts.template_path = "template"; opts.mode = GIT_REPOSITORY_INIT_SHARED_GROUP; cl_git_pass(git_repository_init_ext(&_repo, "init_shared_from_tpl", &opts)); cl_assert(!git_repository_is_bare(_repo)); cl_assert(!git__suffixcmp(git_repository_path(_repo), "/init_shared_from_tpl/.git/")); filemode = cl_repo_get_bool(_repo, "core.filemode"); repo_path = git_repository_path(_repo); assert_mode_seems_okay(repo_path, "hooks", GIT_FILEMODE_TREE | GIT_REPOSITORY_INIT_SHARED_GROUP, true, filemode); assert_mode_seems_okay(repo_path, "info", GIT_FILEMODE_TREE | GIT_REPOSITORY_INIT_SHARED_GROUP, true, filemode); assert_mode_seems_okay(repo_path, "description", GIT_FILEMODE_BLOB, false, filemode); validate_templates(_repo, "template"); cl_fixture_cleanup("template"); }
static int packfile_load__cb(void *_data, char *path) { struct pack_backend *backend = (struct pack_backend *)_data; struct git_pack_file *pack; int error; size_t i; if (git__suffixcmp(path, ".idx") != 0) return GIT_SUCCESS; /* not an index */ for (i = 0; i < backend->packs.length; ++i) { struct git_pack_file *p = git_vector_get(&backend->packs, i); if (memcmp(p->pack_name, path, strlen(path) - strlen(".idx")) == 0) return GIT_SUCCESS; } error = git_packfile_check(&pack, path); if (error < GIT_SUCCESS) return git__rethrow(error, "Failed to load packfile"); if (git_vector_insert(&backend->packs, pack) < GIT_SUCCESS) { free(pack); return GIT_ENOMEM; } return GIT_SUCCESS; }
void test_repo_open__bare_empty_repo(void) { git_repository *repo = cl_git_sandbox_init("empty_bare.git"); cl_assert(git_repository_path(repo) != NULL); cl_assert(git__suffixcmp(git_repository_path(repo), "/") == 0); cl_assert(git_repository_workdir(repo) == NULL); }
int git_attr_file__parse_buffer( git_repository *repo, const char *buffer, git_attr_file *attrs) { int error = 0; const char *scan = NULL; char *context = NULL; git_attr_rule *rule = NULL; assert(buffer && attrs); scan = buffer; /* if subdir file path, convert context for file paths */ if (attrs->key && git__suffixcmp(attrs->key, "/" GIT_ATTR_FILE) == 0) { context = attrs->key + 2; context[strlen(context) - strlen(GIT_ATTR_FILE)] = '\0'; } while (!error && *scan) { /* allocate rule if needed */ if (!rule && !(rule = git__calloc(1, sizeof(git_attr_rule)))) { error = -1; break; } /* parse the next "pattern attr attr attr" line */ if (!(error = git_attr_fnmatch__parse( &rule->match, attrs->pool, context, &scan)) && !(error = git_attr_assignment__parse( repo, attrs->pool, &rule->assigns, &scan))) { if (rule->match.flags & GIT_ATTR_FNMATCH_MACRO) /* should generate error/warning if this is coming from any * file other than .gitattributes at repo root. */ error = git_attr_cache__insert_macro(repo, rule); else error = git_vector_insert(&attrs->rules, rule); } /* if the rule wasn't a pattern, on to the next */ if (error < 0) { git_attr_rule__clear(rule); /* reset rule contents */ if (error == GIT_ENOTFOUND) error = 0; } else { rule = NULL; /* vector now "owns" the rule */ } } git_attr_rule__free(rule); /* restore file path used for context */ if (context) context[strlen(context)] = '.'; /* first char of GIT_ATTR_FILE */ return error; }
void test_repo_init__extended_0(void) { git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; /* without MKDIR this should fail */ cl_git_fail(git_repository_init_ext(&_repo, "extended", &opts)); /* make the directory first, then it should succeed */ cl_git_pass(git_futils_mkdir("extended", 0775, 0)); cl_git_pass(git_repository_init_ext(&_repo, "extended", &opts)); cl_assert(!git__suffixcmp(git_repository_workdir(_repo), "/extended/")); cl_assert(!git__suffixcmp(git_repository_path(_repo), "/extended/.git/")); cl_assert(!git_repository_is_bare(_repo)); cl_assert(git_repository_is_empty(_repo)); cleanup_repository("extended"); }
void test_repo_init__extended_1(void) { git_reference *ref; git_remote *remote; struct stat st; git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_NO_DOTGIT_DIR; opts.mode = GIT_REPOSITORY_INIT_SHARED_GROUP; opts.workdir_path = "../c_wd"; opts.description = "Awesomest test repository evah"; opts.initial_head = "development"; opts.origin_url = "https://github.com/libgit2/libgit2.git"; cl_git_pass(git_repository_init_ext(&_repo, "root/b/c.git", &opts)); cl_assert(!git__suffixcmp(git_repository_workdir(_repo), "/c_wd/")); cl_assert(!git__suffixcmp(git_repository_path(_repo), "/c.git/")); cl_assert(git_path_isfile("root/b/c_wd/.git")); cl_assert(!git_repository_is_bare(_repo)); /* repo will not be counted as empty because we set head to "development" */ cl_assert(!git_repository_is_empty(_repo)); cl_git_pass(git_path_lstat(git_repository_path(_repo), &st)); cl_assert(S_ISDIR(st.st_mode)); if (cl_is_chmod_supported()) cl_assert((S_ISGID & st.st_mode) == S_ISGID); else cl_assert((S_ISGID & st.st_mode) == 0); cl_git_pass(git_reference_lookup(&ref, _repo, "HEAD")); cl_assert(git_reference_type(ref) == GIT_REF_SYMBOLIC); cl_assert_equal_s("refs/heads/development", git_reference_symbolic_target(ref)); git_reference_free(ref); cl_git_pass(git_remote_lookup(&remote, _repo, "origin")); cl_assert_equal_s("origin", git_remote_name(remote)); cl_assert_equal_s(opts.origin_url, git_remote_url(remote)); git_remote_free(remote); git_repository_free(_repo); cl_fixture_cleanup("root"); }
/* compare suffixes */ void test_core_string__1(void) { cl_assert(git__suffixcmp("", "") == 0); cl_assert(git__suffixcmp("a", "") == 0); cl_assert(git__suffixcmp("", "a") < 0); cl_assert(git__suffixcmp("a", "b") < 0); cl_assert(git__suffixcmp("b", "a") > 0); cl_assert(git__suffixcmp("ba", "a") == 0); cl_assert(git__suffixcmp("zaa", "ac") < 0); cl_assert(git__suffixcmp("zaz", "ac") > 0); }
void test_repo_open__win32_path(void) { #ifdef GIT_WIN32 git_repository *repo = cl_git_sandbox_init("empty_standard_repo"), *repo2; git_buf winpath = GIT_BUF_INIT; static const char *repo_path = "empty_standard_repo/.git/"; static const char *repo_wd = "empty_standard_repo/"; cl_assert(git__suffixcmp(git_repository_path(repo), repo_path) == 0); cl_assert(git__suffixcmp(git_repository_workdir(repo), repo_wd) == 0); cl_git_pass(git_buf_sets(&winpath, git_repository_path(repo))); unposix_path(&winpath); cl_git_pass(git_repository_open(&repo2, winpath.ptr)); cl_assert(git__suffixcmp(git_repository_path(repo2), repo_path) == 0); cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0); git_repository_free(repo2); cl_git_pass(git_buf_sets(&winpath, git_repository_path(repo))); git_buf_truncate(&winpath, winpath.size - 1); /* remove trailing '/' */ unposix_path(&winpath); cl_git_pass(git_repository_open(&repo2, winpath.ptr)); cl_assert(git__suffixcmp(git_repository_path(repo2), repo_path) == 0); cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0); git_repository_free(repo2); cl_git_pass(git_buf_sets(&winpath, git_repository_workdir(repo))); unposix_path(&winpath); cl_git_pass(git_repository_open(&repo2, winpath.ptr)); cl_assert(git__suffixcmp(git_repository_path(repo2), repo_path) == 0); cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0); git_repository_free(repo2); cl_git_pass(git_buf_sets(&winpath, git_repository_workdir(repo))); git_buf_truncate(&winpath, winpath.size - 1); /* remove trailing '/' */ unposix_path(&winpath); cl_git_pass(git_repository_open(&repo2, winpath.ptr)); cl_assert(git__suffixcmp(git_repository_path(repo2), repo_path) == 0); cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0); git_repository_free(repo2); git_buf_free(&winpath); #endif }
int git_attr_file__parse_buffer( git_repository *repo, git_attr_file *attrs, const char *data) { int error = 0; const char *scan = data, *context = NULL; git_attr_rule *rule = NULL; /* if subdir file path, convert context for file paths */ if (attrs->entry && git_path_root(attrs->entry->path) < 0 && !git__suffixcmp(attrs->entry->path, "/" GIT_ATTR_FILE)) context = attrs->entry->path; if (git_mutex_lock(&attrs->lock) < 0) { giterr_set(GITERR_OS, "Failed to lock attribute file"); return -1; } while (!error && *scan) { /* allocate rule if needed */ if (!rule && !(rule = git__calloc(1, sizeof(*rule)))) { error = -1; break; } rule->match.flags = GIT_ATTR_FNMATCH_ALLOWNEG | GIT_ATTR_FNMATCH_ALLOWMACRO; /* parse the next "pattern attr attr attr" line */ if (!(error = git_attr_fnmatch__parse( &rule->match, &attrs->pool, context, &scan)) && !(error = git_attr_assignment__parse( repo, &attrs->pool, &rule->assigns, &scan))) { if (rule->match.flags & GIT_ATTR_FNMATCH_MACRO) /* TODO: warning if macro found in file below repo root */ error = git_attr_cache__insert_macro(repo, rule); else error = git_vector_insert(&attrs->rules, rule); } /* if the rule wasn't a pattern, on to the next */ if (error < 0) { git_attr_rule__clear(rule); /* reset rule contents */ if (error == GIT_ENOTFOUND) error = 0; } else { rule = NULL; /* vector now "owns" the rule */ } } git_mutex_unlock(&attrs->lock); git_attr_rule__free(rule); return error; }
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; make_gitlink_dir("alternate", "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); }
void test_repo_init__extended_with_template_and_shared_mode(void) { git_buf expected = GIT_BUF_INIT; git_buf actual = GIT_BUF_INIT; git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; int filemode = true; const char *repo_path = NULL; cl_set_cleanup(&cleanup_repository, "init_shared_from_tpl"); template_sandbox("template"); opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE; opts.template_path = "template"; opts.mode = GIT_REPOSITORY_INIT_SHARED_GROUP; cl_git_pass(git_repository_init_ext(&_repo, "init_shared_from_tpl", &opts)); cl_assert(!git_repository_is_bare(_repo)); cl_assert(!git__suffixcmp(git_repository_path(_repo), "/init_shared_from_tpl/.git/")); filemode = cl_repo_get_bool(_repo, "core.filemode"); cl_git_pass(git_futils_readbuffer( &expected, "template/description")); cl_git_pass(git_futils_readbuffer( &actual, "init_shared_from_tpl/.git/description")); cl_assert_equal_s(expected.ptr, actual.ptr); git_buf_free(&expected); git_buf_free(&actual); repo_path = git_repository_path(_repo); assert_mode_seems_okay(repo_path, "hooks", GIT_FILEMODE_TREE | GIT_REPOSITORY_INIT_SHARED_GROUP, true, filemode); assert_mode_seems_okay(repo_path, "info", GIT_FILEMODE_TREE | GIT_REPOSITORY_INIT_SHARED_GROUP, true, filemode); assert_mode_seems_okay(repo_path, "description", GIT_FILEMODE_BLOB, false, filemode); /* for a non-symlinked hook, it should have shared permissions now */ assert_hooks_match( "template", git_repository_path(_repo), "hooks/update.sample", filemode); /* for a symlinked hook, the permissions still should match the * source link, not the GIT_REPOSITORY_INIT_SHARED_GROUP value */ assert_hooks_match( "template", git_repository_path(_repo), "hooks/link.sample", filemode); cl_fixture_cleanup("template"); }
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"); }
void test_repo_setters__setting_a_workdir_creates_a_gitlink(void) { git_config *cfg; git_buf buf = GIT_BUF_INIT; git_buf content = GIT_BUF_INIT; cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", true)); cl_assert(git_path_isfile("./new_workdir/.git")); cl_git_pass(git_futils_readbuffer(&content, "./new_workdir/.git")); cl_assert(git__prefixcmp(git_buf_cstr(&content), "gitdir: ") == 0); cl_assert(git__suffixcmp(git_buf_cstr(&content), "testrepo.git/") == 0); git_buf_free(&content); cl_git_pass(git_repository_config(&cfg, repo)); cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.worktree")); cl_assert(git__suffixcmp(git_buf_cstr(&buf), "new_workdir/") == 0); git_buf_free(&buf); git_config_free(cfg); }
static int confirm_submodule_status( const char *path, unsigned int status_flags, void *payload) { submodule_expectations *exp = payload; while (git__suffixcmp(exp->paths[exp->counter], "/") == 0) exp->counter++; cl_assert_equal_s(exp->paths[exp->counter++], path); GIT_UNUSED(status_flags); return 0; }
void test_repo_init__extended_with_template(void) { git_repository_init_options opts; memset(&opts, 0, sizeof(opts)); opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE; opts.template_path = cl_fixture("template"); cl_git_pass(git_repository_init_ext(&_repo, "templated.git", &opts)); cl_assert(git_repository_is_bare(_repo)); cl_assert(!git__suffixcmp(git_repository_path(_repo), "/templated.git/")); cleanup_repository("templated.git"); }
static int remove_file_cb(void *data, git_buf *file) { const char *filename = git_buf_cstr(file); GIT_UNUSED(data); if (git__suffixcmp(filename, ".git") == 0) return 0; if (git_path_isdir(filename)) cl_git_pass(git_futils_rmdir_r(filename, NULL, GIT_RMDIR_REMOVE_FILES)); else cl_git_pass(p_unlink(git_buf_cstr(file))); return 0; }
void test_repo_init__external_templates_specified_in_options(void) { git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; cl_set_cleanup(&cleanup_repository, "templated.git"); template_sandbox("template"); opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE; opts.template_path = "template"; cl_git_pass(git_repository_init_ext(&_repo, "templated.git", &opts)); cl_assert(git_repository_is_bare(_repo)); cl_assert(!git__suffixcmp(git_repository_path(_repo), "/templated.git/")); validate_templates(_repo, "template"); cl_fixture_cleanup("template"); }
void test_repo_init__extended_with_template(void) { git_buf expected = GIT_BUF_INIT; git_buf actual = GIT_BUF_INIT; git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; int filemode; cl_set_cleanup(&cleanup_repository, "templated.git"); template_sandbox("template"); opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE; opts.template_path = "template"; cl_git_pass(git_repository_init_ext(&_repo, "templated.git", &opts)); cl_assert(git_repository_is_bare(_repo)); cl_assert(!git__suffixcmp(git_repository_path(_repo), "/templated.git/")); cl_git_pass(git_futils_readbuffer(&expected, "template/description")); cl_git_pass(git_futils_readbuffer( &actual, "templated.git/description")); cl_assert_equal_s(expected.ptr, actual.ptr); git_buf_free(&expected); git_buf_free(&actual); filemode = cl_repo_get_bool(_repo, "core.filemode"); assert_hooks_match( "template", git_repository_path(_repo), "hooks/update.sample", filemode); assert_hooks_match( "template", git_repository_path(_repo), "hooks/link.sample", filemode); cl_fixture_cleanup("template"); }
static int addall_match_suffix( const char *path, const char *matched_pathspec, void *payload) { GIT_UNUSED(matched_pathspec); return !git__suffixcmp(path, payload) ? 0 : 1; }