Skip to content

feat: add status subcommand #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
refactoring
  • Loading branch information
SandrineP committed Jun 13, 2025
commit a7b747db787fe7facbb410a7bfc8edd31cd9f3f5
6 changes: 4 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
#include <git2.h> // For version number only
#include <iostream>

#include "git_exception.hpp"
#include "src/utils/git_exception.hpp"
#include "version.hpp"
#include "subcommand/init_subcommand.hpp"
// #include "subcommand/status_subcommand.hpp"

int main(int argc, char** argv)
{
int exitCode = 0;
try
{
const libgit2_object lg2_obj;
CLI::App app{"Git using C++ wrapper of libgit2"};

// Top-level command options.
auto version = app.add_flag("-v,--version", "Show version");

// Sub commands
InitSubcommand init(app);
InitSubcommand init(lg2_obj, app);

app.parse(argc, argv);

Expand Down
4 changes: 2 additions & 2 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
subdir('subcommand')
subdir('utils')
subdir('wrapper')

src_files = files([
'git_exception.cpp',
'main.cpp'
]) + subcommand_files + wrapper_files
]) + subcommand_files + utils_files + wrapper_files
16 changes: 0 additions & 16 deletions src/subcommand/base_subcommand.hpp

This file was deleted.

6 changes: 2 additions & 4 deletions src/subcommand/init_subcommand.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <filesystem>
#include "init_subcommand.hpp"
#include "../wrapper/repository_wrapper.hpp"

InitSubcommand::InitSubcommand(CLI::App& app)
InitSubcommand::InitSubcommand(const libgit2_object&, CLI::App& app)
{
auto *sub = app.add_subcommand("init", "Explanation of init here");

Expand All @@ -18,6 +17,5 @@ InitSubcommand::InitSubcommand(CLI::App& app)

void InitSubcommand::run()
{
RepositoryWrapper repo;
repo.init(directory, bare);
RepositoryWrapper::init(directory, bare);
}
9 changes: 6 additions & 3 deletions src/subcommand/init_subcommand.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#pragma once

#include <CLI/CLI.hpp>
#include <string>
#include "base_subcommand.hpp"

class InitSubcommand : public BaseSubcommand
#include "src/wrapper/repository_wrapper.hpp"

class InitSubcommand
{
public:
InitSubcommand(CLI::App& app);

explicit InitSubcommand(const libgit2_object&, CLI::App& app);
void run();

private:
Expand Down
13 changes: 13 additions & 0 deletions src/utils/common.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <git2.h>

#include "common.hpp"

libgit2_object::libgit2_object()
{
git_libgit2_init();
}

libgit2_object::~libgit2_object()
{
git_libgit2_shutdown();
}
20 changes: 20 additions & 0 deletions src/utils/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class noncopiable_nonmovable
{
public:
noncopiable_nonmovable(const noncopiable_nonmovable&) = delete;
noncopiable_nonmovable& operator=(const noncopiable_nonmovable&) = delete;
noncopiable_nonmovable(noncopiable_nonmovable&) = delete;
noncopiable_nonmovable& operator=(noncopiable_nonmovable&&) = delete;

protected:
noncopiable_nonmovable() = default;
~noncopiable_nonmovable() = default;
};

class libgit2_object : private noncopiable_nonmovable
{
public:

libgit2_object();
~libgit2_object();
};
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions src/utils/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
utils_files = files([
'common.cpp',
'git_exception.cpp',
])
15 changes: 0 additions & 15 deletions src/wrapper/base_wrapper.cpp

This file was deleted.

16 changes: 0 additions & 16 deletions src/wrapper/base_wrapper.hpp

This file was deleted.

1 change: 0 additions & 1 deletion src/wrapper/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
wrapper_files = files([
'base_wrapper.cpp',
'repository_wrapper.cpp',
])
22 changes: 12 additions & 10 deletions src/wrapper/repository_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
#include <iostream>
#include <string>

#include "../git_exception.hpp"
#include "src/utils/git_exception.hpp"
#include "repository_wrapper.hpp"


RepositoryWrapper::RepositoryWrapper()
: _repo(nullptr)
: p_repo(nullptr)
{}

RepositoryWrapper::~RepositoryWrapper()
{
if (_repo != nullptr) {
git_repository_free(_repo); // no return
}
git_repository_free(p_repo);
p_repo=nullptr;
}

// RepositoryWrapper::RepositoryWrapper open(const std::string path)
// {
//
// };

void RepositoryWrapper::init(const std::string& directory, bool bare)
{
// what if it is already initialised? Throw exception or delete and recreate?
throwIfError(git_repository_init(&_repo, directory.c_str(), bare));
RepositoryWrapper rw;
throwIfError(git_repository_init(&(rw.p_repo), directory.c_str(), bare));
}
17 changes: 11 additions & 6 deletions src/wrapper/repository_wrapper.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
#pragma once

#include "base_wrapper.hpp"
#include <git2.h>
#include <string>

class RepositoryWrapper : public BaseWrapper
#include "../utils/common.hpp"

class RepositoryWrapper : private noncopiable_nonmovable
{
public:
RepositoryWrapper();

virtual ~RepositoryWrapper();
~RepositoryWrapper();

void init(const std::string& directory, bool bare);
// static RepositoryWrapper open(const std::string path);
static void init(const std::string& directory, bool bare);

private:
git_repository *_repo;

RepositoryWrapper();
git_repository* p_repo;
};