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
3601c4bf
Commit
3601c4bf
authored
Aug 08, 2011
by
nulltoken
Committed by
Vicent Marti
Sep 15, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
repository: Add git_repository_head()
parent
a9daa9bc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
5 deletions
+27
-5
include/git2/repository.h
+10
-0
src/repository.c
+17
-5
No files found.
include/git2/repository.h
View file @
3601c4bf
...
...
@@ -219,6 +219,16 @@ GIT_EXTERN(void) git_repository_free(git_repository *repo);
GIT_EXTERN
(
int
)
git_repository_init
(
git_repository
**
repo_out
,
const
char
*
path
,
unsigned
is_bare
);
/**
* Retrieve and resolve the reference pointed at by HEAD.
*
* @param head_out pointer to the reference which will be retrieved
* @param repo a repository object
*
* @return 0 on success; error code otherwise
*/
GIT_EXTERN
(
int
)
git_repository_head
(
git_reference
**
head_out
,
git_repository
*
repo
);
/**
* Check if a repository's HEAD is detached
*
* A repository's HEAD is detached when it points directly to a commit
...
...
src/repository.c
View file @
3601c4bf
...
...
@@ -729,19 +729,31 @@ int git_repository_head_detached(git_repository *repo)
return
1
;
}
int
git_repository_head
_orphan
(
git_repository
*
repo
)
int
git_repository_head
(
git_reference
**
head_out
,
git_repository
*
repo
)
{
git_reference
*
ref
;
int
error
;
*
head_out
=
NULL
;
error
=
git_reference_lookup
(
&
ref
,
repo
,
GIT_HEAD_FILE
);
if
(
error
<
GIT_SUCCESS
)
return
error
;
if
(
git_reference_type
(
ref
)
==
GIT_REF_OID
)
return
0
;
return
git__rethrow
(
GIT_ENOTAREPO
,
"Failed to locate the HEAD"
);
error
=
git_reference_resolve
(
&
ref
,
ref
);
if
(
error
<
GIT_SUCCESS
)
return
git__rethrow
(
error
,
"Failed to resolve the HEAD"
);
*
head_out
=
ref
;
return
GIT_SUCCESS
;
}
int
git_repository_head_orphan
(
git_repository
*
repo
)
{
git_reference
*
ref
;
int
error
;
error
=
git_repository_head
(
&
ref
,
repo
);
return
error
==
GIT_ENOTFOUND
?
1
:
error
;
}
...
...
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