void test_core_env__1(void) { git_buf path = GIT_BUF_INIT; cl_assert(git_futils_find_global_file(&path, "nonexistentfile") == GIT_ENOTFOUND); #ifdef GIT_WIN32 cl_git_pass(cl_setenv("USERPROFILE", "doesnotexist")); #else cl_git_pass(cl_setenv("HOME", "doesnotexist")); #endif cl_assert(git_futils_find_global_file(&path, "nonexistentfile") == GIT_ENOTFOUND); #ifdef GIT_WIN32 cl_git_pass(cl_setenv("USERPROFILE", NULL)); #else cl_git_pass(cl_setenv("HOME", NULL)); #endif cl_assert(git_futils_find_global_file(&path, "nonexistentfile") == -1); cl_assert(git_futils_find_system_file(&path, "nonexistentfile") == GIT_ENOTFOUND); #ifdef GIT_WIN32 cl_git_pass(cl_setenv("PROGRAMFILES", NULL)); cl_assert(git_futils_find_system_file(&path, "nonexistentfile") == -1); #endif git_buf_free(&path); }
void test_core_env__cleanup(void) { #ifdef GIT_WIN32 cl_setenv("USERPROFILE", env_userprofile); git__free(env_userprofile); cl_setenv("PROGRAMFILES", env_programfiles); git__free(env_programfiles); #else cl_setenv("HOME", env_home); #endif }
void test_core_env__0(void) { static char *home_values[] = { "fake_home", "fáke_hõme", /* all in latin-1 supplement */ "fĀke_Ĥome", /* latin extended */ "fακε_hοmέ", /* having fun with greek */ "faงe_นome", /* now I have no idea, but thai characters */ "f\xe1\x9cx80ke_\xe1\x9c\x91ome", /* tagalog characters */ "\xe1\xb8\x9fẢke_hoṁe", /* latin extended additional */ "\xf0\x9f\x98\x98\xf0\x9f\x98\x82", /* emoticons */ NULL }; git_buf path = GIT_BUF_INIT, found = GIT_BUF_INIT; char **val; char *check; for (val = home_values; *val != NULL; val++) { if (p_mkdir(*val, 0777) == 0) { /* if we can't make the directory, let's just assume * we are on a filesystem that doesn't support the * characters in question and skip this test... */ cl_git_pass(git_path_prettify(&path, *val, NULL)); #ifdef GIT_WIN32 cl_git_pass(cl_setenv("USERPROFILE", path.ptr)); /* do a quick check that it was set correctly */ check = cl_getenv("USERPROFILE"); cl_assert_equal_s(path.ptr, check); git__free(check); #else cl_git_pass(cl_setenv("HOME", path.ptr)); /* do a quick check that it was set correctly */ check = cl_getenv("HOME"); cl_assert_equal_s(path.ptr, check); #endif cl_git_pass(git_buf_puts(&path, "/testfile")); cl_git_mkfile(path.ptr, "find me"); cl_git_pass(git_futils_find_global_file(&found, "testfile")); } } git_buf_free(&path); git_buf_free(&found); }
void test_refs_revparse__initialize(void) { char *tz = cl_getenv("TZ"); if (tz) strcpy(g_orig_tz, tz); cl_setenv("TZ", "UTC"); g_repo = cl_git_sandbox_init("testrepo.git"); }
static void clear_git_env(void) { cl_setenv("GIT_DIR", NULL); cl_setenv("GIT_CEILING_DIRECTORIES", NULL); cl_setenv("GIT_INDEX_FILE", NULL); cl_setenv("GIT_NAMESPACE", NULL); cl_setenv("GIT_OBJECT_DIRECTORY", NULL); cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", NULL); cl_setenv("GIT_WORK_TREE", NULL); cl_setenv("GIT_COMMON_DIR", NULL); }
static int GIT_FORMAT_PRINTF(2, 3) cl_setenv_printf(const char *name, const char *fmt, ...) { int ret; va_list args; git_buf buf = GIT_BUF_INIT; va_start(args, fmt); cl_git_pass(git_buf_vprintf(&buf, fmt, args)); va_end(args); ret = cl_setenv(name, git_buf_cstr(&buf)); git_buf_free(&buf); return ret; }
void test_repo_env__open(void) { git_repository *repo = NULL; git_buf repo_dir_buf = GIT_BUF_INIT; const char *repo_dir = NULL; git_index *index = NULL; const char *t_obj = "testrepo.git/objects"; const char *p_obj = "peeled.git/objects"; clear_git_env(); cl_fixture_sandbox("attr"); cl_fixture_sandbox("testrepo.git"); cl_fixture_sandbox("peeled.git"); cl_git_pass(p_rename("attr/.gitted", "attr/.git")); cl_git_pass(git_path_prettify_dir(&repo_dir_buf, "attr", NULL)); repo_dir = git_buf_cstr(&repo_dir_buf); /* GIT_DIR that doesn't exist */ cl_setenv("GIT_DIR", "does-not-exist"); env_fail(NULL); /* Explicit start_path overrides GIT_DIR */ env_pass("attr"); env_pass("attr/.git"); env_pass("attr/sub"); env_pass("attr/sub/sub"); /* GIT_DIR with relative paths */ cl_setenv("GIT_DIR", "attr/.git"); env_pass(NULL); cl_setenv("GIT_DIR", "attr"); env_fail(NULL); cl_setenv("GIT_DIR", "attr/sub"); env_fail(NULL); cl_setenv("GIT_DIR", "attr/sub/sub"); env_fail(NULL); /* GIT_DIR with absolute paths */ cl_setenv_printf("GIT_DIR", "%s/.git", repo_dir); env_pass(NULL); cl_setenv("GIT_DIR", repo_dir); env_fail(NULL); cl_setenv_printf("GIT_DIR", "%s/sub", repo_dir); env_fail(NULL); cl_setenv_printf("GIT_DIR", "%s/sub/sub", repo_dir); env_fail(NULL); cl_setenv("GIT_DIR", NULL); /* Searching from the current directory */ env_cd_pass("attr"); env_cd_pass("attr/.git"); env_cd_pass("attr/sub"); env_cd_pass("attr/sub/sub"); /* A ceiling directory blocks searches from ascending into that * directory, but doesn't block the start_path itself. */ cl_setenv("GIT_CEILING_DIRECTORIES", repo_dir); env_cd_pass("attr"); env_cd_fail("attr/sub"); env_cd_fail("attr/sub/sub"); cl_setenv_printf("GIT_CEILING_DIRECTORIES", "%s/sub", repo_dir); env_cd_pass("attr"); env_cd_pass("attr/sub"); env_cd_fail("attr/sub/sub"); /* Multiple ceiling directories */ cl_setenv_printf("GIT_CEILING_DIRECTORIES", "123%c%s/sub%cabc", GIT_PATH_LIST_SEPARATOR, repo_dir, GIT_PATH_LIST_SEPARATOR); env_cd_pass("attr"); env_cd_pass("attr/sub"); env_cd_fail("attr/sub/sub"); cl_setenv_printf("GIT_CEILING_DIRECTORIES", "%s%c%s/sub", repo_dir, GIT_PATH_LIST_SEPARATOR, repo_dir); env_cd_pass("attr"); env_cd_fail("attr/sub"); env_cd_fail("attr/sub/sub"); cl_setenv_printf("GIT_CEILING_DIRECTORIES", "%s/sub%c%s", repo_dir, GIT_PATH_LIST_SEPARATOR, repo_dir); env_cd_pass("attr"); env_cd_fail("attr/sub"); env_cd_fail("attr/sub/sub"); cl_setenv_printf("GIT_CEILING_DIRECTORIES", "%s%c%s/sub/sub", repo_dir, GIT_PATH_LIST_SEPARATOR, repo_dir); env_cd_pass("attr"); env_cd_fail("attr/sub"); env_cd_fail("attr/sub/sub"); cl_setenv("GIT_CEILING_DIRECTORIES", NULL); /* Index files */ cl_setenv("GIT_INDEX_FILE", cl_fixture("gitgit.index")); cl_git_pass(git_repository_open_ext(&repo, "attr", GIT_REPOSITORY_OPEN_FROM_ENV, NULL)); cl_git_pass(git_repository_index(&index, repo)); cl_assert_equal_s(git_index_path(index), cl_fixture("gitgit.index")); cl_assert_equal_i(git_index_entrycount(index), 1437); git_index_free(index); git_repository_free(repo); cl_setenv("GIT_INDEX_FILE", NULL); /* Namespaces */ cl_setenv("GIT_NAMESPACE", "some-namespace"); cl_git_pass(git_repository_open_ext(&repo, "attr", GIT_REPOSITORY_OPEN_FROM_ENV, NULL)); cl_assert_equal_s(git_repository_get_namespace(repo), "some-namespace"); git_repository_free(repo); cl_setenv("GIT_NAMESPACE", NULL); /* Object directories and alternates */ env_check_objects(true, false, false); cl_setenv("GIT_OBJECT_DIRECTORY", t_obj); env_check_objects(false, true, false); cl_setenv("GIT_OBJECT_DIRECTORY", NULL); cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", t_obj); env_check_objects(true, true, false); cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", NULL); cl_setenv("GIT_OBJECT_DIRECTORY", p_obj); env_check_objects(false, false, true); cl_setenv("GIT_OBJECT_DIRECTORY", NULL); cl_setenv("GIT_OBJECT_DIRECTORY", t_obj); cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", p_obj); env_check_objects(false, true, true); cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", NULL); cl_setenv("GIT_OBJECT_DIRECTORY", NULL); cl_setenv_printf("GIT_ALTERNATE_OBJECT_DIRECTORIES", "%s%c%s", t_obj, GIT_PATH_LIST_SEPARATOR, p_obj); env_check_objects(true, true, true); cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", NULL); cl_setenv_printf("GIT_ALTERNATE_OBJECT_DIRECTORIES", "%s%c%s", p_obj, GIT_PATH_LIST_SEPARATOR, t_obj); env_check_objects(true, true, true); cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", NULL); cl_fixture_cleanup("peeled.git"); cl_fixture_cleanup("testrepo.git"); cl_fixture_cleanup("attr"); git_buf_free(&repo_dir_buf); clear_git_env(); }
void test_refs_revparse__cleanup(void) { cl_git_sandbox_cleanup(); g_obj = NULL; cl_setenv("TZ", g_orig_tz); }