Last active
August 29, 2015 14:16
-
-
Save macmade/dd676aad77651ccda958 to your computer and use it in GitHub Desktop.
libgit2 - coveralls.io infos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* @author Jean-David Gadina | |
* @copyright (c) 2015, Jean-David Gadina - www.xs-labs.com | |
*/ | |
#include <stdio.h> | |
#include <stdbool.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include "git2.h" | |
int main( void ) | |
{ | |
int err; | |
const git_error * e; | |
git_repository * repos; | |
git_reference * head; | |
git_commit * commit; | |
git_remote * remote; | |
git_strarray remoteNames; | |
const git_oid * oid; | |
const git_signature * author; | |
const git_signature * committer; | |
const char * message; | |
const char * branchName; | |
char sha[ 256 ]; | |
size_t i; | |
repos = NULL; | |
head = NULL; | |
commit = NULL; | |
branchName = NULL; | |
err = git_repository_open( &repos, "/Users/macmade/Desktop/libgit-test/" ); | |
if( err || repos == NULL ) | |
{ | |
goto fail; | |
} | |
err = git_repository_head( &head, repos ); | |
if( err || head == NULL ) | |
{ | |
goto fail; | |
} | |
oid = git_reference_target( head ); | |
err = git_commit_lookup( &commit, repos, oid ); | |
if( err || commit == NULL ) | |
{ | |
goto fail; | |
} | |
memset( sha, 0, sizeof( sha ) ); | |
git_oid_tostr( sha, sizeof( sha ) - 1, oid ); | |
author = git_commit_author( commit ); | |
committer = git_commit_committer( commit ); | |
message = git_commit_message( commit ); | |
printf | |
( | |
"ID: %s\n" | |
"Author: %s\n" | |
"Author email: %s\n" | |
"Author time: %lli\n" | |
"Committer: %s\n" | |
"Committer email: %s\n" | |
"Committer time: %lli\n" | |
"Message: %s\n", | |
sha, | |
author->name, | |
author->email, | |
author->when.time, | |
committer->name, | |
committer->email, | |
committer->when.time, | |
message | |
); | |
if( git_reference_is_branch( head ) ) | |
{ | |
err = git_branch_name( &branchName, head ); | |
if( err || branchName == NULL ) | |
{ | |
goto fail; | |
} | |
printf( "Branch name: %s\n\n", branchName ); | |
} | |
err = git_remote_list( &remoteNames, repos ); | |
if( err ) | |
{ | |
goto fail; | |
} | |
for( i = 0; i < remoteNames.count; i++ ) | |
{ | |
err = git_remote_load( &remote, repos, remoteNames.strings[ i ] ); | |
if( err ) | |
{ | |
goto fail; | |
} | |
printf | |
( | |
"Remote %lu\n" | |
" - Name: %s\n" | |
" - URL: %s\n", | |
( unsigned long )i + 1, | |
git_remote_name( remote ), | |
git_remote_url( remote ) | |
); | |
git_remote_free( remote ); | |
} | |
goto cleanup; | |
fail: | |
e = giterr_last(); | |
if( e != NULL ) | |
{ | |
fprintf( stderr, "Error %d/%d: %s\n", err, e->klass, e->message ); | |
} | |
else | |
{ | |
fprintf( stderr, "Unknown error\n" ); | |
} | |
cleanup: | |
git_strarray_free( &remoteNames ); | |
git_commit_free( commit ); | |
git_reference_free( head ); | |
git_repository_free( repos ); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment