/* * Copyright (c) 2020, Itamar S. * Copyright (c) 2021, Conor Byrne * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include namespace HackStudio { class GitRepo final : public RefCounted { public: struct CreateResult { enum class Type { Success, NoGitRepo, GitProgramNotFound, }; Type type; RefPtr repo; }; static CreateResult try_to_create(DeprecatedString const& repository_root); static RefPtr initialize_repository(DeprecatedString const& repository_root); bool stage(DeprecatedString const& file); bool unstage(DeprecatedString const& file); bool commit(DeprecatedString const& message); bool is_tracked(DeprecatedString const& file) const; Vector unstaged_files() const; Vector staged_files() const; Optional original_file_content(DeprecatedString const& file) const; Optional unstaged_diff(DeprecatedString const& file) const; private: static bool git_is_installed(); static bool git_repo_exists(DeprecatedString const& repo_root); static DeprecatedString command_wrapper(Vector const& command_parts, DeprecatedString const& chdir); static Vector parse_files_list(DeprecatedString const&); explicit GitRepo(DeprecatedString const& repository_root) : m_repository_root(repository_root) { } Vector modified_files() const; Vector untracked_files() const; DeprecatedString command(Vector const& command_parts) const; DeprecatedString m_repository_root; }; }