summaryrefslogtreecommitdiff
path: root/src/command.cpp
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2023-04-02 12:46:44 +0200
committerEugen Wissner <belka@caraus.de>2023-04-02 12:46:44 +0200
commitae0048ef3d03c1511f2e12e0fdb5ae8d28061dab (patch)
tree8c6ffc8116b66530b4a42d63cc59d9c479cf3eab /src/command.cpp
parentf46a16b4a0d50b6512df2b312f7f800a9a963ca2 (diff)
downloadslackbuilder-ae0048ef3d03c1511f2e12e0fdb5ae8d28061dab.tar.gz
Add command to clone the source repository
Diffstat (limited to 'src/command.cpp')
-rw-r--r--src/command.cpp33
1 files changed, 32 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>();