This repository has been archived on 2021-03-22. You can view files and clone it, but cannot push or open issues or pull requests.
backend/src/git.hpp

81 lines
1.9 KiB
C++

/* This file is part of FediBlock-backend.
* Copyright © 2020 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FEDIBLOCK_BACKEND_GIT_HPP
#define FEDIBLOCK_BACKEND_GIT_HPP
#include "types.hpp"
#include <git2.h>
#include <cstdint>
#include <string>
namespace FediBlock::git
{
using std::string;
using std::uint64_t;
/*!
* @brief Initialize libgit and _repo_dir.
*
* @param cache Set _repo_dir to cache dir if true, to temporary dir if false.
*
* @since 0.1.0
*/
void init(bool cache = false);
/*!
* @brief Clean up libgit's global state.
*
* @param cache remove temporary dir if false.
*
* @since 0.1.0
*/
void cleanup(bool cache = false);
// Throw runtime_error on error.
void check(int error);
// Acquire credentials for SSH.
int cred_acquire(git_cred **cred, const char *url,
const char *username_from_url, unsigned int allowed_types,
void *payload);
/*!
* @brief Clone the git repo.
*
* @since 0.1.0
*/
void clone();
// Make a new branch for preparing the pull request.
void create_branch();
// Make a new commit.
void commit(const entry_type &entry);
// Push the new commit.
void push();
// Get the name of the branch we use.
string get_branch_name();
} // namespace FediBlock::git
#endif // FEDIBLOCK_BACKEND_GIT_HPP