Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
17a93afa
Commit
17a93afa
authored
May 06, 2016
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3757 from johnhaley81/jh/fix-create-initial-commit
Fix `git_commit_create` for an initial commit
parents
2e43a37b
5785ae9b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
1 deletions
+61
-1
src/commit.c
+1
-1
tests/commit/commit.c
+60
-0
No files found.
src/commit.c
View file @
17a93afa
...
@@ -104,7 +104,7 @@ static int validate_tree_and_parents(git_array_oid_t *parents, git_repository *r
...
@@ -104,7 +104,7 @@ static int validate_tree_and_parents(git_array_oid_t *parents, git_repository *r
i
++
;
i
++
;
}
}
if
(
current_id
&&
git_oid_cmp
(
current_id
,
git_array_get
(
*
parents
,
0
)))
{
if
(
current_id
&&
(
parents
->
size
==
0
||
git_oid_cmp
(
current_id
,
git_array_get
(
*
parents
,
0
)
)))
{
giterr_set
(
GITERR_OBJECT
,
"failed to create commit: current tip is not the first parent"
);
giterr_set
(
GITERR_OBJECT
,
"failed to create commit: current tip is not the first parent"
);
error
=
GIT_EMODIFIED
;
error
=
GIT_EMODIFIED
;
goto
on_error
;
goto
on_error
;
...
...
tests/commit/commit.c
View file @
17a93afa
...
@@ -51,6 +51,66 @@ void test_commit_commit__create_unexisting_update_ref(void)
...
@@ -51,6 +51,66 @@ void test_commit_commit__create_unexisting_update_ref(void)
git_reference_free
(
ref
);
git_reference_free
(
ref
);
}
}
void
test_commit_commit__create_initial_commit
(
void
)
{
git_oid
oid
;
git_tree
*
tree
;
git_commit
*
commit
;
git_signature
*
s
;
git_reference
*
ref
;
git_oid_fromstr
(
&
oid
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
);
cl_git_pass
(
git_commit_lookup
(
&
commit
,
_repo
,
&
oid
));
git_oid_fromstr
(
&
oid
,
"944c0f6e4dfa41595e6eb3ceecdb14f50fe18162"
);
cl_git_pass
(
git_tree_lookup
(
&
tree
,
_repo
,
&
oid
));
cl_git_pass
(
git_signature_now
(
&
s
,
"alice"
,
"alice@example.com"
));
cl_git_fail
(
git_reference_lookup
(
&
ref
,
_repo
,
"refs/heads/foo/bar"
));
cl_git_pass
(
git_commit_create
(
&
oid
,
_repo
,
"refs/heads/foo/bar"
,
s
,
s
,
NULL
,
"initial commit"
,
tree
,
0
,
NULL
));
cl_git_pass
(
git_reference_lookup
(
&
ref
,
_repo
,
"refs/heads/foo/bar"
));
cl_assert_equal_oid
(
&
oid
,
git_reference_target
(
ref
));
git_tree_free
(
tree
);
git_commit_free
(
commit
);
git_signature_free
(
s
);
git_reference_free
(
ref
);
}
void
test_commit_commit__create_initial_commit_parent_not_current
(
void
)
{
git_oid
oid
;
git_oid
original_oid
;
git_tree
*
tree
;
git_commit
*
commit
;
git_signature
*
s
;
git_oid_fromstr
(
&
oid
,
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750"
);
cl_git_pass
(
git_commit_lookup
(
&
commit
,
_repo
,
&
oid
));
git_oid_fromstr
(
&
oid
,
"944c0f6e4dfa41595e6eb3ceecdb14f50fe18162"
);
cl_git_pass
(
git_tree_lookup
(
&
tree
,
_repo
,
&
oid
));
cl_git_pass
(
git_signature_now
(
&
s
,
"alice"
,
"alice@example.com"
));
cl_git_pass
(
git_reference_name_to_id
(
&
original_oid
,
_repo
,
"HEAD"
));
cl_git_fail
(
git_commit_create
(
&
oid
,
_repo
,
"HEAD"
,
s
,
s
,
NULL
,
"initial commit"
,
tree
,
0
,
NULL
));
cl_git_pass
(
git_reference_name_to_id
(
&
oid
,
_repo
,
"HEAD"
));
cl_assert_equal_oid
(
&
oid
,
&
original_oid
);
git_tree_free
(
tree
);
git_commit_free
(
commit
);
git_signature_free
(
s
);
}
void
assert_commit_summary
(
const
char
*
expected
,
const
char
*
given
)
void
assert_commit_summary
(
const
char
*
expected
,
const
char
*
given
)
{
{
git_commit
*
dummy
;
git_commit
*
dummy
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment