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
3b6a5bac
Commit
3b6a5bac
authored
Feb 03, 2014
by
Vicent Marti
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2095 from libgit2/update-head-reflog
Correct "new" id for reattached-HEAD reflog entry
parents
0b4d86af
7f058b86
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
14 deletions
+45
-14
src/refdb_fs.c
+7
-1
tests/repo/head.c
+38
-13
No files found.
src/refdb_fs.c
View file @
3b6a5bac
...
...
@@ -1452,7 +1452,13 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
if
(
error
<
0
)
return
error
;
if
(
git_reference_target
(
ref
)
!=
NULL
)
if
(
git_reference_symbolic_target
(
ref
)
!=
NULL
)
{
error
=
git_reference_name_to_id
(
&
new_id
,
repo
,
git_reference_symbolic_target
(
ref
));
if
(
error
!=
0
&&
error
!=
GIT_ENOTFOUND
)
goto
cleanup
;
giterr_clear
();
}
else
if
(
git_reference_target
(
ref
)
!=
NULL
)
git_oid_cpy
(
&
new_id
,
git_reference_target
(
ref
));
if
((
error
=
serialize_reflog_entry
(
&
buf
,
&
old_id
,
&
new_id
,
who
,
message
))
<
0
)
...
...
tests/repo/head.c
View file @
3b6a5bac
...
...
@@ -195,10 +195,41 @@ void test_repo_head__can_tell_if_an_unborn_head_is_detached(void)
cl_assert_equal_i
(
false
,
git_repository_head_detached
(
repo
));
}
void
test_repo_head__setting_head_updates_reflog
(
void
)
static
void
test_reflog
(
git_repository
*
repo
,
size_t
idx
,
const
char
*
old_spec
,
const
char
*
new_spec
,
const
char
*
email
,
const
char
*
message
)
{
git_reflog
*
log
;
const
git_reflog_entry
*
entry1
,
*
entry2
,
*
entry3
;
git_reflog_entry
*
entry
;
cl_git_pass
(
git_reflog_read
(
&
log
,
repo
,
"HEAD"
));
entry
=
git_reflog_entry_byindex
(
log
,
idx
);
if
(
old_spec
)
{
git_object
*
obj
;
cl_git_pass
(
git_revparse_single
(
&
obj
,
repo
,
old_spec
));
cl_assert_equal_i
(
0
,
git_oid_cmp
(
git_object_id
(
obj
),
git_reflog_entry_id_old
(
entry
)));
git_object_free
(
obj
);
}
if
(
new_spec
)
{
git_object
*
obj
;
cl_git_pass
(
git_revparse_single
(
&
obj
,
repo
,
new_spec
));
cl_assert_equal_i
(
0
,
git_oid_cmp
(
git_object_id
(
obj
),
git_reflog_entry_id_new
(
entry
)));
git_object_free
(
obj
);
}
if
(
email
)
{
cl_assert_equal_s
(
email
,
git_reflog_entry_committer
(
entry
)
->
email
);
}
if
(
message
)
{
cl_assert_equal_s
(
message
,
git_reflog_entry_message
(
entry
));
}
git_reflog_free
(
log
);
}
void
test_repo_head__setting_head_updates_reflog
(
void
)
{
git_object
*
tag
;
git_signature
*
sig
;
...
...
@@ -208,19 +239,13 @@ void test_repo_head__setting_head_updates_reflog(void)
cl_git_pass
(
git_repository_set_head
(
repo
,
"refs/heads/unborn"
,
sig
,
"message2"
));
cl_git_pass
(
git_revparse_single
(
&
tag
,
repo
,
"tags/test"
));
cl_git_pass
(
git_repository_set_head_detached
(
repo
,
git_object_id
(
tag
),
sig
,
"message3"
));
cl_git_pass
(
git_repository_set_head
(
repo
,
"refs/heads/haacked"
,
sig
,
"message4"
));
cl_git_pass
(
git_reflog_read
(
&
log
,
repo
,
"HEAD"
));
entry1
=
git_reflog_entry_byindex
(
log
,
2
);
entry2
=
git_reflog_entry_byindex
(
log
,
1
);
entry3
=
git_reflog_entry_byindex
(
log
,
0
);
cl_assert_equal_s
(
"message1"
,
git_reflog_entry_message
(
entry1
));
cl_assert_equal_s
(
"message2"
,
git_reflog_entry_message
(
entry2
));
cl_assert_equal_s
(
"message3"
,
git_reflog_entry_message
(
entry3
));
cl_assert_equal_s
(
"foo@example.com"
,
git_reflog_entry_committer
(
entry1
)
->
email
);
cl_assert_equal_s
(
"foo@example.com"
,
git_reflog_entry_committer
(
entry2
)
->
email
);
cl_assert_equal_s
(
"foo@example.com"
,
git_reflog_entry_committer
(
entry3
)
->
email
);
test_reflog
(
repo
,
3
,
NULL
,
"refs/heads/haacked"
,
"foo@example.com"
,
"message1"
);
test_reflog
(
repo
,
2
,
"refs/heads/haacked"
,
NULL
,
"foo@example.com"
,
"message2"
);
test_reflog
(
repo
,
1
,
NULL
,
"tags/test^{commit}"
,
"foo@example.com"
,
"message3"
);
test_reflog
(
repo
,
0
,
"tags/test^{commit}"
,
"refs/heads/haacked"
,
"foo@example.com"
,
"message4"
);
git_reflog_free
(
log
);
git_object_free
(
tag
);
git_signature_free
(
sig
);
}
...
...
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