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
cf028856
Commit
cf028856
authored
Oct 19, 2012
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1000 from nulltoken/error/GIT_EORPHANEDHEAD
Add error GIT_EORPHANEDHEAD
parents
4fec465b
8b05bea8
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
127 additions
and
25 deletions
+127
-25
include/git2/checkout.h
+2
-1
include/git2/errors.h
+1
-0
include/git2/repository.h
+4
-2
src/branch.c
+7
-1
src/checkout.c
+11
-5
src/repository.c
+10
-6
tests-clar/checkout/head.c
+24
-0
tests-clar/refs/branches/delete.c
+15
-4
tests-clar/refs/branches/ishead.c
+24
-0
tests-clar/repo/head.c
+29
-5
tests-clar/status/worktree.c
+0
-1
No files found.
include/git2/checkout.h
View file @
cf028856
...
...
@@ -81,7 +81,8 @@ typedef struct git_checkout_opts {
* @param repo repository to check out (must be non-bare)
* @param opts specifies checkout options (may be NULL)
* @param stats structure through which progress information is reported
* @return 0 on success, GIT_ERROR otherwise (use giterr_last for information
* @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing
* branch, GIT_ERROR otherwise (use giterr_last for information
* about the error)
*/
GIT_EXTERN
(
int
)
git_checkout_head
(
...
...
include/git2/errors.h
View file @
cf028856
...
...
@@ -27,6 +27,7 @@ enum {
GIT_EBUFS
=
-
6
,
GIT_EUSER
=
-
7
,
GIT_EBAREREPO
=
-
8
,
GIT_EORPHANEDHEAD
=
-
9
,
GIT_PASSTHROUGH
=
-
30
,
GIT_ITEROVER
=
-
31
,
...
...
include/git2/repository.h
View file @
cf028856
...
...
@@ -272,7 +272,8 @@ GIT_EXTERN(int) git_repository_init_ext(
* @param head_out pointer to the reference which will be retrieved
* @param repo a repository object
*
* @return 0 on success; error code otherwise
* @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing
* branch, an error code otherwise
*/
GIT_EXTERN
(
int
)
git_repository_head
(
git_reference
**
head_out
,
git_repository
*
repo
);
...
...
@@ -562,7 +563,8 @@ GIT_EXTERN(int) git_repository_set_head_detached(
* Otherwise, the HEAD will be detached and point to the peeled Commit.
*
* @param repo Repository pointer
* @return 0 on success, or an error code
* @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing
* branchor an error code
*/
GIT_EXTERN
(
int
)
git_repository_detach_head
(
git_repository
*
repo
);
...
...
src/branch.c
View file @
cf028856
...
...
@@ -265,13 +265,19 @@ int git_branch_is_head(
{
git_reference
*
head
;
bool
is_same
=
false
;
int
error
;
assert
(
branch
);
if
(
!
git_reference_is_branch
(
branch
))
return
false
;
if
(
git_repository_head
(
&
head
,
git_reference_owner
(
branch
))
<
0
)
error
=
git_repository_head
(
&
head
,
git_reference_owner
(
branch
));
if
(
error
==
GIT_EORPHANEDHEAD
)
return
false
;
if
(
error
<
0
)
return
-
1
;
is_same
=
strcmp
(
...
...
src/checkout.c
View file @
cf028856
...
...
@@ -430,17 +430,23 @@ int git_checkout_head(
git_checkout_opts
*
opts
,
git_indexer_stats
*
stats
)
{
git_reference
*
head
;
int
error
;
git_
tree
*
tree
=
NULL
;
git_
object
*
tree
=
NULL
;
assert
(
repo
);
if
(
git_repository_head_tree
(
&
tree
,
repo
)
<
0
)
return
-
1
;
if
((
error
=
git_repository_head
(
&
head
,
repo
))
<
0
)
return
error
;
if
((
error
=
git_reference_peel
(
&
tree
,
head
,
GIT_OBJ_TREE
))
<
0
)
goto
cleanup
;
error
=
git_checkout_tree
(
repo
,
(
git_object
*
)
tree
,
opts
,
stats
);
error
=
git_checkout_tree
(
repo
,
tree
,
opts
,
stats
);
git_tree_free
(
tree
);
cleanup:
git_reference_free
(
head
);
git_object_free
(
tree
);
return
error
;
}
src/repository.c
View file @
cf028856
...
...
@@ -1206,7 +1206,11 @@ int git_repository_head_detached(git_repository *repo)
int
git_repository_head
(
git_reference
**
head_out
,
git_repository
*
repo
)
{
return
git_reference_lookup_resolved
(
head_out
,
repo
,
GIT_HEAD_FILE
,
-
1
);
int
error
;
error
=
git_reference_lookup_resolved
(
head_out
,
repo
,
GIT_HEAD_FILE
,
-
1
);
return
error
==
GIT_ENOTFOUND
?
GIT_EORPHANEDHEAD
:
error
;
}
int
git_repository_head_orphan
(
git_repository
*
repo
)
...
...
@@ -1217,7 +1221,7 @@ int git_repository_head_orphan(git_repository *repo)
error
=
git_repository_head
(
&
ref
,
repo
);
git_reference_free
(
ref
);
if
(
error
==
GIT_E
NOTFOUN
D
)
if
(
error
==
GIT_E
ORPHANEDHEA
D
)
return
1
;
if
(
error
<
0
)
...
...
@@ -1519,14 +1523,14 @@ int git_repository_detach_head(
git_reference
*
old_head
=
NULL
,
*
new_head
=
NULL
;
git_object
*
object
=
NULL
;
int
error
=
-
1
;
int
error
;
assert
(
repo
);
if
(
git_repository_head
(
&
old_head
,
repo
)
<
0
)
return
-
1
;
if
(
(
error
=
git_repository_head
(
&
old_head
,
repo
)
)
<
0
)
return
error
;
if
(
git_object_lookup
(
&
object
,
repo
,
git_reference_oid
(
old_head
),
GIT_OBJ_COMMIT
)
<
0
)
if
(
(
error
=
git_object_lookup
(
&
object
,
repo
,
git_reference_oid
(
old_head
),
GIT_OBJ_COMMIT
)
)
<
0
)
goto
cleanup
;
error
=
git_reference_create_oid
(
&
new_head
,
repo
,
GIT_HEAD_FILE
,
git_reference_oid
(
old_head
),
1
);
...
...
tests-clar/checkout/head.c
0 → 100644
View file @
cf028856
#include "clar_libgit2.h"
#include "refs.h"
static
git_repository
*
g_repo
;
void
test_checkout_head__initialize
(
void
)
{
g_repo
=
cl_git_sandbox_init
(
"testrepo"
);
}
void
test_checkout_head__cleanup
(
void
)
{
cl_git_sandbox_cleanup
();
}
void
test_checkout_head__checking_out_an_orphaned_head_returns_GIT_EORPHANEDHEAD
(
void
)
{
git_reference
*
head
;
cl_git_pass
(
git_reference_create_symbolic
(
&
head
,
g_repo
,
GIT_HEAD_FILE
,
"refs/heads/hide/and/seek"
,
1
));
git_reference_free
(
head
);
cl_assert_equal_i
(
GIT_EORPHANEDHEAD
,
git_checkout_head
(
g_repo
,
NULL
,
NULL
));
}
tests-clar/refs/branches/delete.c
View file @
cf028856
...
...
@@ -38,17 +38,28 @@ void test_refs_branches_delete__can_not_delete_a_branch_pointed_at_by_HEAD(void)
git_reference_free
(
branch
);
}
void
test_refs_branches_delete__can_
not_delete_a_branch
_if_HEAD_is_missing
(
void
)
void
test_refs_branches_delete__can_
delete_a_branch_even
_if_HEAD_is_missing
(
void
)
{
git_reference
*
head
;
git_reference
*
branch
=
NULL
;
git_reference
*
branch
;
cl_git_pass
(
git_reference_lookup
(
&
head
,
repo
,
GIT_HEAD_FILE
));
git_reference_delete
(
head
);
cl_git_pass
(
git_branch_lookup
(
&
branch
,
repo
,
"br2"
,
GIT_BRANCH_LOCAL
));
cl_git_fail
(
git_branch_delete
(
branch
));
git_reference_free
(
branch
);
cl_git_pass
(
git_branch_delete
(
branch
));
}
void
test_refs_branches_delete__can_delete_a_branch_when_HEAD_is_orphaned
(
void
)
{
git_reference
*
head
;
git_reference
*
branch
;
cl_git_pass
(
git_reference_create_symbolic
(
&
head
,
repo
,
GIT_HEAD_FILE
,
"refs/heads/hide/and/seek"
,
1
));
git_reference_free
(
head
);
cl_git_pass
(
git_branch_lookup
(
&
branch
,
repo
,
"br2"
,
GIT_BRANCH_LOCAL
));
cl_git_pass
(
git_branch_delete
(
branch
));
}
void
test_refs_branches_delete__can_delete_a_branch_pointed_at_by_detached_HEAD
(
void
)
...
...
tests-clar/refs/branches/ishead.c
View file @
cf028856
...
...
@@ -22,6 +22,30 @@ void test_refs_branches_ishead__can_tell_if_a_branch_is_pointed_at_by_HEAD(void)
cl_assert_equal_i
(
true
,
git_branch_is_head
(
branch
));
}
static
void
make_head_orphaned
(
void
)
{
git_reference
*
head
;
cl_git_pass
(
git_reference_create_symbolic
(
&
head
,
repo
,
GIT_HEAD_FILE
,
"refs/heads/hide/and/seek"
,
1
));
git_reference_free
(
head
);
}
void
test_refs_branches_ishead__can_properly_handle_orphaned_HEAD
(
void
)
{
git_repository_free
(
repo
);
repo
=
cl_git_sandbox_init
(
"testrepo.git"
);
make_head_orphaned
();
cl_git_pass
(
git_reference_lookup
(
&
branch
,
repo
,
"refs/heads/master"
));
cl_assert_equal_i
(
false
,
git_branch_is_head
(
branch
));
cl_git_sandbox_cleanup
();
repo
=
NULL
;
}
void
test_refs_branches_ishead__can_tell_if_a_branch_is_not_pointed_at_by_HEAD
(
void
)
{
cl_git_pass
(
git_reference_lookup
(
&
branch
,
repo
,
"refs/heads/br2"
));
...
...
tests-clar/repo/head.c
View file @
cf028856
...
...
@@ -33,18 +33,26 @@ void test_repo_head__head_detached(void)
git_reference_free
(
ref
);
}
static
void
make_head_orphaned
(
void
)
{
git_reference
*
head
;
cl_git_pass
(
git_reference_create_symbolic
(
&
head
,
repo
,
GIT_HEAD_FILE
,
"refs/heads/hide/and/seek"
,
1
));
git_reference_free
(
head
);
}
void
test_repo_head__head_orphan
(
void
)
{
git_reference
*
ref
;
cl_assert
(
git_repository_head_orphan
(
repo
)
==
0
);
/* orphan HEAD */
cl_git_pass
(
git_reference_create_symbolic
(
&
ref
,
repo
,
"HEAD"
,
"refs/heads/orphan"
,
1
));
make_head_orphaned
();
cl_assert
(
git_repository_head_orphan
(
repo
)
==
1
);
git_reference_free
(
ref
);
/* take the reop back to it's original state */
/* take the repo back to it's original state */
cl_git_pass
(
git_reference_create_symbolic
(
&
ref
,
repo
,
"HEAD"
,
"refs/heads/master"
,
1
));
cl_assert
(
git_repository_head_orphan
(
repo
)
==
0
);
...
...
@@ -59,7 +67,7 @@ void test_repo_head__set_head_Attaches_HEAD_to_un_unborn_branch_when_the_branch_
cl_assert_equal_i
(
false
,
git_repository_head_detached
(
repo
));
cl_assert_equal_i
(
GIT_E
NOTFOUN
D
,
git_repository_head
(
&
head
,
repo
));
cl_assert_equal_i
(
GIT_E
ORPHANEDHEA
D
,
git_repository_head
(
&
head
,
repo
));
}
void
test_repo_head__set_head_Returns_ENOTFOUND_when_the_reference_doesnt_exist
(
void
)
...
...
@@ -163,3 +171,19 @@ void test_repo_head__detach_head_Fails_if_HEAD_and_point_to_a_non_commitish(void
git_reference_free
(
head
);
}
void
test_repo_head__detaching_an_orphaned_head_returns_GIT_EORPHANEDHEAD
(
void
)
{
make_head_orphaned
();
cl_assert_equal_i
(
GIT_EORPHANEDHEAD
,
git_repository_detach_head
(
repo
));
}
void
test_repo_head__retrieving_an_orphaned_head_returns_GIT_EORPHANEDHEAD
(
void
)
{
git_reference
*
head
;
make_head_orphaned
();
cl_assert_equal_i
(
GIT_EORPHANEDHEAD
,
git_repository_head
(
&
head
,
repo
));
}
tests-clar/status/worktree.c
View file @
cf028856
...
...
@@ -414,7 +414,6 @@ void test_status_worktree__issue_592_ignored_dirs_with_tracked_content(void)
void
test_status_worktree__cannot_retrieve_the_status_of_a_bare_repository
(
void
)
{
git_repository
*
repo
;
int
error
;
unsigned
int
status
=
0
;
cl_git_pass
(
git_repository_open
(
&
repo
,
cl_fixture
(
"testrepo.git"
)));
...
...
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