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
b1a3a70e
Commit
b1a3a70e
authored
Nov 12, 2012
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
repository: Refine repository_head() error report
parent
ef887151
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
51 additions
and
3 deletions
+51
-3
include/git2/repository.h
+1
-1
src/branch.c
+1
-1
src/repository.c
+11
-1
tests-clar/refs/branches/ishead.c
+16
-0
tests-clar/repo/head.c
+10
-0
tests-clar/repo/repo_helpers.c
+11
-0
tests-clar/repo/repo_helpers.h
+1
-0
No files found.
include/git2/repository.h
View file @
b1a3a70e
...
...
@@ -273,7 +273,7 @@ GIT_EXTERN(int) git_repository_init_ext(
* @param repo a repository object
*
* @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing
* branch, an error code otherwise
* branch,
GIT_ENOTFOUND when HEAD is missing;
an error code otherwise
*/
GIT_EXTERN
(
int
)
git_repository_head
(
git_reference
**
head_out
,
git_repository
*
repo
);
...
...
src/branch.c
View file @
b1a3a70e
...
...
@@ -317,7 +317,7 @@ int git_branch_is_head(
error
=
git_repository_head
(
&
head
,
git_reference_owner
(
branch
));
if
(
error
==
GIT_EORPHANEDHEAD
)
if
(
error
==
GIT_EORPHANEDHEAD
||
error
==
GIT_ENOTFOUND
)
return
false
;
if
(
error
<
0
)
...
...
src/repository.c
View file @
b1a3a70e
...
...
@@ -1207,9 +1207,19 @@ int git_repository_head_detached(git_repository *repo)
int
git_repository_head
(
git_reference
**
head_out
,
git_repository
*
repo
)
{
git_reference
*
head
;
int
error
;
error
=
git_reference_lookup_resolved
(
head_out
,
repo
,
GIT_HEAD_FILE
,
-
1
);
if
((
error
=
git_reference_lookup
(
&
head
,
repo
,
GIT_HEAD_FILE
))
<
0
)
return
error
;
if
(
git_reference_type
(
head
)
==
GIT_REF_OID
)
{
*
head_out
=
head
;
return
0
;
}
error
=
git_reference_lookup_resolved
(
head_out
,
repo
,
git_reference_target
(
head
),
-
1
);
git_reference_free
(
head
);
return
error
==
GIT_ENOTFOUND
?
GIT_EORPHANEDHEAD
:
error
;
}
...
...
tests-clar/refs/branches/ishead.c
View file @
b1a3a70e
...
...
@@ -39,6 +39,22 @@ void test_refs_branches_ishead__can_properly_handle_orphaned_HEAD(void)
repo
=
NULL
;
}
void
test_refs_branches_ishead__can_properly_handle_missing_HEAD
(
void
)
{
git_repository_free
(
repo
);
repo
=
cl_git_sandbox_init
(
"testrepo.git"
);
delete_head
(
repo
);
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 @
b1a3a70e
#include "clar_libgit2.h"
#include "refs.h"
#include "repo_helpers.h"
#include "posix.h"
git_repository
*
repo
;
...
...
@@ -178,6 +179,15 @@ void test_repo_head__retrieving_an_orphaned_head_returns_GIT_EORPHANEDHEAD(void)
cl_assert_equal_i
(
GIT_EORPHANEDHEAD
,
git_repository_head
(
&
head
,
repo
));
}
void
test_repo_head__retrieving_a_missing_head_returns_GIT_ENOTFOUND
(
void
)
{
git_reference
*
head
;
delete_head
(
repo
);
cl_assert_equal_i
(
GIT_ENOTFOUND
,
git_repository_head
(
&
head
,
repo
));
}
void
test_repo_head__can_tell_if_an_orphaned_head_is_detached
(
void
)
{
make_head_orphaned
(
repo
,
NON_EXISTING_HEAD
);
...
...
tests-clar/repo/repo_helpers.c
View file @
b1a3a70e
#include "clar_libgit2.h"
#include "refs.h"
#include "repo_helpers.h"
#include "posix.h"
void
make_head_orphaned
(
git_repository
*
repo
,
const
char
*
target
)
{
...
...
@@ -9,3 +10,13 @@ void make_head_orphaned(git_repository* repo, const char *target)
cl_git_pass
(
git_reference_create_symbolic
(
&
head
,
repo
,
GIT_HEAD_FILE
,
target
,
1
));
git_reference_free
(
head
);
}
void
delete_head
(
git_repository
*
repo
)
{
git_buf
head_path
=
GIT_BUF_INIT
;
cl_git_pass
(
git_buf_joinpath
(
&
head_path
,
git_repository_path
(
repo
),
GIT_HEAD_FILE
));
cl_git_pass
(
p_unlink
(
git_buf_cstr
(
&
head_path
)));
git_buf_free
(
&
head_path
);
}
tests-clar/repo/repo_helpers.h
View file @
b1a3a70e
...
...
@@ -3,3 +3,4 @@
#define NON_EXISTING_HEAD "refs/heads/hide/and/seek"
extern
void
make_head_orphaned
(
git_repository
*
repo
,
const
char
*
target
);
extern
void
delete_head
(
git_repository
*
repo
);
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