navid/veins / commit
b2c412f69b54
Navid M <navidmomtahen@gmail.com> · 2026-11-29
parents: 4fd13fa7c760
Browse files at this commit · Download source
--- a/docs/SPECIFICATION_V1.adoc+++ b/docs/SPECIFICATION_V1.adoc@@ -757,6 +757,8 @@ . Importing is idempotent. A commit whose SHA-1 is in the map is not converted again. The initial import of a long history pays git's delta resolution cost once, for reading the source. This cost is not paid again on any later clone.++Git import does not copy the git mirror's remotes into native remotes, because a git host URL is not a veins URL. `vn git import -remote:<url> [-remote-name:<name>]` records a native remote after a successful import, using `o` as the default name, and makes it the active remote. `vn init -git-import:<gitdir>` accepts the same options. If `-remote:` is omitted, no native remote is configured; the command warns that `vn psh o` will fail until one is added with `vn remote add o <url>`. === Lazy git-backed import (M1) @@ -885,6 +887,8 @@ * `all`: fetch every chunk in history. . For `head` or `all`, the client computes the set of chunk IDs it lacks from the received manifests and issues `GET_CHUNKS`. On an initial clone with `all`, the server MAY satisfy this directly by streaming its packs, because it knows the client has nothing. . In incremental fetches, the client sends `GET_CHUNKS` only for chunk IDs it does not already hold (found by index lookup). Revisions of a regenerated file share most chunks, so only the changed chunks cross the wire.++After a successful native clone, the client records the source URL as remote `o` in local config (`remote.o.url`, plus `remote.o.key` and `remote.o.tls-pin` when supplied) and sets `remote.default = o`. A clone that promises blobs also sets `promisor = o`. This lets the user run `vn psh o` immediately, without first running `vn remote add`. The client MAY verify hashes lazily in the background (`-verify=lazy`) but the default is eager. Failed verification MUST abort the operation and discard the received data. @@ -1121,8 +1125,8 @@ |=== | Command | Description -| `vn init [path] [-git-import:<gitdir>]` | Create a repository, optionally importing an existing git repo.-| `vn clone <url> [-blobs head\|none\|all]` | Clone via the native protocol.+| `vn init [path] [-git-import:<gitdir>] [-remote:<url>] [-remote-name:<name>]` | Create a repository, optionally importing an existing git repo and configuring a native remote.+| `vn clone <url> [-blobs head\|none\|all]` | Clone via the native protocol. Records the source as remote `o`. | `vn status` | Working-copy changes, conflicts, files needing regeneration. | `vn log [-rev <revset>] [-lN \| -fN] [-no-col-titles]` | Show history, newest first, flagging conflicted and divergent changes. | `vn inf [-inc-gen]` | Show repository, language and author statistics; generated paths are excluded unless `-inc-gen` is passed.@@ -1138,8 +1142,9 @@ | `vn regenerate` | Run configured regeneration commands for `merge=regenerate` paths. | `vn undo`, `vn op log`, `vn op restore <op>`, `vn op revert <op>` | Operation log commands. | `vn bookmark set\|list\|delete`, `vn tag set\|ls\|rm\|latest` | Manage named pointers.-| `vn fetch`, `vn push [<remote>] [<bookmark>]` | Native protocol; `push` uses the current bookmark when omitted.-| `vn git import [-source:<gitdir>] [path]`, `vn git export`, `vn git materialize [path]`, `vn git fetch`, `vn git push`, `vn git remote` | Git bridge.+| `vn remote add\|set-url\|list\|remove ...` | Manage native remotes stored in local config.+| `vn fetch [<remote>]`, `vn push [<remote>] [<bookmark>]` | Native protocol. Both use the active remote when none is given; `push` uses the current bookmark when omitted.+| `vn git import [-source:<gitdir>] [-remote:<url>] [-remote-name:<name>] [path]`, `vn git export`, `vn git materialize [path]`, `vn git fetch`, `vn git push`, `vn git remote` | Git bridge. | `vn serve -stdio <repo>`, `vn serve -listen <addr:port> -root <dir> ...` | Run the native server over stdio or TLS. | `vn key generate\|list\|show\|import` | Manage client keys. | `vn access add\|list\|remove\|anonymous` | Manage a served repository's access file (server side, local only).@@ -1152,6 +1157,8 @@ `vn cfg` reads and writes `.veins/config` by default. With `-global`, it edits the user-level `~/.local/config/veins/veins.toml`. `vn cfg <key>` prints a value, `vn cfg <key> <value>` sets one, `vn cfg -unset <key>` removes one, and `vn cfg` with no arguments lists the configuration. `vn co <bookmark>` and `vn bmk set <name>` set the current bookmark, stored as `bookmark.current` in local config. `vn clone` and `vn git import` initialize it from the default branch (the checked-out or imported `HEAD`). Snapshots, `describe`, and `go` advance the current bookmark, and `vn push <remote>` uses it when no bookmark argument is given.++`vn fetch` and `vn push` use the active remote when no remote is named: `remote.current`, then `remote.default`, then `o`, then the first configured remote. A native clone records its source as remote `o` and sets `remote.default = o`, so `vn psh o` and bare `vn psh` work immediately after cloning. `vn log` prints commits newest first in aligned columns with no borders. Column titles are shown by default and can be omitted with `-no-col-titles`. `-lN` limits the output to the last N commits (newest N), while `-fN` shows the first N commits (oldest N) in oldest-first order. The separated forms `-l N` and `-f N`, and the bare forms `lN` and `fN`, are also accepted. Output is colored when standard output is a terminal; setting `NO_COLOR` disables color. --- a/docs/SPECIFICATION_V1.html+++ b/docs/SPECIFICATION_V1.html@@ -2171,7 +2171,10 @@ <div class="paragraph"> <p>The initial import of a long history pays git’s delta resolution cost once, for reading the source. This cost is not paid again on any later clone.</p> </div>+<div class="paragraph">+<p>Git import does not copy the git mirror’s remotes into native remotes, because a git host URL is not a veins URL. <code>vn git import -remote:<url> [-remote-name:<name>]</code> records a native remote after a successful import, using <code>o</code> as the default name, and makes it the active remote. <code>vn init -git-import:<gitdir></code> accepts the same options. If <code>-remote:</code> is omitted, no native remote is configured; the command warns that <code>vn psh o</code> will fail until one is added with <code>vn remote add o <url></code>.</p> </div>+</div> <div class="sect2"> <h3 id="_lazy_git_backed_import_m1">8.4. Lazy git-backed import (M1)</h3> <div class="paragraph">@@ -2475,6 +2478,9 @@ </ol> </div> <div class="paragraph">+<p>After a successful native clone, the client records the source URL as remote <code>o</code> in local config (<code>remote.o.url</code>, plus <code>remote.o.key</code> and <code>remote.o.tls-pin</code> when supplied) and sets <code>remote.default = o</code>. A clone that promises blobs also sets <code>promisor = o</code>. This lets the user run <code>vn psh o</code> immediately, without first running <code>vn remote add</code>.</p>+</div>+<div class="paragraph"> <p>The client MAY verify hashes lazily in the background (<code>-verify=lazy</code>) but the default is eager. Failed verification MUST abort the operation and discard the received data.</p> </div> </div>@@ -3005,12 +3011,12 @@ </thead> <tbody> <tr>-<td class="tableblock halign-left valign-top"><p class="tableblock"><code>vn init [path] [-git-import:<gitdir>]</code></p></td>-<td class="tableblock halign-left valign-top"><p class="tableblock">Create a repository, optionally importing an existing git repo.</p></td>+<td class="tableblock halign-left valign-top"><p class="tableblock"><code>vn init [path] [-git-import:<gitdir>] [-remote:<url>] [-remote-name:<name>]</code></p></td>+<td class="tableblock halign-left valign-top"><p class="tableblock">Create a repository, optionally importing an existing git repo and configuring a native remote.</p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock"><code>vn clone <url> [-blobs head|none|all]</code></p></td>-<td class="tableblock halign-left valign-top"><p class="tableblock">Clone via the native protocol.</p></td>+<td class="tableblock halign-left valign-top"><p class="tableblock">Clone via the native protocol. Records the source as remote <code>o</code>.</p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock"><code>vn status</code></p></td>@@ -3073,11 +3079,15 @@ <td class="tableblock halign-left valign-top"><p class="tableblock">Manage named pointers.</p></td> </tr> <tr>-<td class="tableblock halign-left valign-top"><p class="tableblock"><code>vn fetch</code>, <code>vn push [<remote>] [<bookmark>]</code></p></td>-<td class="tableblock halign-left valign-top"><p class="tableblock">Native protocol; <code>push</code> uses the current bookmark when omitted.</p></td>+<td class="tableblock halign-left valign-top"><p class="tableblock"><code>vn remote add|set-url|list|remove …​</code></p></td>+<td class="tableblock halign-left valign-top"><p class="tableblock">Manage native remotes stored in local config.</p></td> </tr> <tr>-<td class="tableblock halign-left valign-top"><p class="tableblock"><code>vn git import [-source:<gitdir>] [path]</code>, <code>vn git export</code>, <code>vn git materialize [path]</code>, <code>vn git fetch</code>, <code>vn git push</code>, <code>vn git remote</code></p></td>+<td class="tableblock halign-left valign-top"><p class="tableblock"><code>vn fetch [<remote>]</code>, <code>vn push [<remote>] [<bookmark>]</code></p></td>+<td class="tableblock halign-left valign-top"><p class="tableblock">Native protocol. Both use the active remote when none is given; <code>push</code> uses the current bookmark when omitted.</p></td>+</tr>+<tr>+<td class="tableblock halign-left valign-top"><p class="tableblock"><code>vn git import [-source:<gitdir>] [-remote:<url>] [-remote-name:<name>] [path]</code>, <code>vn git export</code>, <code>vn git materialize [path]</code>, <code>vn git fetch</code>, <code>vn git push</code>, <code>vn git remote</code></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">Git bridge.</p></td> </tr> <tr>@@ -3117,6 +3127,9 @@ <p><code>vn co <bookmark></code> and <code>vn bmk set <name></code> set the current bookmark, stored as <code>bookmark.current</code> in local config. <code>vn clone</code> and <code>vn git import</code> initialize it from the default branch (the checked-out or imported <code>HEAD</code>). Snapshots, <code>describe</code>, and <code>go</code> advance the current bookmark, and <code>vn push <remote></code> uses it when no bookmark argument is given.</p> </div> <div class="paragraph">+<p><code>vn fetch</code> and <code>vn push</code> use the active remote when no remote is named: <code>remote.current</code>, then <code>remote.default</code>, then <code>o</code>, then the first configured remote. A native clone records its source as remote <code>o</code> and sets <code>remote.default = o</code>, so <code>vn psh o</code> and bare <code>vn psh</code> work immediately after cloning.</p>+</div>+<div class="paragraph"> <p><code>vn log</code> prints commits newest first in aligned columns with no borders. Column titles are shown by default and can be omitted with <code>-no-col-titles</code>. <code>-lN</code> limits the output to the last N commits (newest N), while <code>-fN</code> shows the first N commits (oldest N) in oldest-first order. The separated forms <code>-l N</code> and <code>-f N</code>, and the bare forms <code>lN</code> and <code>fN</code>, are also accepted. Output is colored when standard output is a terminal; setting <code>NO_COLOR</code> disables color.</p> </div> <div class="paragraph">@@ -3507,7 +3520,7 @@ <div id="footer"> <div id="footer-text"> Version 0.1-draft<br>-Last updated 2026-11-28 19:16:07 UTC+Last updated 2026-11-29 01:18:57 UTC </div> </div> </body>--- a/xveins/CMakePresets.json+++ b/xveins/CMakePresets.json@@ -68,10 +68,30 @@ { "name": "tsan", "configurePreset": "tsan" } ], "testPresets": [- { "name": "dev", "configurePreset": "dev", "output": { "outputOnFailure": true } },- { "name": "release", "configurePreset": "release", "output": { "outputOnFailure": true } },- { "name": "release-harden", "configurePreset": "release-harden", "output": { "outputOnFailure": true } },- { "name": "asan", "configurePreset": "asan", "output": { "outputOnFailure": true } },- { "name": "tsan", "configurePreset": "tsan", "output": { "outputOnFailure": true } }+ {+ "name": "dev",+ "configurePreset": "dev",+ "output": { "outputOnFailure": true }+ },+ {+ "name": "release",+ "configurePreset": "release",+ "output": { "outputOnFailure": true }+ },+ {+ "name": "release-harden",+ "configurePreset": "release-harden",+ "output": { "outputOnFailure": true }+ },+ {+ "name": "asan",+ "configurePreset": "asan",+ "output": { "outputOnFailure": true }+ },+ {+ "name": "tsan",+ "configurePreset": "tsan",+ "output": { "outputOnFailure": true }+ } ] }--- a/xveins/src/cli/cli.cpp+++ b/xveins/src/cli/cli.cpp@@ -528,6 +528,9 @@ int run_init(const std::vector<std::string>& args) { std::string path = "."; std::optional<std::string> source;+ std::string remote_url;+ std::string remote_name = "o";+ bool remote_name_given = false; bool end_flags = false; for (std::size_t i = 2; i < args.size(); ++i) { const std::string& arg = args[i];@@ -540,6 +543,21 @@ std::cout << "-git-import: requires a path\n"; return 1; }+ } else if (!end_flags && arg.rfind("-remote:", 0) == 0) {+ remote_url = arg.substr(8);+ if (remote_url.empty()) {+ error_prefix();+ std::cout << "-remote: requires a URL\n";+ return 1;+ }+ } else if (!end_flags && arg.rfind("-remote-name:", 0) == 0) {+ remote_name = arg.substr(13);+ if (remote_name.empty()) {+ error_prefix();+ std::cout << "-remote-name: requires a name\n";+ return 1;+ }+ remote_name_given = true; } else if (!end_flags && is_flag(arg)) { error_prefix(); std::cout << "unknown flag: " << arg << "\n";@@ -548,6 +566,16 @@ path = arg; } }+ if (remote_name_given && remote_url.empty()) {+ error_prefix();+ std::cout << "-remote-name: requires -remote:<url>\n";+ return 1;+ }+ if (!source && !remote_url.empty()) {+ error_prefix();+ std::cout << "-remote: requires -git-import:<path>\n";+ return 1;+ } const auto initialized = init_repo(path_from_bytes(path)); if (!initialized) { error_prefix();@@ -570,7 +598,10 @@ } return 1; }- return git_import(*initialized);+ const int imported = git_import(*initialized);+ if (imported != 0)+ return imported;+ git_import_configure_remote(*initialized, remote_url, remote_name); } return 0; }@@ -2445,7 +2476,8 @@ } void show_init() {- std::cout << "usage: vn init [path] [-git-import:<gitdir>]\n\n";+ std::cout << "usage: vn init [path] [-git-import:<gitdir>] [-remote:<url>] "+ "[-remote-name:<name>]\n\n"; std::cout << "create a veins repository, optionally importing an existing " "git repository\n\n"; std::cout << "arguments:\n";@@ -2453,6 +2485,10 @@ std::cout << "options:\n"; std::cout << " -git-import:<gitdir> import from <gitdir> (a directory " "containing .git)\n";+ std::cout << " -remote:<url> configure a native remote after import\n";+ std::cout << " -remote-name:<name> remote name to configure (default: o)\n";+ std::cout << "\nwithout -remote:, no native remote is configured and 'vn psh o'\n";+ std::cout << "will fail until one is added with 'vn remote add o <url>'\n"; } void show_status() {@@ -2754,7 +2790,8 @@ } void show_git_import() {- std::cout << "usage: vn git import [-source:<gitdir>] [path]\n\n";+ std::cout << "usage: vn git import [-source:<gitdir>] [-remote:<url>] "+ "[-remote-name:<name>] [path]\n\n"; std::cout << "import commits and refs reachable from a git repository\n\n"; std::cout << "an empty working tree is checked out to the imported head\n\n"; std::cout << "arguments:\n";@@ -2762,6 +2799,10 @@ std::cout << "options:\n"; std::cout << " -source:<gitdir> source git root to mirror (a directory " "containing .git)\n";+ std::cout << " -remote:<url> configure a native remote after import\n";+ std::cout << " -remote-name:<name> remote name to configure (default: o)\n";+ std::cout << "\nwithout -remote:, no native remote is configured and 'vn psh o'\n";+ std::cout << "will fail until one is added with 'vn remote add o <url>'\n"; } void show_git_export() {@@ -2974,7 +3015,7 @@ return fetch_run(args); if (cmd == "gg") return gg_run(args);- if (cmd == "push" || "psh")+ if (cmd == "push" || cmd == "psh") return push_run(args); if (cmd == "serve") return serve_run(args);--- a/xveins/src/cli/net_commands.cpp+++ b/xveins/src/cli/net_commands.cpp@@ -492,12 +492,12 @@ return *name; } }- if (config_value(root, remote_key("origin", "url")))- return "origin";+ if (config_value(root, remote_key("o", "url")))+ return "o"; const auto names = list_remote_names(root); if (!names.empty()) return names.front();- return "origin";+ return "o"; } std::string role_text(std::uint8_t role) {@@ -726,11 +726,12 @@ if (auto fallback = auth::key_for_url(url)) key_name = *fallback; }- (void)repo_config_set(root, remote_key("origin", "url"), url);+ (void)repo_config_set(root, remote_key("o", "url"), url); if (key_explicit && !key_name.empty())- (void)repo_config_set(root, remote_key("origin", "key"), key_name);+ (void)repo_config_set(root, remote_key("o", "key"), key_name); if (!tls_pin.empty())- (void)repo_config_set(root, remote_key("origin", "tls-pin"), tls_pin);+ (void)repo_config_set(root, remote_key("o", "tls-pin"), tls_pin);+ (void)repo_config_set(root, "remote.default", "o"); const std::string repo_name = proto::url_repo_name(url); auto client = proto::Client::connect(url, key_name, repo_name, tls_pin);@@ -768,12 +769,12 @@ return 1; } }- if (!apply_refs(root, refs, "origin", true)) {+ if (!apply_refs(root, refs, "o", true)) { error_prefix(); std::cout << "cannot write repository state\n"; return 1; }- (void)repo_config_set(root, "promisor", "origin");+ (void)repo_config_set(root, "promisor", "o"); install_promisor_fetcher(); if (policy == "none") { info_prefix();@@ -811,7 +812,7 @@ // --------------------------------------------------------------------------- int fetch_run(const std::vector<std::string>& args) {- std::string remote_name = "origin";+ std::string remote_name; std::string path = "."; std::string explicit_key; std::string explicit_pin;@@ -845,6 +846,8 @@ return 1; } const fs::path root = *repo;+ if (!have_remote)+ remote_name = active_remote(root); auto url = config_value(root, remote_key(remote_name, "url")); if (!url) { error_prefix();@@ -959,7 +962,7 @@ // --------------------------------------------------------------------------- int push_run(const std::vector<std::string>& args) {- std::string remote_name = "origin";+ std::string remote_name; std::string bookmark; std::string explicit_key; std::string explicit_pin;@@ -996,6 +999,8 @@ return 1; } const fs::path root = *repo;+ if (!have_remote)+ remote_name = active_remote(root); if (bookmark.empty()) { if (auto current = current_bookmark_name(root)) bookmark = *current;@@ -1432,7 +1437,7 @@ // --------------------------------------------------------------------------- int whoami_run(const std::vector<std::string>& args) {- std::string remote = "origin";+ std::string remote; std::string url; std::string key; std::string repo_name;@@ -1455,6 +1460,8 @@ return 1; } const fs::path root = *repo;+ if (remote.empty())+ remote = active_remote(root); auto configured = config_value(root, remote_key(remote, "url")); if (!configured) { error_prefix();@@ -1509,8 +1516,8 @@ std::cout << " remove <name> remove a remote\n\n"; std::cout << "an empty -key: or -pin: value clears that setting\n\n"; std::cout << "examples:\n";- std::cout << " vn remote add origin veins://127.0.0.1:7419/navid-m/veins2\n";- std::cout << " vn remote set-url origin veins://example/repo -key:my-key\n";+ std::cout << " vn remote add o veins://127.0.0.1:7419/navid-m/veins2\n";+ std::cout << " vn remote set-url o veins://example/repo -key:my-key\n"; return true; } if (command == "clone") {@@ -1517,6 +1524,7 @@ std::cout << "usage: vn clone <url> [-blobs:<head|none|all>] [-key:<name>] " "[-pin:<sha256>] [path]\n\n"; std::cout << "clone a repository over file://, ssh://, or veins://\n\n";+ std::cout << "records the URL as remote 'o' and makes it the active remote\n"; std::cout << "without -key, the key stored by 'vn auth use' is used when " "available\n"; return true;@@ -1525,6 +1533,7 @@ std::cout << "usage: vn fetch [-key:<name>] [<remote>] [path]\n\n"; std::cout << "fetch new history and chunks from a configured native " "remote\n\n";+ std::cout << "without <remote>, the active remote is used\n"; std::cout << "auth falls back to remote.<name>.key, then 'vn auth use'\n"; return true; }@@ -1533,12 +1542,13 @@ std::cout << " vn gg <url> [path]\n\n"; std::cout << "fetch the active remote, or clone when given a URL\n\n"; std::cout << "the active remote is remote.current, then remote.default,\n";- std::cout << "then origin, then the first configured remote\n";+ std::cout << "then o, then the first configured remote\n"; return true; } if (command == "push" || command == "psh") { std::cout << "usage: vn push [-key:<name>] [<remote>] [<bookmark>] [path]\n\n"; std::cout << "push a bookmark to a configured native remote\n\n";+ std::cout << "without <remote>, the active remote is used\n"; std::cout << "without <bookmark>, the current bookmark is pushed\n"; std::cout << "tags reachable from the pushed bookmark are pushed too\n"; std::cout << "auth falls back to remote.<name>.key, then 'vn auth use'\n";--- a/xveins/src/git/git.cpp+++ b/xveins/src/git/git.cpp@@ -1310,6 +1310,24 @@ if (!object || object->kind != git::KIND_BLOB) return std::nullopt; return std::move(object->body);+}++void git_import_configure_remote(const fs::path& root, std::string_view url,+ std::string_view name) {+ if (name.empty())+ name = "o";+ const std::string url_key = git::remote_key(name, "url");+ if (url.empty()) {+ if (!repo_config_value(root, url_key)) {+ warning_prefix();+ std::cout << "no native remote configured; 'vn psh " << name+ << "' will fail until you add one with 'vn remote add " << name+ << " <url>'\n";+ }+ return;+ }+ (void)repo_config_set(root, url_key, url);+ (void)repo_config_set(root, "remote.default", name); } namespace {@@ -1317,6 +1335,9 @@ int git_import_cli(const std::vector<std::string>& args) { std::string repo_path = "."; std::optional<std::string> source;+ std::string remote_url;+ std::string remote_name = "o";+ bool remote_name_given = false; for (std::size_t i = 3; i < args.size(); ++i) { const std::string& arg = args[i]; if (arg.starts_with("-source:")) {@@ -1326,6 +1347,21 @@ return 1; } source = arg.substr(8);+ } else if (arg.starts_with("-remote:")) {+ if (arg.size() == 8) {+ error_prefix();+ std::cout << "-remote: requires a URL\n";+ return 1;+ }+ remote_url = arg.substr(8);+ } else if (arg.starts_with("-remote-name:")) {+ if (arg.size() == 13) {+ error_prefix();+ std::cout << "-remote-name: requires a name\n";+ return 1;+ }+ remote_name = arg.substr(13);+ remote_name_given = true; } else if (!arg.empty() && arg.front() == '-') { error_prefix(); std::cout << "unknown flag: " << arg << "\n";@@ -1333,6 +1369,11 @@ } else { repo_path = arg; }+ }+ if (remote_name_given && remote_url.empty()) {+ error_prefix();+ std::cout << "-remote-name: requires -remote:<url>\n";+ return 1; } const auto root = discover_repo(path_from_bytes(repo_path)); if (!root) {@@ -1355,7 +1396,11 @@ return 1; } }- return git_import(*root);+ const int imported = git_import(*root);+ if (imported != 0)+ return imported;+ git_import_configure_remote(*root, remote_url, remote_name);+ return 0; } int git_export_cli(const std::vector<std::string>& args) {--- a/xveins/src/git/git.h+++ b/xveins/src/git/git.h@@ -10,6 +10,7 @@ namespace vn { int git_import(const fs::path& root);+void git_import_configure_remote(const fs::path& root, std::string_view url, std::string_view name); int git_export(const fs::path& root); int git_materialize(const fs::path& root); int git_fetch(const fs::path& root, std::string_view remote);--- a/xveins/tests/integration/errors_tests.cpp+++ b/xveins/tests/integration/errors_tests.cpp@@ -12,8 +12,7 @@ namespace vn::integration { namespace { -void expect_no_exception(test::Context& t, const CommandResult& result,- std::string_view command) {+void expect_no_exception(test::Context& t, const CommandResult& result, std::string_view command) { (void)command; t.expect_not_contains(result.err, "exception:"); }@@ -71,25 +70,71 @@ const std::string huge(200'000, 'x'); const std::string binary("\x01\x7f\x80\xff", 4); const std::vector<std::string> tokens = {- "", "-", "--", "-x", "-r",- "-rev", "-m", "-message", "-l", "-f",- "-a", "-all", "-short", "-long", "-plain",- "-p", "-v", "-verbose", "-gen", "gen",- "txt", "bin", "eol", "-eol", "@",- "master", "HEAD", "0", "1", "999999999999999999999999",- "a", "a/b", "..", "../outside", "/",- "//", ".", ".veins", "a.veins", binary,- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "*.txt", "set", "ls", "rm",- "mv", "get", "list", "unset", "log",- "restore", "revert", "latest", "theirs", "ours",- "current", "all()", "unknown", huge,+ "",+ "-",+ "--",+ "-x",+ "-r",+ "-rev",+ "-m",+ "-message",+ "-l",+ "-f",+ "-a",+ "-all",+ "-short",+ "-long",+ "-plain",+ "-p",+ "-v",+ "-verbose",+ "-gen",+ "gen",+ "txt",+ "bin",+ "eol",+ "-eol",+ "@",+ "master",+ "HEAD",+ "0",+ "1",+ "999999999999999999999999",+ "a",+ "a/b",+ "..",+ "../outside",+ "/",+ "//",+ ".",+ ".veins",+ "a.veins",+ binary,+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",+ "*.txt",+ "set",+ "ls",+ "rm",+ "mv",+ "get",+ "list",+ "unset",+ "log",+ "restore",+ "revert",+ "latest",+ "theirs",+ "ours",+ "current",+ "all()",+ "unknown",+ huge, }; const std::vector<std::string> commands = {- "stat", "ls", "inf", "log", "show", "hash", "diff",- "new", "desc", "go", "amend", "co", "bmk", "tag",- "cfg", "attr", "op", "undo", "merge", "rebase", "xs",- "resolve", "fsck", "repack", "self-test", "version", "help", "rm",- "mv", "ex", "edit", "init",+ "stat", "ls", "inf", "log", "show", "hash", "diff", "new",+ "desc", "go", "amend", "co", "bmk", "tag", "cfg", "attr",+ "op", "undo", "merge", "rebase", "xs", "resolve", "fsck", "repack",+ "self-test", "version", "help", "rm", "mv", "ex", "edit", "init", }; for (const auto& command : commands) {@@ -139,13 +184,8 @@ f.write(".vnexclude", hostile_ignore); f.write(".vnattribs", std::string(100'000, 'a') + "\n"); - for (const std::vector<std::string>& command :- std::vector<std::vector<std::string>>{{"cfg", "list"},- {"stat"},- {"log"},- {"inf"},- {"fsck"},- {"version"}}) {+ for (const std::vector<std::string>& command : std::vector<std::vector<std::string>>{+ {"cfg", "list"}, {"stat"}, {"log"}, {"inf"}, {"fsck"}, {"version"}}) { CommandResult result = f.vn(command, {}, false); expect_no_exception(t, result, join_args(command)); }@@ -177,9 +217,15 @@ } for (const std::vector<std::string>& command :- std::vector<std::vector<std::string>>{- {"stat"}, {"log"}, {"fsck"}, {"show"}, {"ls"}, {"hash"}, {"inf"},- {"self-test"}, {"repack"}}) {+ std::vector<std::vector<std::string>>{{"stat"},+ {"log"},+ {"fsck"},+ {"show"},+ {"ls"},+ {"hash"},+ {"inf"},+ {"self-test"},+ {"repack"}}) { CommandResult result = f.vn(command, {}, false); expect_no_exception(t, result, join_args(command)); }@@ -198,4 +244,3 @@ }}; } } // namespace vn::integration---- a/xveins/tests/integration/git_tests.cpp+++ b/xveins/tests/integration/git_tests.cpp@@ -16,7 +16,11 @@ VnFixture f; const fs::path git_repo = make_git_repository(t, f); const fs::path vn_repo = f.root / "vnrepo";- f.vn({"init", vn_repo.string(), "-git-import:" + git_repo.string()}, f.root);+ f.vn({"init", vn_repo.string(), "-git-import:" + git_repo.string(),+ "-remote:file:///tmp/veins-native"},+ f.root);+ t.expect_contains(f.vn({"remote", "list"}, vn_repo).out, "o\tfile:///tmp/veins-native");+ t.expect_contains(f.vn({"cfg", "remote.default"}, vn_repo).out, "o"); std::string log = f.vn({"log", "-no-col-titles"}, vn_repo).out; t.expect_contains(log, "git one"); t.expect_contains(log, "git two");@@ -51,6 +55,39 @@ fs::create_directories(not_git); f.failed({"init", (f.root / "bad").string(), "-git-import:" + not_git.string()}, "not a git repository root", f.root);+#endif+}++void git_bridge_import_remote_options(test::Context& t) {+#if defined(_WIN32)+ t.expect(true);+#else+ if (!git_available()) {+ t.expect(true);+ return;+ }+ VnFixture f;+ const fs::path git_repo = make_git_repository(t, f);++ const fs::path named = f.root / "named";+ f.vn({"init", named.string(), "-git-import:" + git_repo.string(),+ "-remote:file:///tmp/veins-upstream", "-remote-name:upstream"},+ f.root);+ t.expect_contains(f.vn({"remote", "list"}, named).out, "upstream\tfile:///tmp/veins-upstream");+ t.expect_contains(f.vn({"cfg", "remote.default"}, named).out, "upstream");++ const fs::path warning = f.root / "warning";+ const CommandResult imported =+ f.vn({"init", warning.string(), "-git-import:" + git_repo.string()}, f.root);+ t.expect_contains(imported.text(), "no native remote configured");+ t.expect_contains(imported.text(), "vn psh o");++ const fs::path via_import = f.root / "via-import";+ f.vn({"init", via_import.string()}, f.root);+ f.vn({"git", "import", "-source:" + git_repo.string(), "-remote:file:///tmp/veins-import"},+ via_import);+ t.expect_contains(f.vn({"remote", "list"}, via_import).out, "o\tfile:///tmp/veins-import");+ t.expect_contains(f.vn({"cfg", "remote.default"}, via_import).out, "o"); #endif } @@ -61,6 +98,7 @@ { {"import_materialize_export", git_bridge_import_materialize_export}, {"invalid_import", git_bridge_invalid_import},+ {"import_remote_options", git_bridge_import_remote_options}, }}; } } // namespace vn::integration--- a/xveins/tests/integration/protocol_tests.cpp+++ b/xveins/tests/integration/protocol_tests.cpp@@ -15,8 +15,13 @@ t.expect_eq(f.read("a.txt", clone), "hello\n"); t.expect_contains(f.vn({"log"}, clone).out, "initial"); t.expect_contains(f.vn({"stat"}, clone).out, "working copy clean");- t.expect_contains(f.vn({"remote", "list"}, clone).out, "origin");- t.expect_contains(f.vn({"whoami", "origin"}, clone).out, "role: read");+ const std::string remotes = f.vn({"remote", "list"}, clone).out;+ t.expect_contains(remotes, "o\t");+ t.expect_not_contains(remotes, "origin");+ t.expect_contains(f.vn({"cfg", "remote.o.url"}, clone).out, "file://");+ t.expect_contains(f.vn({"cfg", "remote.default"}, clone).out, "o");+ t.expect_contains(f.vn({"whoami", "o"}, clone).out, "role: read");+ t.expect_contains(f.vn({"whoami"}, clone).out, "role: read"); } void protocol_push_fetch(test::Context& t) {@@ -40,30 +45,32 @@ const fs::path clone_a = f.root / "clone-a"; f.vn({"clone", "file://" + source.string(), clone_a.string()}, f.root);- f.vn({"cfg", "remote.origin.key", "integration"}, clone_a);+ f.vn({"cfg", "remote.o.key", "integration"}, clone_a); f.write("a.txt", "from clone a\n", clone_a); f.commit("clone a change", clone_a); f.write("c.txt", "from clone a again\n", clone_a); f.commit("clone a second change", clone_a);- const CommandResult pushed = f.vn({"push", "origin", "master"}, clone_a);+ const CommandResult pushed = f.vn({"psh", "o", "master"}, clone_a); t.expect_contains(pushed.out, "pushed master"); t.expect_contains(f.vn({"log"}, source).out, "clone a change"); t.expect_contains(f.vn({"log"}, source).out, "clone a second change");- t.expect_contains(f.vn({"whoami", "origin"}, clone_a).out, "role: write");+ t.expect_contains(f.vn({"whoami", "o"}, clone_a).out, "role: write"); f.vn({"tag", "set", "v0.0.1"}, clone_a);- const CommandResult tag_pushed = f.vn({"push", "origin", "master"}, clone_a);+ const CommandResult tag_pushed = f.vn({"push"}, clone_a); t.expect_contains(tag_pushed.out, "pushed 1 tag(s)"); t.expect_contains(f.vn({"tag", "ls"}, source).out, "v0.0.1"); const fs::path clone_b = f.root / "clone-b"; f.vn({"clone", "file://" + source.string(), clone_b.string()}, f.root);- f.vn({"cfg", "remote.origin.key", "integration"}, clone_b);+ f.vn({"cfg", "remote.o.key", "integration"}, clone_b); f.write("b.txt", "from clone b\n", clone_b); f.commit("clone b change", clone_b);- f.vn({"push", "origin", "master"}, clone_b);- f.vn({"fetch", "origin"}, clone_a);- t.expect_contains(f.vn({"log", "-rev", "origin/master"}, clone_a).out, "clone b change");+ f.vn({"push", "o", "master"}, clone_b);+ f.vn({"fetch", "o"}, clone_a);+ t.expect_contains(f.vn({"log", "-rev", "o/master"}, clone_a).out, "clone b change");+ f.vn({"fetch"}, clone_a);+ t.expect_contains(f.vn({"log", "-rev", "o/master"}, clone_a).out, "clone b change"); } void protocol_bad_inputs(test::Context& t) {--- a/xveins/tests/integration/support.cpp+++ b/xveins/tests/integration/support.cpp@@ -158,8 +158,6 @@ return CommandResult{code, out, {}}; #endif }-- bool git_available() { return run_shell({"git", "--version"}, fs::current_path()).code == 0;--- a/xveins/tests/integration/support.h+++ b/xveins/tests/integration/support.h@@ -4,8 +4,8 @@ #include "core/common.h" -#include <array> #include <algorithm>+#include <array> #include <chrono> #include <cstdint> #include <map>--- a/xveins/tests/unit/core_tests.cpp+++ b/xveins/tests/unit/core_tests.cpp@@ -12,8 +12,7 @@ void test_varint(test::Context& t) { const std::vector<std::uint64_t> values = {- 0, 1, 2, 127, 128, 255,- 256, 300, 16384, 1'000'000, 0xffffffffull,+ 0, 1, 2, 127, 128, 255, 256, 300, 16384, 1'000'000, 0xffffffffull, }; for (std::uint64_t value : values) { ByteWriter writer;@@ -45,8 +44,7 @@ Reader truncated_reader(Bytes(truncated, sizeof(truncated))); t.expect(!truncated_reader.varint().has_value()); - const std::uint8_t overflow[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,- 0xff, 0xff, 0x02};+ const std::uint8_t overflow[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x02}; Reader overflow_reader(Bytes(overflow, sizeof(overflow))); const auto overflowing = overflow_reader.varint(); t.expect(!overflowing.has_value());--- a/xveins/tests/unit/main.cpp+++ b/xveins/tests/unit/main.cpp@@ -9,7 +9,7 @@ int main(int argc, char** argv) { const std::vector<vn::test::Suite> suites = {- vn::unit::core_suite(), vn::unit::object_suite(), vn::unit::store_suite(),+ vn::unit::core_suite(), vn::unit::object_suite(), vn::unit::store_suite(), vn::unit::worktree_suite(), vn::unit::protocol_suite(), }; --- a/xveins/tests/unit/object_tests.cpp+++ b/xveins/tests/unit/object_tests.cpp@@ -79,8 +79,8 @@ template <typename Decode> void exercise_mutations(const std::vector<std::uint8_t>& body, Decode decode) { for (std::size_t i = 0; i < body.size(); ++i) {- for (const std::uint8_t mask : {std::uint8_t{0x01}, std::uint8_t{0x80},- std::uint8_t{0xff}}) {+ for (const std::uint8_t mask :+ {std::uint8_t{0x01}, std::uint8_t{0x80}, std::uint8_t{0xff}}) { auto copy = body; copy[i] = static_cast<std::uint8_t>(copy[i] ^ mask); (void)decode(bytes_of(copy));--- a/xveins/tests/unit/protocol_tests.cpp+++ b/xveins/tests/unit/protocol_tests.cpp@@ -134,12 +134,10 @@ t.expect(decoded_negotiate_ok.has_value()); if (decoded_negotiate_ok) t.expect_eq(decoded_negotiate_ok->size(), 3u);- expect_all_prefixes_rejected(t, negotiate_ok_bytes, [](Bytes bytes) {- return proto::decode_negotiate_ok(bytes);- });- exercise_mutations(negotiate_ok_bytes, [](Bytes bytes) {- return proto::decode_negotiate_ok(bytes);- });+ expect_all_prefixes_rejected(t, negotiate_ok_bytes,+ [](Bytes bytes) { return proto::decode_negotiate_ok(bytes); });+ exercise_mutations(negotiate_ok_bytes,+ [](Bytes bytes) { return proto::decode_negotiate_ok(bytes); }); auto bitmap_bytes = proto::encode_bitmap({1, 0, 1, 1}); const auto decoded_bitmap = proto::decode_bitmap(bytes_of(bitmap_bytes));@@ -161,14 +159,13 @@ t.expect_eq(decoded_updates->size(), 2u); expect_all_prefixes_rejected(t, updates_bytes, [](Bytes bytes) { return proto::decode_update_refs(bytes); });- exercise_mutations(updates_bytes,- [](Bytes bytes) { return proto::decode_update_refs(bytes); });+ exercise_mutations(updates_bytes, [](Bytes bytes) { return proto::decode_update_refs(bytes); }); t.expect_eq(proto::role_name(2), "write"); t.expect_eq(proto::role_name(1), "read"); t.expect_eq(proto::role_name(0), "anonymous");- const std::string message = proto::auth_message(1, "repo", bytes_of("server"),- bytes_of("client"), bytes_of("binding"));+ const std::string message =+ proto::auth_message(1, "repo", bytes_of("server"), bytes_of("client"), bytes_of("binding")); t.expect(!message.empty()); } @@ -197,8 +194,7 @@ t.expect_eq(record->kind, TYPE_BLOB); t.expect_eq(to_string(bytes_of(record->body)), body); }- expect_all_prefixes_rejected(t, encoded,- [](Bytes bytes) { return wire::parse_record(bytes); });+ expect_all_prefixes_rejected(t, encoded, [](Bytes bytes) { return wire::parse_record(bytes); }); exercise_mutations(encoded, [](Bytes bytes) { return wire::parse_record(bytes); }); ByteWriter claimed_huge;@@ -278,8 +274,7 @@ t.expect(!git::parse_sig("Name <mail@example.com> 1 +000").has_value()); t.expect(!git::parse_sig("Name <mail@example.com> nope +0000").has_value()); t.expect(!git::parse_sig("Name mail@example.com 1 +0000").has_value());- t.expect(!git::parse_sig("Name <mail@example.com> 999999999999999999999999 +0000")- .has_value());+ t.expect(!git::parse_sig("Name <mail@example.com> 999999999999999999999999 +0000").has_value()); git::ParsedCommit commit; const auto tree_oid = git::oid_from_hex(std::string(40, '1'));@@ -304,8 +299,7 @@ } for (std::size_t length = 0; length < commit_body.size(); ++length) (void)git::parse_commit(bytes_of(commit_body).first(length));- exercise_mutations(commit_body,- [](Bytes bytes) { return git::parse_commit(bytes); });+ exercise_mutations(commit_body, [](Bytes bytes) { return git::parse_commit(bytes); }); std::vector<std::uint8_t> tree_body; const std::string mode = "100644";@@ -328,8 +322,7 @@ (void)git::parse_tree(bytes_of(tree_body).first(length)); exercise_mutations(tree_body, [](Bytes bytes) { return git::parse_tree(bytes); }); - const std::string tag_text = "object " + git::oid_hex(*tree_oid) +- "\ntype commit\n\nmessage\n";+ const std::string tag_text = "object " + git::oid_hex(*tree_oid) + "\ntype commit\n\nmessage\n"; const auto parsed_tag = git::parse_tag(bytes_of(tag_text)); t.expect(parsed_tag.has_value()); if (parsed_tag) {