src/main.cpp

changeset 4
82680ce258d6
parent 3
c87bde92805f
child 5
60c2588b4455
--- a/src/main.cpp	Tue Jan 21 20:24:45 2025 +0100
+++ b/src/main.cpp	Tue Jan 21 21:01:54 2025 +0100
@@ -24,6 +24,7 @@
 
 #include "settings.h"
 #include "repositories.h"
+#include "process.h"
 
 #include <cstdlib>
 #include <cstdio>
@@ -131,18 +132,49 @@
 }
 
 int main(int argc, char *argv[]) {
+    // parse settings
     fm::settings settings;
-
     if (parse_args(settings, argc, argv)) {
         return EXIT_FAILURE;
     }
 
+    // check hg and git
+    fm::process proc;
+    proc.setbin(settings.hg);
+    if (proc.exec({"--version"})) {
+        fprintf(stderr, "Testing hg binary '%s' failed!\n", settings.hg.c_str());
+        return EXIT_FAILURE;
+    }
+    proc.setbin(settings.git);
+    if (proc.exec({"--version"})) {
+        fprintf(stderr, "Testing git binary '%s' failed!\n", settings.git.c_str());
+        return EXIT_FAILURE;
+    }
+
+    // scan for repos
     fm::repositories repos;
     for (auto &&path: settings.paths) {
         repos.scan(path, settings.depth);
     }
-    if (!settings.update_repos) {
-        // TODO: update repositories
+
+    // update repos, if not disabled
+    if (settings.update_repos) {
+        for (auto &&repo : repos.list()) {
+            proc.chdir(repo.path);
+            if (repo.type == fm::HG) {
+                proc.setbin(settings.hg);
+                if (proc.exec({"pull"})) {
+                    fprintf(stderr, "Pulling repo '%s' failed!\nMaybe there is no remote?\n", repo.path.c_str());
+                } else if (proc.exec({"update"})) {
+                    fprintf(stderr, "Updating repo '%s' failed!\nMaybe there are local changes?\n", repo.path.c_str());
+                }
+            } else {
+                proc.setbin(settings.git);
+                if (proc.exec({"pull"})) {
+                    fprintf(stderr, "Pulling repo '%s' failed!\nMaybe there is no remote or there are local changes?\n", repo.path.c_str());
+                }
+            }
+        }
     }
     // TODO: calculate the heat maps
 

mercurial