void test_filter_blob__ident(void) { git_oid id; git_blob *blob; git_buf buf = { 0 }; cl_git_mkfile("crlf/test.ident", "Some text\n$Id$\nGoes there\n"); cl_git_pass(git_blob_create_fromworkdir(&id, g_repo, "test.ident")); cl_git_pass(git_blob_lookup(&blob, g_repo, &id)); cl_assert_equal_s( "Some text\n$Id$\nGoes there\n", git_blob_rawcontent(blob)); git_blob_free(blob); cl_git_mkfile("crlf/test.ident", "Some text\n$Id: Any old just you want$\nGoes there\n"); cl_git_pass(git_blob_create_fromworkdir(&id, g_repo, "test.ident")); cl_git_pass(git_blob_lookup(&blob, g_repo, &id)); cl_assert_equal_s( "Some text\n$Id$\nGoes there\n", git_blob_rawcontent(blob)); cl_git_pass(git_blob_filtered_content(&buf, blob, "filter.bin", 1)); cl_assert_equal_s( "Some text\n$Id$\nGoes there\n", buf.ptr); cl_git_pass(git_blob_filtered_content(&buf, blob, "filter.identcrlf", 1)); cl_assert_equal_s( "Some text\r\n$Id: 3164f585d548ac68027d22b104f2d8100b2b6845$\r\nGoes there\r\n", buf.ptr); cl_git_pass(git_blob_filtered_content(&buf, blob, "filter.identlf", 1)); cl_assert_equal_s( "Some text\n$Id: 3164f585d548ac68027d22b104f2d8100b2b6845$\nGoes there\n", buf.ptr); git_buf_free(&buf); git_blob_free(blob); }
PyObject * Repository_create_blob_fromworkdir(Repository *self, PyObject *args) { git_oid oid; const char* path; int err; if (!PyArg_ParseTuple(args, "s", &path)) return NULL; err = git_blob_create_fromworkdir(&oid, self->repo, path); if (err < 0) return Error_set(err); return git_oid_to_python(&oid); }
/* * call-seq: * Blob.from_workdir(repository, file_path) -> oid * * Write the file specified in +file_path+ to a blob in +repository+. * +file_path+ must be relative to the repository's working folder. * The repository cannot be bare. * * Blob.from_workdir(repo, 'src/blob.h') #=> '9d09060c850defbc7711d08b57def0d14e742f4e' */ static VALUE rb_git_blob_from_workdir(VALUE self, VALUE rb_repo, VALUE rb_path) { int error; git_oid oid; git_repository *repo; Check_Type(rb_path, T_STRING); rugged_check_repo(rb_repo); Data_Get_Struct(rb_repo, git_repository, repo); error = git_blob_create_fromworkdir(&oid, repo, StringValueCStr(rb_path)); rugged_exception_check(error); return rugged_create_oid(&oid); }
static void add_blob_and_filter( const char *data, git_filter_list *fl, const char *expected) { git_oid id; git_blob *blob; git_buf out = { 0 }; cl_git_mkfile("crlf/identtest", data); cl_git_pass(git_blob_create_fromworkdir(&id, g_repo, "identtest")); cl_git_pass(git_blob_lookup(&blob, g_repo, &id)); cl_git_pass(git_filter_list_apply_to_blob(&out, fl, blob)); cl_assert_equal_s(expected, out.ptr); git_blob_free(blob); git_buf_free(&out); }
int merge_test_workdir(git_repository *repo, const struct merge_index_entry expected[], size_t expected_len) { size_t actual_len = 0, i; git_oid actual_oid, expected_oid; git_buf wd = GIT_BUF_INIT; git_buf_puts(&wd, repo->workdir); git_path_direach(&wd, 0, dircount, &actual_len); if (actual_len != expected_len) return 0; for (i = 0; i < expected_len; i++) { git_blob_create_fromworkdir(&actual_oid, repo, expected[i].path); git_oid_fromstr(&expected_oid, expected[i].oid_str); if (git_oid_cmp(&actual_oid, &expected_oid) != 0) return 0; } git_buf_free(&wd); return 1; }
int configctl_git_commit(char *path) { int rc; int git_status = -1; git_oid oid_blob; git_oid oid_tree; git_oid oid_commit; git_blob *blob; git_tree *tree_cmt; git_treebuilder *tree_bld; char *file; file = get_file(path); #if 0 // TODO: check if file is changed __debug("%s", file); git_diff_stats *stats; git_diff *diff; git_diff_options opts = GIT_DIFF_OPTIONS_INIT; opts.pathspec.strings = &file; opts.pathspec.count = 1; rc = git_diff_index_to_workdir(&diff, repo, NULL, &opts); if(rc) goto error; int diff_num = git_diff_num_deltas(diff); __debug("%d", diff_num); git_diff_get_stats(&stats, diff); int x = git_diff_stats_files_changed(stats); __debug("%d", x); git_diff_free(diff); #endif rc = git_add(file); if (rc) goto error; rc = git_blob_create_fromworkdir(&oid_blob, repo, file); if (rc) goto error; rc = git_blob_lookup(&blob, repo, &oid_blob); if (rc) goto error; rc = git_treebuilder_new(&tree_bld, repo, NULL ); if (0 == rc) { rc = git_treebuilder_insert(NULL, tree_bld, file, &oid_blob, GIT_FILEMODE_BLOB); if (!rc) { rc = git_treebuilder_write(&oid_tree, tree_bld); if (!rc) { rc = git_tree_lookup(&tree_cmt, repo, &oid_tree); if (0 == rc) { git_commit *commit; commit = get_last_commit(); git_signature_now(&sign, sign_name, sign_email); rc = git_commit_create(&oid_commit, repo, "HEAD", sign, sign, NULL, commit_message, tree_cmt, 1, (const struct git_commit **) &commit); if (!rc) { git_status = 0; __debug("successful git commit"); } git_tree_free( tree_cmt ); git_commit_free(commit); git_signature_free(sign); } } } git_treebuilder_free(tree_bld); } git_blob_free( blob ); error: return git_status; }