diff options
author | Russell Belfer <rb@github.com> | 2014-05-02 09:42:07 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-05-02 09:42:07 -0700 |
commit | 9862ef8ef8ffd95a74be8082acab9fea0de85edb (patch) | |
tree | ed973ac2992b496b4163c197a5858ab2faf1f9ec /tests | |
parent | 6a1ca96e4193f79c16c6a71dd8b5d576acf22e91 (diff) | |
parent | 217c029b54e8f1574ae6bc71c4b25533ecff3b6a (diff) | |
download | libgit2-9862ef8ef8ffd95a74be8082acab9fea0de85edb.tar.gz |
Merge pull request #2310 from libgit2/cmn/commit-create-safe
commit: safer commit creation with reference update
Diffstat (limited to 'tests')
-rw-r--r-- | tests/commit/commit.c | 4 | ||||
-rw-r--r-- | tests/object/commit/commitstagedfile.c | 9 |
2 files changed, 13 insertions, 0 deletions
diff --git a/tests/commit/commit.c b/tests/commit/commit.c index 38397d2df..fa181b703 100644 --- a/tests/commit/commit.c +++ b/tests/commit/commit.c @@ -38,6 +38,10 @@ void test_commit_commit__create_unexisting_update_ref(void) cl_git_pass(git_commit_create(&oid, _repo, "refs/heads/foo/bar", s, s, NULL, "some msg", tree, 1, (const git_commit **) &commit)); + /* fail because the parent isn't the tip of the branch anymore */ + cl_git_fail(git_commit_create(&oid, _repo, "refs/heads/foo/bar", s, s, + NULL, "some msg", tree, 1, (const git_commit **) &commit)); + cl_git_pass(git_reference_lookup(&ref, _repo, "refs/heads/foo/bar")); cl_assert(!git_oid_cmp(&oid, git_reference_target(ref))); diff --git a/tests/object/commit/commitstagedfile.c b/tests/object/commit/commitstagedfile.c index 3e7b3c02c..9758ea9a2 100644 --- a/tests/object/commit/commitstagedfile.c +++ b/tests/object/commit/commitstagedfile.c @@ -175,6 +175,10 @@ void test_object_commit_commitstagedfile__amend_commit(void) cl_git_pass(git_commit_amend( &new_oid, old_commit, "HEAD", NULL, NULL, NULL, "Initial commit", NULL)); + /* fail because the commit isn't the tip of the branch anymore */ + cl_git_fail(git_commit_amend( + &new_oid, old_commit, "HEAD", NULL, NULL, NULL, "Initial commit", NULL)); + cl_git_pass(git_commit_lookup(&new_commit, repo, &new_oid)); cl_assert_equal_i(0, git_commit_parentcount(new_commit)); @@ -182,6 +186,7 @@ void test_object_commit_commitstagedfile__amend_commit(void) assert_commit_is_head(new_commit); git_commit_free(old_commit); + old_commit = new_commit; /* let's amend the tree of that last commit */ @@ -192,6 +197,10 @@ void test_object_commit_commitstagedfile__amend_commit(void) cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid)); cl_assert_equal_i(2, git_tree_entrycount(tree)); + /* fail to amend on a ref which does not exist */ + cl_git_fail_with(GIT_ENOTFOUND, git_commit_amend( + &new_oid, old_commit, "refs/heads/nope", NULL, NULL, NULL, "Initial commit", tree)); + cl_git_pass(git_commit_amend( &new_oid, old_commit, "HEAD", NULL, NULL, NULL, "Initial commit", tree)); git_tree_free(tree); |