6 n__git_8h
gullradriel edited this page 2026-10-09 00:55:18 +02:00

include/nilorea/n_git.h

libgit2 wrapper for Git repository operations More...

Structures

Name
struct N_GIT_STATUS_ENTRY
Single file status entry.
struct N_GIT_REPO
Wrapper around a git_repository handle.
struct N_GIT_REMOTE_AUTH
Credentials for remote operations.
struct N_GIT_COMMIT_INFO
Commit metadata.

Detailed Description

libgit2 wrapper for Git repository operations

Author: Castagnier Mickael

Version: 1.0

Date: 26/03/2026

Source code

/*
 * Nilorea Library
 * Copyright (C) 2005-2026 Castagnier Mickael
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 */


#ifndef __N_GIT_H__
#define __N_GIT_H__

#ifdef __cplusplus
extern "C" {
#endif

#ifdef HAVE_LIBGIT2


#include "nilorea/n_str.h"
#include "nilorea/n_list.h"
#include <git2.h>

#define N_GIT_STATUS_NEW 1
#define N_GIT_STATUS_MODIFIED 2
#define N_GIT_STATUS_DELETED 4
#define N_GIT_STATUS_STAGED 8

#define N_GIT_AUTH_NONE 0
#define N_GIT_AUTH_TOKEN 1
#define N_GIT_AUTH_BASIC 2
#define N_GIT_AUTH_SSH 3

typedef struct N_GIT_REMOTE_AUTH {
    int type;
    char* username;
    char* password;
    char* ssh_pubkey_path;
    char* ssh_privkey_path;
    char* ssh_passphrase;
} N_GIT_REMOTE_AUTH;

typedef struct N_GIT_REPO {
    git_repository* repo;
    char* path;
    N_GIT_REMOTE_AUTH* remote_auth;
    char last_status[512];
} N_GIT_REPO;

typedef struct N_GIT_STATUS_ENTRY {
    char path[512];
    int flags;
} N_GIT_STATUS_ENTRY;

typedef struct N_GIT_COMMIT_INFO {
    char hash[42];
    char short_hash[10];
    char message[512];
    char author[256];
    int64_t timestamp;
} N_GIT_COMMIT_INFO;

N_GIT_REPO* n_git_open(const char* path);

N_GIT_REPO* n_git_init(const char* path);

N_GIT_REPO* n_git_init_ex(const char* path, const char* initial_branch);

void n_git_close(N_GIT_REPO** repo);

LIST* n_git_status(N_GIT_REPO* repo);

int n_git_stage(N_GIT_REPO* repo, const char* filepath);

int n_git_stage_all(N_GIT_REPO* repo);

int n_git_unstage(N_GIT_REPO* repo, const char* filepath);

int n_git_commit(N_GIT_REPO* repo, const char* message, const char* author_name, const char* author_email);

LIST* n_git_log(N_GIT_REPO* repo, size_t max_entries);

N_STR* n_git_diff_workdir(N_GIT_REPO* repo);

N_STR* n_git_diff_commits(N_GIT_REPO* repo, const char* hash_a, const char* hash_b);

int n_git_checkout_path(N_GIT_REPO* repo, const char* filepath);

int n_git_checkout_commit(N_GIT_REPO* repo, const char* hash);

LIST* n_git_list_branches(N_GIT_REPO* repo);

int n_git_create_branch(N_GIT_REPO* repo, const char* branch_name);

int n_git_switch_branch(N_GIT_REPO* repo, const char* branch_name);

int n_git_current_branch(N_GIT_REPO* repo, char* out, size_t out_size);

int n_git_delete_branch(N_GIT_REPO* repo, const char* branch_name);

int n_git_set_remote_auth(N_GIT_REPO* repo, const N_GIT_REMOTE_AUTH* auth);

int n_git_remote_set_url(N_GIT_REPO* repo, const char* url);

int n_git_push(N_GIT_REPO* repo);

int n_git_pull(N_GIT_REPO* repo);

int n_git_fetch(N_GIT_REPO* repo);

int n_git_ahead_behind(N_GIT_REPO* repo, size_t* ahead, size_t* behind);


#endif /* HAVE_LIBGIT2 */

#ifdef __cplusplus
}
#endif

#endif /* __N_GIT_H__ */