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
010cec3a
Commit
010cec3a
authored
Feb 04, 2014
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add reflog params to git_repository_detach_head
parent
c3ab1e5a
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
44 additions
and
16 deletions
+44
-16
include/git2/repository.h
+5
-1
src/repository.c
+5
-2
tests/refs/branches/delete.c
+1
-1
tests/repo/head.c
+28
-7
tests/repo/headtree.c
+1
-1
tests/repo/state.c
+1
-1
tests/reset/soft.c
+2
-2
tests/stash/save.c
+1
-1
No files found.
include/git2/repository.h
View file @
010cec3a
...
...
@@ -615,11 +615,15 @@ GIT_EXTERN(int) git_repository_set_head_detached(
* Otherwise, the HEAD will be detached and point to the peeled Commit.
*
* @param repo Repository pointer
* @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EUNBORNBRANCH when HEAD points to a non existing
* branch or an error code
*/
GIT_EXTERN
(
int
)
git_repository_detach_head
(
git_repository
*
repo
);
git_repository
*
repo
,
const
git_signature
*
signature
,
const
char
*
reflog_message
);
typedef
enum
{
GIT_REPOSITORY_STATE_NONE
,
...
...
src/repository.c
View file @
010cec3a
...
...
@@ -1891,7 +1891,9 @@ cleanup:
}
int
git_repository_detach_head
(
git_repository
*
repo
)
git_repository
*
repo
,
const
git_signature
*
signature
,
const
char
*
reflog_message
)
{
git_reference
*
old_head
=
NULL
,
*
new_head
=
NULL
;
...
...
@@ -1906,7 +1908,8 @@ int git_repository_detach_head(
if
((
error
=
git_object_lookup
(
&
object
,
repo
,
git_reference_target
(
old_head
),
GIT_OBJ_COMMIT
))
<
0
)
goto
cleanup
;
error
=
git_reference_create
(
&
new_head
,
repo
,
GIT_HEAD_FILE
,
git_reference_target
(
old_head
),
1
,
NULL
,
NULL
);
error
=
git_reference_create
(
&
new_head
,
repo
,
GIT_HEAD_FILE
,
git_reference_target
(
old_head
),
1
,
signature
,
reflog_message
);
cleanup:
git_object_free
(
object
);
...
...
tests/refs/branches/delete.c
View file @
010cec3a
...
...
@@ -78,7 +78,7 @@ void test_refs_branches_delete__can_delete_a_branch_pointed_at_by_detached_HEAD(
git_reference_free
(
head
);
/* Detach HEAD and make it target the commit that "master" points to */
git_repository_detach_head
(
repo
);
git_repository_detach_head
(
repo
,
NULL
,
NULL
);
cl_git_pass
(
git_branch_lookup
(
&
branch
,
repo
,
"master"
,
GIT_BRANCH_LOCAL
));
cl_git_pass
(
git_branch_delete
(
branch
));
...
...
tests/repo/head.c
View file @
010cec3a
...
...
@@ -15,21 +15,42 @@ void test_repo_head__cleanup(void)
cl_git_sandbox_cleanup
();
}
static
void
check_last_reflog_entry
(
const
char
*
email
,
const
char
*
message
)
{
git_reflog
*
log
;
const
git_reflog_entry
*
entry
;
cl_git_pass
(
git_reflog_read
(
&
log
,
repo
,
GIT_HEAD_FILE
));
cl_assert
(
git_reflog_entrycount
(
log
)
>
0
);
entry
=
git_reflog_entry_byindex
(
log
,
0
);
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__head_detached
(
void
)
{
git_reference
*
ref
;
git_signature
*
sig
;
cl_git_pass
(
git_
repository_head_detached
(
repo
));
cl_git_pass
(
git_
signature_now
(
&
sig
,
"Foo Bar"
,
"foo@example.com"
));
cl_
git_pass
(
git_repository_detach_hea
d
(
repo
));
cl_
assert_equal_i
(
false
,
git_repository_head_detache
d
(
repo
));
cl_git_pass
(
git_repository_detach_head
(
repo
,
sig
,
"CABLE DETACHED"
));
check_last_reflog_entry
(
sig
->
email
,
"CABLE DETACHED"
);
cl_assert_equal_i
(
true
,
git_repository_head_detached
(
repo
));
/* take the reop back to it's original state */
cl_git_pass
(
git_reference_symbolic_create
(
&
ref
,
repo
,
"HEAD"
,
"refs/heads/master"
,
1
,
NULL
,
NULL
));
/* take the repo back to it's original state */
cl_git_pass
(
git_reference_symbolic_create
(
&
ref
,
repo
,
"HEAD"
,
"refs/heads/master"
,
true
,
sig
,
"REATTACH"
));
git_reference_free
(
ref
);
check_last_reflog_entry
(
sig
->
email
,
"REATTACH"
);
cl_assert_equal_i
(
false
,
git_repository_head_detached
(
repo
));
git_signature_free
(
sig
);
}
void
test_repo_head__unborn_head
(
void
)
...
...
@@ -147,7 +168,7 @@ void test_repo_head__detach_head_Detaches_HEAD_and_make_it_point_to_the_peeled_c
{
cl_assert_equal_i
(
false
,
git_repository_head_detached
(
repo
));
cl_git_pass
(
git_repository_detach_head
(
repo
));
cl_git_pass
(
git_repository_detach_head
(
repo
,
NULL
,
NULL
));
assert_head_is_correctly_detached
();
}
...
...
@@ -158,7 +179,7 @@ void test_repo_head__detach_head_Fails_if_HEAD_and_point_to_a_non_commitish(void
cl_git_pass
(
git_reference_symbolic_create
(
&
head
,
repo
,
GIT_HEAD_FILE
,
"refs/tags/point_to_blob"
,
1
,
NULL
,
NULL
));
cl_git_fail
(
git_repository_detach_head
(
repo
));
cl_git_fail
(
git_repository_detach_head
(
repo
,
NULL
,
NULL
));
git_reference_free
(
head
);
}
...
...
@@ -167,7 +188,7 @@ void test_repo_head__detaching_an_unborn_branch_returns_GIT_EUNBORNBRANCH(void)
{
make_head_unborn
(
repo
,
NON_EXISTING_HEAD
);
cl_assert_equal_i
(
GIT_EUNBORNBRANCH
,
git_repository_detach_head
(
repo
));
cl_assert_equal_i
(
GIT_EUNBORNBRANCH
,
git_repository_detach_head
(
repo
,
NULL
,
NULL
));
}
void
test_repo_head__retrieving_an_unborn_branch_returns_GIT_EUNBORNBRANCH
(
void
)
...
...
tests/repo/headtree.c
View file @
010cec3a
...
...
@@ -20,7 +20,7 @@ void test_repo_headtree__cleanup(void)
void
test_repo_headtree__can_retrieve_the_root_tree_from_a_detached_head
(
void
)
{
cl_git_pass
(
git_repository_detach_head
(
repo
));
cl_git_pass
(
git_repository_detach_head
(
repo
,
NULL
,
NULL
));
cl_git_pass
(
git_repository_head_tree
(
&
tree
,
repo
));
...
...
tests/repo/state.c
View file @
010cec3a
...
...
@@ -37,7 +37,7 @@ void test_repo_state__none_with_HEAD_attached(void)
void
test_repo_state__none_with_HEAD_detached
(
void
)
{
cl_git_pass
(
git_repository_detach_head
(
_repo
));
cl_git_pass
(
git_repository_detach_head
(
_repo
,
NULL
,
NULL
));
assert_repo_state
(
GIT_REPOSITORY_STATE_NONE
);
}
...
...
tests/reset/soft.c
View file @
010cec3a
...
...
@@ -45,7 +45,7 @@ void test_reset_soft__can_reset_the_non_detached_Head_to_the_specified_commit(vo
void
test_reset_soft__can_reset_the_detached_Head_to_the_specified_commit
(
void
)
{
git_repository_detach_head
(
repo
);
git_repository_detach_head
(
repo
,
NULL
,
NULL
);
assert_reset_soft
(
true
);
}
...
...
@@ -118,7 +118,7 @@ void test_reset_soft__fails_when_merging(void)
{
git_buf
merge_head_path
=
GIT_BUF_INIT
;
cl_git_pass
(
git_repository_detach_head
(
repo
));
cl_git_pass
(
git_repository_detach_head
(
repo
,
NULL
,
NULL
));
cl_git_pass
(
git_buf_joinpath
(
&
merge_head_path
,
git_repository_path
(
repo
),
"MERGE_HEAD"
));
cl_git_mkfile
(
git_buf_cstr
(
&
merge_head_path
),
"beefbeefbeefbeefbeefbeefbeefbeefbeefbeef
\n
"
);
...
...
tests/stash/save.c
View file @
010cec3a
...
...
@@ -196,7 +196,7 @@ void test_stash_save__cannot_stash_against_a_bare_repository(void)
void
test_stash_save__can_stash_against_a_detached_head
(
void
)
{
git_repository_detach_head
(
repo
);
git_repository_detach_head
(
repo
,
NULL
,
NULL
);
cl_git_pass
(
git_stash_save
(
&
stash_tip_oid
,
repo
,
signature
,
NULL
,
GIT_STASH_DEFAULT
));
...
...
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