diff options
author | Russell Belfer <rb@github.com> | 2013-09-06 02:06:42 +0400 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-09-17 20:31:46 +0400 |
commit | 155fa2342d838bdb2aa873c95a42e091351bb69a (patch) | |
tree | 4441514a2ad0b4cb2c0e088e03864b9d9f7acbe6 /tests-clar/stash | |
parent | 13f36ffb9e1c4fb70b44a477d716873fecfc0407 (diff) |
Add clar helper to create new commit from index
There were a lot of places in the test code base that were creating
a commit from the index on the current branch. This just adds a
helper to handle that case pretty easily. There was only one test
where this change ended up tweaking the test data, so pretty easy
and mostly just a cleanup.
Diffstat (limited to 'tests-clar/stash')
-rw-r--r-- | tests-clar/stash/drop.c | 16 | ||||
-rw-r--r-- | tests-clar/stash/save.c | 5 | ||||
-rw-r--r-- | tests-clar/stash/stash_helpers.c | 33 | ||||
-rw-r--r-- | tests-clar/stash/stash_helpers.h | 5 |
4 files changed, 12 insertions, 47 deletions
diff --git a/tests-clar/stash/drop.c b/tests-clar/stash/drop.c index 60b3c72e0..59413f01e 100644 --- a/tests-clar/stash/drop.c +++ b/tests-clar/stash/drop.c @@ -36,25 +36,27 @@ static void push_three_states(void) cl_git_mkfile("stash/zero.txt", "content\n"); cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_index_add_bypath(index, "zero.txt")); - commit_staged_files(&oid, index, signature); + cl_repo_commit_from_index(NULL, repo, signature, 0, "Initial commit"); cl_assert(git_path_exists("stash/zero.txt")); + git_index_free(index); cl_git_mkfile("stash/one.txt", "content\n"); - cl_git_pass(git_stash_save(&oid, repo, signature, "First", GIT_STASH_INCLUDE_UNTRACKED)); + cl_git_pass(git_stash_save( + &oid, repo, signature, "First", GIT_STASH_INCLUDE_UNTRACKED)); cl_assert(!git_path_exists("stash/one.txt")); cl_assert(git_path_exists("stash/zero.txt")); cl_git_mkfile("stash/two.txt", "content\n"); - cl_git_pass(git_stash_save(&oid, repo, signature, "Second", GIT_STASH_INCLUDE_UNTRACKED)); + cl_git_pass(git_stash_save( + &oid, repo, signature, "Second", GIT_STASH_INCLUDE_UNTRACKED)); cl_assert(!git_path_exists("stash/two.txt")); cl_assert(git_path_exists("stash/zero.txt")); cl_git_mkfile("stash/three.txt", "content\n"); - cl_git_pass(git_stash_save(&oid, repo, signature, "Third", GIT_STASH_INCLUDE_UNTRACKED)); + cl_git_pass(git_stash_save( + &oid, repo, signature, "Third", GIT_STASH_INCLUDE_UNTRACKED)); cl_assert(!git_path_exists("stash/three.txt")); cl_assert(git_path_exists("stash/zero.txt")); - - git_index_free(index); } void test_stash_drop__cannot_drop_a_non_existing_stashed_state(void) @@ -160,7 +162,7 @@ void test_stash_drop__dropping_the_top_stash_updates_the_stash_reference(void) retrieve_top_stash_id(&oid); cl_git_pass(git_revparse_single(&next_top_stash, repo, "stash@{1}")); - cl_assert_equal_i(false, git_oid_cmp(&oid, git_object_id(next_top_stash)) == 0); + cl_assert(git_oid_cmp(&oid, git_object_id(next_top_stash)) != 0); cl_git_pass(git_stash_drop(repo, 0)); diff --git a/tests-clar/stash/save.c b/tests-clar/stash/save.c index bb35a3d71..035b62279 100644 --- a/tests-clar/stash/save.c +++ b/tests-clar/stash/save.c @@ -241,7 +241,7 @@ void test_stash_save__stashing_updates_the_reflog(void) void test_stash_save__cannot_stash_when_there_are_no_local_change(void) { git_index *index; - git_oid commit_oid, stash_tip_oid; + git_oid stash_tip_oid; cl_git_pass(git_repository_index(&index, repo)); @@ -251,8 +251,7 @@ void test_stash_save__cannot_stash_when_there_are_no_local_change(void) */ cl_git_pass(git_index_add_bypath(index, "what")); cl_git_pass(git_index_add_bypath(index, "who")); - cl_git_pass(git_index_write(index)); - commit_staged_files(&commit_oid, index, signature); + cl_repo_commit_from_index(NULL, repo, signature, 0, "Initial commit"); git_index_free(index); cl_assert_equal_i(GIT_ENOTFOUND, diff --git a/tests-clar/stash/stash_helpers.c b/tests-clar/stash/stash_helpers.c index f462a1351..06b63f177 100644 --- a/tests-clar/stash/stash_helpers.c +++ b/tests-clar/stash/stash_helpers.c @@ -2,38 +2,8 @@ #include "fileops.h" #include "stash_helpers.h" -void commit_staged_files( - git_oid *commit_oid, - git_index *index, - git_signature *signature) -{ - git_tree *tree; - git_oid tree_oid; - git_repository *repo; - - repo = git_index_owner(index); - - cl_git_pass(git_index_write_tree(&tree_oid, index)); - - cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid)); - - cl_git_pass(git_commit_create_v( - commit_oid, - repo, - "HEAD", - signature, - signature, - NULL, - "Initial commit", - tree, - 0)); - - git_tree_free(tree); -} - void setup_stash(git_repository *repo, git_signature *signature) { - git_oid commit_oid; git_index *index; cl_git_pass(git_repository_index(&index, repo)); @@ -50,9 +20,8 @@ void setup_stash(git_repository *repo, git_signature *signature) cl_git_pass(git_index_add_bypath(index, "how")); cl_git_pass(git_index_add_bypath(index, "who")); cl_git_pass(git_index_add_bypath(index, ".gitignore")); - cl_git_pass(git_index_write(index)); - commit_staged_files(&commit_oid, index, signature); + cl_repo_commit_from_index(NULL, repo, signature, 0, "Initial commit"); cl_git_rewritefile("stash/what", "goodbye\n"); /* dd7e1c6f0fefe118f0b63d9f10908c460aa317a6 */ cl_git_rewritefile("stash/how", "not so small and\n"); /* e6d64adb2c7f3eb8feb493b556cc8070dca379a3 */ diff --git a/tests-clar/stash/stash_helpers.h b/tests-clar/stash/stash_helpers.h index bb7fec4f5..7c3e13de3 100644 --- a/tests-clar/stash/stash_helpers.h +++ b/tests-clar/stash/stash_helpers.h @@ -1,8 +1,3 @@ void setup_stash( git_repository *repo, git_signature *signature); - -void commit_staged_files( - git_oid *commit_oid, - git_index *index, - git_signature *signature);
\ No newline at end of file |