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); }
int git_config_find_system(char *system_config_path) { const char *etc = "/etc/gitconfig"; if (git_futils_exists(etc) == GIT_SUCCESS) { memcpy(system_config_path, etc, strlen(etc) + 1); return GIT_SUCCESS; } #if GIT_WIN32 return win32_find_system(system_config_path); #else return GIT_ENOTFOUND; #endif }
/* make sure git_filebuf_open doesn't delete an existing lock */ void test_core_filebuf__0(void) { git_filebuf file; int fd; char test[] = "test", testlock[] = "test.lock"; fd = p_creat(testlock, 0744); cl_must_pass(fd); cl_must_pass(p_close(fd)); cl_git_fail(git_filebuf_open(&file, test, 0)); cl_git_pass(git_futils_exists(testlock)); cl_must_pass(p_unlink(testlock)); }
int git_config_find_global(char *global_config_path) { const char *home; home = getenv("HOME"); #ifdef GIT_WIN32 if (home == NULL) home = getenv("USERPROFILE"); #endif if (home == NULL) return git__throw(GIT_EOSERR, "Failed to open global config file. Cannot locate the user's home directory"); git_path_join(global_config_path, home, GIT_CONFIG_FILENAME); if (git_futils_exists(global_config_path) < GIT_SUCCESS) return git__throw(GIT_EOSERR, "Failed to open global config file. The file does not exist"); return GIT_SUCCESS; }
int git_index_read(git_index *index) { struct stat indexst; int error = GIT_SUCCESS; assert(index->index_file_path); if (!index->on_disk || git_futils_exists(index->index_file_path) < 0) { git_index_clear(index); index->on_disk = 0; return GIT_SUCCESS; } if (p_stat(index->index_file_path, &indexst) < 0) return git__throw(GIT_EOSERR, "Failed to read index. %s does not exist or is corrupted", index->index_file_path); if (!S_ISREG(indexst.st_mode)) return git__throw(GIT_ENOTFOUND, "Failed to read index. %s is not an index file", index->index_file_path); if (indexst.st_mtime != index->last_modified) { git_fbuffer buffer; if ((error = git_futils_readbuffer(&buffer, index->index_file_path)) < GIT_SUCCESS) return git__rethrow(error, "Failed to read index"); git_index_clear(index); error = parse_index(index, buffer.data, buffer.len); if (error == GIT_SUCCESS) index->last_modified = indexst.st_mtime; git_futils_freebuffer(&buffer); } if (error < GIT_SUCCESS) return git__rethrow(error, "Failed to read index"); return error; }
* pack weak tags */ must_pass(git_reference_packall(repo)); /* Ensure the packed-refs file exists */ git_path_join(temp_path, repo->path_repository, GIT_PACKEDREFS_FILE); must_pass(git_futils_exists(temp_path)); /* Ensure the known ref can still be looked up but is now packed */ must_pass(git_reference_lookup(&reference, repo, loose_tag_ref_name)); must_be_true((reference->type & GIT_REF_PACKED) != 0); must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0); /* Ensure the known ref has been removed from the loose folder structure */ git_path_join(temp_path, repo->path_repository, loose_tag_ref_name); must_pass(!git_futils_exists(temp_path)); close_temp_repo(repo); END_TEST BEGIN_TEST(rename0, "rename a loose reference") git_reference *looked_up_ref, *another_looked_up_ref; git_repository *repo; char temp_path[GIT_PATH_MAX]; const char *new_name = "refs/tags/Nemo/knows/refs.kung-fu"; must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); /* Ensure the ref doesn't exist on the file system */ git_path_join(temp_path, repo->path_repository, new_name); must_pass(!git_futils_exists(temp_path));