2020-09-12 22:43:35 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-12 22:43:35 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/LexicalPath.h>
|
|
|
|
#include <AK/Optional.h>
|
|
|
|
#include <AK/RefCounted.h>
|
|
|
|
#include <AK/RefPtr.h>
|
|
|
|
#include <AK/String.h>
|
|
|
|
#include <AK/Vector.h>
|
|
|
|
|
|
|
|
namespace HackStudio {
|
|
|
|
|
|
|
|
class GitRepo final : public RefCounted<GitRepo> {
|
|
|
|
public:
|
|
|
|
struct CreateResult {
|
|
|
|
enum class Type {
|
|
|
|
Success,
|
|
|
|
NoGitRepo,
|
|
|
|
GitProgramNotFound,
|
|
|
|
};
|
|
|
|
Type type;
|
|
|
|
RefPtr<GitRepo> repo;
|
|
|
|
};
|
|
|
|
|
|
|
|
static CreateResult try_to_create(const LexicalPath& repository_root);
|
|
|
|
static RefPtr<GitRepo> initialize_repository(const LexicalPath& repository_root);
|
|
|
|
|
|
|
|
Vector<LexicalPath> unstaged_files() const;
|
|
|
|
Vector<LexicalPath> staged_files() const;
|
|
|
|
bool stage(const LexicalPath& file);
|
|
|
|
bool unstage(const LexicalPath& file);
|
2020-09-14 20:48:00 +03:00
|
|
|
bool commit(const String& message);
|
2020-09-12 20:49:56 +03:00
|
|
|
Optional<String> original_file_content(const LexicalPath& file) const;
|
|
|
|
Optional<String> unstaged_diff(const LexicalPath& file) const;
|
|
|
|
bool is_tracked(const LexicalPath& file) const;
|
2020-09-12 22:43:35 +03:00
|
|
|
|
|
|
|
private:
|
2020-09-14 20:48:00 +03:00
|
|
|
static String command_wrapper(const Vector<String>& command_parts, const LexicalPath& chdir);
|
2020-09-12 22:43:35 +03:00
|
|
|
static bool git_is_installed();
|
|
|
|
static bool git_repo_exists(const LexicalPath& repo_root);
|
|
|
|
static Vector<LexicalPath> parse_files_list(const String&);
|
|
|
|
|
|
|
|
explicit GitRepo(const LexicalPath& repository_root)
|
|
|
|
: m_repository_root(repository_root)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<LexicalPath> modified_files() const;
|
|
|
|
Vector<LexicalPath> untracked_files() const;
|
|
|
|
|
2020-09-14 20:48:00 +03:00
|
|
|
String command(const Vector<String>& command_parts) const;
|
2020-09-12 22:43:35 +03:00
|
|
|
|
|
|
|
LexicalPath m_repository_root;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|