Artifact 517f64cc62d6c66bf16d00ef21d9499b596c6beaaf2f0f445962ca2bf5cd15d3:
- File
src/main.c
— part of check-in
[fe29cebc6a]
at
2026-11-13 20:38:51
on branch trunk
— Phase 7b-1: a wardrobe syncs with a remote, over file:// and http://
suit remote sets, shows or clears a wardrobe's remote address. An address that carries a user name or password is refused. suit login reads a secret from standard input into a credentials file of mode 0600, and suit refuses to use that file if anyone else can read it. The secret is never printed, never put in an error message or another file, and is wiped from memory after each use.
suit sync pulls, brings the working copy forward with the safe update, and pushes. When both sides have new check-ins it tries a merge as a dry run. A clean merge is checked in and pushed. A conflicting one changes no file, is pushed as a fork so nothing is lost, and is written to the attention file. No conflict marker is ever written to a live file. With local changes in the working copy the pull is kept and nothing else happens.
suit tend now continues into a sync after its check-in.
Three limits of libfossil, each handled here: its merge drops a file the other side deleted, so suit finds those itself and treats a delete against an edit as a conflict; a merge that changes no file cannot be checked in, so the files are put back and the fork stays open; and a file:// remote is reached through the stock fossil program, which must be on the path. http:// uses libfossil's own socket code and starts no other program.
An https:// address is accepted and stored, and syncing it says this build cannot use https yet. There is no clone command yet.
Also: LICENSE (BSD 2-Clause, the same as libfossil), a license section and current status in the README, and a state table in docs/phases.md.
1204 unit checks, 227 shell cases, 555 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. Seven fuzz targets. No suite has fewer cases than at the last check-in. (user: dmestas, size: 4883) [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 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 == 3 ? store_tend(argv[2]) : 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(); }