aboutsummaryrefslogtreecommitdiff
path: root/src/fetch_git.c
diff options
context:
space:
mode:
authordacctal <dacctal@symlinx.net>2026-05-24 10:23:38 +0000
committerdacctal <dacctal@symlinx.net>2026-05-24 10:23:38 +0000
commitaa0d78815004ae6b0c4a42b0e024f5c4ef555ae2 (patch)
tree62f97b4c5acfdb98003568466f878fbd3d6b9dfb /src/fetch_git.c
parent83d471f2c1d1b1fa6be51f41e4f1c36ab19d7094 (diff)
c rewrite
Diffstat (limited to 'src/fetch_git.c')
-rw-r--r--src/fetch_git.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/fetch_git.c b/src/fetch_git.c
new file mode 100644
index 0000000..04f6428
--- /dev/null
+++ b/src/fetch_git.c
@@ -0,0 +1,40 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include "fetch_git.h"
+#include "vars.h"
+
+int fetch_git(Pkg pkg) {
+ pid_t pid = fork();
+ if (pid == 0) {
+ const char *argv[8];
+ int i = 0;
+ argv[i++] = "git";
+ argv[i++] = "-c";
+ argv[i++] = "advice.detachedHead=false";
+ argv[i++] = "clone";
+ if (strcmp(pkg.ver, "HEAD") != 0) {
+ argv[i++] = "--branch";
+ argv[i++] = pkg.ver;
+ }
+ argv[i++] = pkg.url;
+ argv[i++] = pkg.src;
+ argv[i] = NULL;
+
+ execvp("git", (char *const *)argv);
+ _exit(127);
+ }
+
+ int status;
+ waitpid(pid, &status, 0);
+ int result = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
+
+ if (result != 0) {
+ printf("clone failed\n");
+ }
+
+ return result;
+} \ No newline at end of file