diff options
| author | Eugen Wissner <belka@caraus.de> | 2023-04-02 12:46:44 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2023-04-02 12:46:44 +0200 |
| commit | ae0048ef3d03c1511f2e12e0fdb5ae8d28061dab (patch) | |
| tree | 8c6ffc8116b66530b4a42d63cc59d9c479cf3eab /src | |
| parent | f46a16b4a0d50b6512df2b312f7f800a9a963ca2 (diff) | |
| download | slackbuilder-ae0048ef3d03c1511f2e12e0fdb5ae8d28061dab.tar.gz | |
Add command to clone the source repository
Diffstat (limited to 'src')
| -rw-r--r-- | src/command.cpp | 33 | ||||
| -rw-r--r-- | src/command.h | 25 | ||||
| -rw-r--r-- | src/config.h | 1 |
3 files changed, 58 insertions, 1 deletions
diff --git a/src/command.cpp b/src/command.cpp index 4066c23..0fa6bf1 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -1,5 +1,6 @@ #include "command.h" #include <cassert> +#include "config.h" namespace katja { @@ -17,7 +18,33 @@ namespace katja void help::execute() const { std::cout << "Usage:\n" - "\tkatja {info|help} [OPTIONS]\n\n"; + "\tkatja {list|update|help} [OPTIONS]\n\n"; + } + + update::update() + : git_binary(boost::process::search_path("git")) + { + } + + void update::execute() const + { + std::filesystem::path workdir{ WORKDIR }; + std::filesystem::path repository = workdir / "sbo/repository"; + std::filesystem::file_status repository_status = std::filesystem::status(repository); + + if (std::filesystem::exists(repository_status) + && !std::filesystem::is_directory(repository_status)) + { + throw std::runtime_error("The working directory path \"" + + repository.string() + "\" exists, but it isn't a directory."); + } + else if (!std::filesystem::exists(repository_status)) + { + git("clone", std::filesystem::path(), + "git://git.slackbuilds.org/slackbuilds.git", repository.native()); + } + git("remote", repository.native(), "update", "--prune"); + git("reset", repository.native(), "--hard", "origin/master"); } command_exception::command_exception(const command_exception_t exception_type, @@ -65,6 +92,10 @@ namespace katja { return std::make_unique<list>(); } + else if (strcmp(argv[1], "update") == 0) + { + return std::make_unique<update>(); + } else if (strcmp(argv[1], "help") == 0) { return std::make_unique<help>(); diff --git a/src/command.h b/src/command.h index 8d0679d..f03281f 100644 --- a/src/command.h +++ b/src/command.h @@ -3,6 +3,8 @@ #include <memory> #include <vector> #include "package.h" +#include <boost/process.hpp> +#include <filesystem> namespace katja { @@ -24,6 +26,29 @@ namespace katja void execute() const override; }; + class update final : public command + { + boost::filesystem::path git_binary; + + template<typename... Args> + void git(const std::string& command, const std::filesystem::path& cwd, const Args&... args) const + { + if (cwd.empty()) + { + boost::process::system(git_binary, command, args...); + } + else + { + boost::process::system(git_binary, "-C", cwd.native(), command, args...); + } + } + + public: + explicit update(); + + void execute() const override; + }; + enum class command_exception_t { no_command, diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..c156081 --- /dev/null +++ b/src/config.h @@ -0,0 +1 @@ +#define WORKDIR "./var" |
