2020-09-12 22:43:35 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
|
2021-12-31 18:18:08 +00:00
|
|
|
* Copyright (c) 2021, Conor Byrne <conor@cbyrne.dev>
|
2020-09-12 22:43:35 +03:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-12 22:43:35 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
#include <AK/DeprecatedString.h>
|
2020-09-12 22:43:35 +03:00
|
|
|
#include <AK/LexicalPath.h>
|
|
|
|
#include <AK/Optional.h>
|
|
|
|
#include <AK/RefCounted.h>
|
|
|
|
#include <AK/RefPtr.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;
|
|
|
|
};
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
static CreateResult try_to_create(DeprecatedString const& repository_root);
|
|
|
|
static RefPtr<GitRepo> initialize_repository(DeprecatedString const& repository_root);
|
2020-09-12 22:43:35 +03:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
bool stage(DeprecatedString const& file);
|
|
|
|
bool unstage(DeprecatedString const& file);
|
|
|
|
bool commit(DeprecatedString const& message);
|
|
|
|
bool is_tracked(DeprecatedString const& file) const;
|
2021-12-31 18:18:08 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
Vector<DeprecatedString> unstaged_files() const;
|
|
|
|
Vector<DeprecatedString> staged_files() const;
|
|
|
|
Optional<DeprecatedString> original_file_content(DeprecatedString const& file) const;
|
|
|
|
Optional<DeprecatedString> unstaged_diff(DeprecatedString const& file) const;
|
2020-09-12 22:43:35 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
static bool git_is_installed();
|
2022-12-04 18:02:33 +00:00
|
|
|
static bool git_repo_exists(DeprecatedString const& repo_root);
|
2021-12-31 18:18:08 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
static DeprecatedString command_wrapper(Vector<DeprecatedString> const& command_parts, DeprecatedString const& chdir);
|
|
|
|
static Vector<DeprecatedString> parse_files_list(DeprecatedString const&);
|
2020-09-12 22:43:35 +03:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
explicit GitRepo(DeprecatedString const& repository_root)
|
2020-09-12 22:43:35 +03:00
|
|
|
: m_repository_root(repository_root)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
Vector<DeprecatedString> modified_files() const;
|
|
|
|
Vector<DeprecatedString> untracked_files() const;
|
2020-09-12 22:43:35 +03:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString command(Vector<DeprecatedString> const& command_parts) const;
|
2020-09-12 22:43:35 +03:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString m_repository_root;
|
2020-09-12 22:43:35 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|