Artifact fb221a13b30c8888c18a01df468b5afff7cdcc830cde096ad616ca9b05c0fe5a:
- File
src/main.c
— part of check-in
[0c65a50c7f]
at
2026-11-14 00:48:47
on branch trunk
— Phase 7c-1: a wardrobe can be cloned onto a second machine, and one call tends them all
suit clone NAME URL makes a wardrobe on this machine from a remote. It clones into a temporary file, renames it into place, opens the store at the tip of trunk and records the remote last. A failure at any step removes what it made: no partial repository file, no store folder, no remotes line. A name already in use is refused with exit 20 and nothing is overwritten. A login saved beforehand is used, so a private wardrobe can be cloned.
suit tend with no name tends every wardrobe in name order. One wardrobe's failure does not stop the others; the exit code is the highest any of them returned, with one line for each that did not end clean.
After three failed syncs in a row the attention file names the wardrobe and the host. A sync that reaches the remote clears the count and the line.
A limit: libfossil's clone builds its own context, so fault injection cannot reach the system calls made inside the clone. The tests cover every step suit takes around it, and a bad remote covers a failure inside it.
One existing case changed: tend-usage expected suit tend with no name to be an error, which is now the behaviour above. It tests suit tend with two names instead.
1204 unit checks, 227 shell cases, 669 store cases, 612 placement cases and 378 project cases, under clang, under gcc 16, with no user name set, and under a strict umask. 100% coverage in all 22 source files. No suite has fewer cases than at the last check-in. (user: dmestas, size: 5050) [annotate] [blame] [check-ins using]
#include "bench.h" #include "commands.h" #include "conf.h" #include "platform.h" #include "remote.h" #include "stamp.h" #include "store.h" #include <errno.h> #include <string.h> #include <unistd.h> static Conf conf; static int usage(void) { say(STDERR_FILENO, "usage: suit check FILE\n" " suit store open|status|update|repair NAME\n" " suit plan | apply | status | off | run\n" " suit why NAME\n" " suit machine [NAME]\n" " suit roots [add|rm FOLDER]\n" " suit projects [scan]\n" " suit project set FOLDER KEY | unset FOLDER\n" " suit compare\n" " suit lint NAME\n" " suit commit NAME -m TEXT [--confirm-deletions]\n" " suit tend [NAME]\n" " suit clone NAME URL\n" " suit back NAME\n" " suit remote NAME [URL|--none]\n" " suit login NAME USER (the secret on standard input)\n" " suit logout NAME\n" " suit sync NAME\n" " suit stamp PATH...\n" " suit run\n" " suit bench [-n N] [-e EMPTY_PROGRAM] [-t MICROSECONDS] [-m KIB]\n"); return 2; } static int cmd_check(const char *path) { ConfError err; if (!conf_load(&conf, path, &err)) { say(STDERR_FILENO, "%s:%d: %s\n", path, err.line, err.msg); return 2; } if (!conf_dump(&conf, STDOUT_FILENO)) { say(STDERR_FILENO, "suit: cannot write the dump: %s\n", strerror(errno)); return 1; } return 0; } static int cmd_store(int argc, char **argv) { if (argc != 4) return usage(); const char *verb = argv[2]; if (strcmp(verb, "open") == 0) return store_open(argv[3]); if (strcmp(verb, "status") == 0) return store_status(argv[3]); if (strcmp(verb, "update") == 0) return store_update(argv[3]); if (strcmp(verb, "repair") == 0) return store_repair(argv[3]); return usage(); } static int cmd_roots_args(int argc, char **argv) { if (argc == 2) return cmd_roots(nullptr, nullptr); bool verb = argc == 4 && (strcmp(argv[2], "add") == 0 || strcmp(argv[2], "rm") == 0); return verb ? cmd_roots(argv[2], argv[3]) : usage(); } static int cmd_project_args(int argc, char **argv) { if (argc == 5 && strcmp(argv[2], "set") == 0) return cmd_project(argv[3], argv[4]); if (argc == 4 && strcmp(argv[2], "unset") == 0) return cmd_project(argv[3], nullptr); return usage(); } static int cmd_commit(int argc, char **argv) { bool confirm = argc == 6 && strcmp(argv[5], "--confirm-deletions") == 0; if (argc < 5 || argc > 6 || strcmp(argv[3], "-m") != 0 || (argc == 6 && !confirm)) return usage(); return store_commit(argv[2], argv[4], confirm); } int main(int argc, char **argv) { if (argc < 2) return usage(); const char *cmd = argv[1]; if (strcmp(cmd, "run") == 0) return argc == 2 ? cmd_run() : usage(); if (strcmp(cmd, "compare") == 0) return argc == 2 ? stamp_check(true) : usage(); if (strcmp(cmd, "plan") == 0) return argc == 2 ? cmd_plan() : usage(); if (strcmp(cmd, "apply") == 0) return argc == 2 ? cmd_apply() : usage(); if (strcmp(cmd, "status") == 0) return argc == 2 ? cmd_status() : usage(); if (strcmp(cmd, "why") == 0) return argc == 3 ? cmd_why(argv[2]) : usage(); if (strcmp(cmd, "off") == 0) return argc == 2 ? cmd_off() : usage(); if (strcmp(cmd, "machine") == 0) return argc <= 3 ? cmd_machine(argc == 3 ? argv[2] : nullptr) : usage(); if (strcmp(cmd, "roots") == 0) return cmd_roots_args(argc, argv); if (strcmp(cmd, "projects") == 0) { if (argc == 2) return cmd_projects(false); return argc == 3 && strcmp(argv[2], "scan") == 0 ? cmd_projects(true) : usage(); } if (strcmp(cmd, "project") == 0) return cmd_project_args(argc, argv); if (strcmp(cmd, "check") == 0) return argc == 3 ? cmd_check(argv[2]) : usage(); if (strcmp(cmd, "stamp") == 0) return argc >= 3 ? stamp_write(argc - 2, argv + 2) : usage(); if (strcmp(cmd, "store") == 0) return cmd_store(argc, argv); if (strcmp(cmd, "back") == 0) return argc == 3 ? store_back(argv[2]) : usage(); if (strcmp(cmd, "lint") == 0) return argc == 3 ? store_lint(argv[2]) : usage(); if (strcmp(cmd, "remote") == 0) return argc == 3 || argc == 4 ? cmd_remote(argv[2], argc == 4 ? argv[3] : nullptr) : usage(); if (strcmp(cmd, "login") == 0) return argc == 4 ? cmd_login(argv[2], argv[3]) : usage(); if (strcmp(cmd, "logout") == 0) return argc == 3 ? cmd_logout(argv[2]) : usage(); if (strcmp(cmd, "sync") == 0) return argc == 3 ? store_sync(argv[2]) : usage(); if (strcmp(cmd, "tend") == 0) return argc == 2 ? store_tend_all() : argc == 3 ? store_tend(argv[2]) : usage(); if (strcmp(cmd, "clone") == 0) return argc == 4 ? store_clone(argv[2], argv[3]) : usage(); if (strcmp(cmd, "commit") == 0) return cmd_commit(argc, argv); if (strcmp(cmd, "bench") == 0) return bench_main(argc - 2, argv + 2); return usage(); }