From abf8bb94ccef99c15f44ebf762ef9709410a8e46 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 23 Nov 2020 21:28:26 -0500 Subject: [PATCH] split git.h --- src/main.cpp | 2 +- src/tools/git.h | 131 +++++++++++++++++++++++++++++++++++++++++ src/tools/tools.h | 128 ++-------------------------------------- vs/mob.vcxproj | 1 + vs/mob.vcxproj.filters | 3 + 5 files changed, 140 insertions(+), 125 deletions(-) create mode 100644 src/tools/git.h diff --git a/src/main.cpp b/src/main.cpp index a848325..501609c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -175,7 +175,7 @@ std::shared_ptr handle_command_line(const std::vector& arg all_groups.push_back(c->group()); - // vs reports a no-op on the left side of the comman, which is incorrect + // vs reports a no-op on the left side of the command, which is incorrect #pragma warning(suppress: 4548) auto cli = (all_groups, command::common_options_group()); auto pr = clipp::parse(args, cli); diff --git a/src/tools/git.h b/src/tools/git.h new file mode 100644 index 0000000..f590804 --- /dev/null +++ b/src/tools/git.h @@ -0,0 +1,131 @@ +#pragma once + +namespace mob +{ + +class git : public basic_process_runner +{ +public: + enum ops + { + clone = 1, + pull, + clone_or_pull, + add_submodule + }; + + struct creds + { + std::string username; + std::string email; + }; + + + git(ops o); + + static void delete_directory(const context& cx, const fs::path& p); + + static fs::path binary(); + + static void set_credentials( + const fs::path& repo, + const std::string& username, const std::string& email); + + static void set_remote( + const fs::path& repo, + std::string org, std::string key, + bool no_push_upstream, bool push_default_origin); + + static void ignore_ts(const fs::path& repo, bool b); + + static bool has_remote(const fs::path& repo, const std::string& name); + + static void add_remote( + const fs::path& repo, const std::string& remote_name, + const std::string& org, const std::string& key, + bool push_default, const std::string& url_pattern={}); + + static bool is_git_repo(const fs::path& p); + static bool branch_exists(const mob::url& u, const std::string& name); + static void init_repo(const fs::path& p); + + static void apply(const fs::path& p, const std::string& diff); + static void fetch( + const fs::path& p, + const std::string& remote, const std::string& branch); + static void checkout(const fs::path& p, const std::string& what); + + static std::string current_branch(const fs::path& p); + + + git& url(const mob::url& u); + git& branch(const std::string& name); + git& root(const fs::path& dir); + const fs::path& root() const; + git& credentials(const std::string& username, const std::string& email); + git& submodule_name(const std::string& name); + const std::string& submodule_name() const; + git& ignore_ts_on_clone(bool b); + git& revert_ts_on_pull(bool b); + git& shallow(bool b); + bool is_tracked(const fs::path& relative_file); + + git& remote( + std::string org, std::string key, + bool no_push_upstream, bool push_default_origin); + +protected: + void do_run() override; + +private: + ops op_; + mob::url url_; + std::string branch_; + fs::path root_; + std::string submodule_; + std::string creds_username_; + std::string creds_email_; + std::string remote_org_; + std::string remote_key_; + bool no_push_upstream_ = false; + bool push_default_origin_ = false; + bool ignore_ts_ = false; + bool revert_ts_ = false; + bool shallow_ = false; + + process make_process(); + + void do_clone_or_pull(); + bool do_clone(); + void do_pull(); + void do_add_submodule(); + + void do_set_credentials(); + void do_set_remote(); + void do_ignore_ts(); + void do_revert_ts(); + + void set_config(const std::string& key, const std::string& value); + bool has_remote(const std::string& name); + void rename_remote(const std::string& from, const std::string& to); + void add_remote(const std::string& name, const std::string& url); + void set_remote_push(const std::string& remote, const std::string& url); + void set_assume_unchanged(const fs::path& relative_file, bool on); + void apply(const std::string& diff); + void fetch(const std::string& remote, const std::string& branch); + void checkout(const std::string& what); + std::string current_branch(); + bool is_repo(); + bool branch_exists(); + bool has_uncommitted_changes(); + bool has_stashed_changes(); + void init(); + + std::string git_file(); + + static std::string make_url( + const std::string& org, const std::string& git_file, + const std::string& url_pattern={}); +}; + +} // namespace diff --git a/src/tools/tools.h b/src/tools/tools.h index 34eedc3..1624a96 100644 --- a/src/tools/tools.h +++ b/src/tools/tools.h @@ -9,6 +9,7 @@ namespace mob { class process; +class git; class tool { @@ -151,130 +152,6 @@ private: }; -class git : public basic_process_runner -{ -public: - enum ops - { - clone = 1, - pull, - clone_or_pull, - add_submodule - }; - - struct creds - { - std::string username; - std::string email; - }; - - - git(ops o); - - static void delete_directory(const context& cx, const fs::path& p); - - static fs::path binary(); - - static void set_credentials( - const fs::path& repo, - const std::string& username, const std::string& email); - - static void set_remote( - const fs::path& repo, - std::string org, std::string key, - bool no_push_upstream, bool push_default_origin); - - static void ignore_ts(const fs::path& repo, bool b); - - static bool has_remote(const fs::path& repo, const std::string& name); - - static void add_remote( - const fs::path& repo, const std::string& remote_name, - const std::string& org, const std::string& key, - bool push_default, const std::string& url_pattern={}); - - static bool is_git_repo(const fs::path& p); - static bool branch_exists(const mob::url& u, const std::string& name); - static void init_repo(const fs::path& p); - - static void apply(const fs::path& p, const std::string& diff); - static void fetch( - const fs::path& p, - const std::string& remote, const std::string& branch); - static void checkout(const fs::path& p, const std::string& what); - - static std::string current_branch(const fs::path& p); - - - git& url(const mob::url& u); - git& branch(const std::string& name); - git& root(const fs::path& dir); - const fs::path& root() const; - git& credentials(const std::string& username, const std::string& email); - git& submodule_name(const std::string& name); - const std::string& submodule_name() const; - git& ignore_ts_on_clone(bool b); - git& revert_ts_on_pull(bool b); - git& shallow(bool b); - bool is_tracked(const fs::path& relative_file); - - git& remote( - std::string org, std::string key, - bool no_push_upstream, bool push_default_origin); - -protected: - void do_run() override; - -private: - ops op_; - mob::url url_; - std::string branch_; - fs::path root_; - std::string submodule_; - std::string creds_username_; - std::string creds_email_; - std::string remote_org_; - std::string remote_key_; - bool no_push_upstream_ = false; - bool push_default_origin_ = false; - bool ignore_ts_ = false; - bool revert_ts_ = false; - bool shallow_ = false; - - process make_process(); - - void do_clone_or_pull(); - bool do_clone(); - void do_pull(); - void do_add_submodule(); - - void do_set_credentials(); - void do_set_remote(); - void do_ignore_ts(); - void do_revert_ts(); - - void set_config(const std::string& key, const std::string& value); - bool has_remote(const std::string& name); - void rename_remote(const std::string& from, const std::string& to); - void add_remote(const std::string& name, const std::string& url); - void set_remote_push(const std::string& remote, const std::string& url); - void set_assume_unchanged(const fs::path& relative_file, bool on); - void apply(const std::string& diff); - void fetch(const std::string& remote, const std::string& branch); - void checkout(const std::string& what); - std::string current_branch(); - bool is_repo(); - bool branch_exists(); - bool has_uncommitted_changes(); - bool has_stashed_changes(); - void init(); - - std::string git_file(); - - static std::string make_url( - const std::string& org, const std::string& git_file, - const std::string& url_pattern={}); -}; class git_submodule_adder : public instrumentable<2> @@ -719,3 +596,6 @@ private: }; } // namespace + + +#include "git.h" diff --git a/vs/mob.vcxproj b/vs/mob.vcxproj index 028d579..a7f04b8 100644 --- a/vs/mob.vcxproj +++ b/vs/mob.vcxproj @@ -136,6 +136,7 @@ + diff --git a/vs/mob.vcxproj.filters b/vs/mob.vcxproj.filters index d8b1db4..f2ef1ac 100644 --- a/vs/mob.vcxproj.filters +++ b/vs/mob.vcxproj.filters @@ -269,5 +269,8 @@ src\core + + src\tools + \ No newline at end of file