Commit Graph

120 Commits

Author SHA1 Message Date
Fintan Halpenny 48aa725bea
cli: Add `--base` option to `rad patch update`
Allow the CLI user to update a patch's base commit through the `rad
patch update` command.

There was check to see if the head of the branch was the same as the
head of the revision, which would result in the update being skipped.
This was adapted to check that the head *and* the base were the same.

A test was added in the examples to showcase this use.

Signed-off-by: Fintan Halpenny <Fintan Halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-12-19 15:00:27 +01:00
cloudhead 13db55014b
cli: Show URL on `rad init` 2023-12-19 14:15:30 +01:00
cloudhead 6eb2772235
node: Improve flexibility of test environment
Allows us to pass full configs (profile or node) when creating test
nodes or profiles.
2023-12-19 14:15:30 +01:00
cloudhead 5e3990d411
cli: `rad ls` shouldn't show unseeded by default
Unseeded repos should not show up in `rad ls`, by default. Only with
`--all`. We also use a special visibility of "local" for those projects.
2023-12-19 14:14:11 +01:00
Fintan Halpenny 070e912b3e
cli: allow directory in rad clone
Allow the user to specify a directory to clone into when
performing `rad clone`.

Signed-off-by: Fintan Halpenny <Fintan Halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-12-14 10:52:04 +01:00
cloudhead d773659d66
cli: Don't fork on clone
Since forking creates your `rad/sigrefs`, which then needs to be backed
up forever, we avoid forking on `rad clone`. This should make little or
no difference for users, as the "fork" will be created on `git push`.
2023-12-13 12:14:06 +01:00
cloudhead 472a1e6545
cli: Add `watch` command
Allows watching and waiting for refs to change. This is especially useful for
tests. For now, we don't show it in the output of `rad`.
2023-12-11 12:04:26 +01:00
cloudhead 6ca7da2768
radicle: Rename many more methods using new naming 2023-12-06 10:02:00 +01:00
cloudhead 1b026ae0ee
node: Rename node `tracking` module 2023-12-06 10:00:45 +01:00
cloudhead e65595c4c7
node: Rename commands with new "seed" nomenclature 2023-12-06 09:56:58 +01:00
cloudhead f453090e27
cli: Consolidate policy/scope variants
* Policy::Track -> Policy::Allow
* Scope::Trusted -> Scope::Followed
2023-12-06 09:56:58 +01:00
cloudhead 4605348d68
cli: From "tracking" to "seeding" and "following"
Split the commands and change the naming.

* Tracking a repo is now called "seeding"
* Tracking a peer is now called "following"

In this commit, we don't change most of the internal code, only the
user-facing part.
2023-12-06 09:56:57 +01:00
Fintan Halpenny 1af9480b08
cli: Move label commands to `issue` and `patch`
It is more natural for the label and unlabel commands to exist as
subcommands of the object they are labelling, i.e. issues and
patches.

Remove the `rad label` and `rad unlabel` commands, moving their
functionality to the `rad issue` and `rad patch` commands. The
`rad-issue.md` and `rad-patch.md` tests are modified to include a
label test.

The `rad patch show` command did not support showing labels as part of
its output. This was also included to confirm the test above was working.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-30 14:02:37 +01:00
cloudhead af095d53ca
radicle: Add foreign-key constraint for routing 2023-11-30 13:00:59 +01:00
cloudhead 6b04eff34c
radicle: Consolidate databases
Instead of having a routing database, and an addresses database,
consolidate that in a single database called `node.db`.

We also simplify database access, by providing a single type for opening
the database, and use traits to access the various functions.

We create a new `seed::Store` that has seed-related methods split out of
the `address::Store`.

Note that tracking is still in its own database currently, as it isn't
ephemeral state. This makes it easy to delete the new `node.db` without
risk of losing any important information.

To avoid renaming all database methods, we create a `Stores` wrapper
that allows us to access routing, addresses, seeds etc. without type
ambiguity.

This is a breaking change and requires `addresses.db` and `routing.db`
to be deleted.
2023-11-30 13:00:59 +01:00
Fintan Halpenny 0af233cceb
cli: prevent missing delegate being added
It's necessary for a delegate's references to be present, e.g.
verification, calculating of canonical data, etc.

To ensure that a user does not get themselves into a state where they
have added a delegate without their references, prevent adding a
delegate to the identity document if their `rad/sigrefs` is not
present.

As well as this, it ensures that if there is a `rad/sigrefs` that it
has the default branch -- since it's possible for a peer to have created
`rad/sigrefs` through COBs without a default branch.

This change meant that the `rad-id` tests required the test scenarios
to be set up with all nodes having each other's references. A test
case to add a missing delegate was also added to `rad-id.md`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-30 12:20:16 +01:00
Fintan Halpenny 5b1cdbaa4a
radicle: remove repo iff there's no local rad/sigrefs
If the local peer does not have any `rad/sigrefs` then there is no
risk of any data corruption. In this case the repository can be
removed entirely.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-30 10:48:14 +01:00
cloudhead ad7a3addb6
cli: Add `rad config` command
Displays the current configuration.

Also move to our tree-sitter highlighter for pretty-printing JSON and
remove the `json-color` dependency.
2023-11-30 10:46:32 +01:00
Fintan Halpenny 0fb1128bd3
cli: rework `rad rm` as `rad clean`
Removing a repository completely can result in data corruption for
users, since a user's `rad/sigrefs` are the ground truth of their
state, and any fork of them results in errors in the protocol.

Instead of `rad rm`, we replace it with `rad clean` that removes all
remotes other than the local peer's namespace and the delegates'. The
delegates are also necessary to keep, since the repository's identity
is dependent on them.

Note that the remotes that were cleaned will be populated again upon
fetching, as long as they are tracked.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-24 10:48:06 +00:00
cloudhead e703bad294
remote-helper: Fix `FETCH_HEAD` setting on fetch
The `git2` crate is not reliable at setting the `FETCH_HEAD` on fetch.
Therefore we disable that feature, and let the git command-line do its
thing.
2023-11-22 11:29:44 +01:00
Fintan Halpenny 6510705521
cli: add revision option to rad patch checkout
Add the `--revision` option for `rad patch checkout`. This allows the
user to specify a particular revision of the patch to checkout. If the
revision is not specified it will use the latest revision of the patch.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-21 10:19:25 +01:00
Fintan Halpenny 30ad7e4d67
cli: add force flag to rad patch checkout
Add a `--force` flag to forcibly checkout the branch to the latest
revision, if the branch already exists.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-21 10:19:25 +01:00
cloudhead d3b0483f42
cli: Implement `rad sync status` command
This command shows the sync status of a repository by consulting the
database via the node.

To make it work, we call into the address store to update the
`repo-sync-status` table when receiving ref announcements that are
relevant to us.
2023-11-17 16:56:19 +01:00
cloudhead 9b7c48ab40
cli: Improve `rad diff`
* Properly show the user when a file was moved or copied.
* Don't require a radicle project in the current repo.
2023-11-09 13:04:40 +01:00
Fintan Halpenny 75b52e28b2
radicle: separate repository validation
Make the validation logic customisable by extracting it out into a
separate trait that can be defined by other crates.

The Repository validation logic stays the same.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-06 12:06:13 +01:00
Fintan Halpenny 7e3c7a7ae0
cli: Check for branch on checkout
The `rad patch checkout` command would blindly create a branch when
being executed. If there was a branch already existing and user had
committed to that branch, switched without updating the patch, and
then switched back, then they would lose the commit on that branch --
the original commit of the patch would be taken instead.

Fix this by first checking if the branch existed beforehand, and
setting the workspace to use that branch's commit.

Add a test to ensure that this works as expected.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-10-30 15:25:27 +01:00
cloudhead 1d167581f2
cob: Introduce `xyz.radicle.id` COB
Introduces a new COB type to store repository identity documents.

The reason for this change is to:

1. Simplify the code, as the identity document logic resembled a COB,
   yet it had custom logic. This allows existing COB code to be used for
   identities.
2. Make identity document update logic more flexible, since COB actions
   can be added in the future.
3. Re-purpose existing tools around COBs to work on identities, eg. `rad
   cob`.
4. Unify the concept of an identity change proposal, with regular identity
   changes. This means we can remove the `id.proposal` COB in favor of
   using the `id` COB itself.

Notes
-----

* Each repository has one Identity COB.
* The `Proposal` COB has been repurposed into the `Identity` COB.
* Identity documents are stored as *embeds* inside the Identity COB
  actions.
* The action that contains new document versions is called `revision`,
  just like the Patches COB.
* The namespaced `rad/id` ref is a symbolic reference to that Identity
  COB.
* The canonical `rad/id` ref is a direct reference to the commit in the
  Identity COB that contains the latest *accepted* revision of the
  document.
* All commands for managing identities have been folded into `rad id`.
  Hence `rad delegate` and `rad edit` are removed.
* The concept of "rebasing" an identity document is gone.
* The `rad id` output has been updated to match the style of other
  commands.
* When a revision has enough signatures, it is automatically adopted as
  the current identity, there is no longer the need for a "commit"
  action.
* When an identity revision is proposed, and the current identity has a
  threshold of `1`, that identity is automatically accepted due to the
  above point.
* The idea of "verifying a peer's identity branch" no longer applies, as
  COBs cannot be verified one history at a time.
* Since the root commit of the Identity COB does not have a "Resource"
  to point to (it would have to point to itself, which is impossible),
  we've made the resource id optional for COBs.
2023-10-12 17:32:33 +02:00
Lars Wirzenius b133785449
cli: Add `rad cob list` subcommand
This will be helpful when we add additional types of COB.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2023-10-11 14:44:32 +02:00
Alexis Sellier c0271c303f
Prevent divergences in canonical head
On push, we check whether the resulting state would cause a
divergence/fork in the canonical head, and if so, prevent the push from
happening.

This is to avoid situations where delegates have to then rollback their
heads.

Note that this doesn't prevent forks from happening altogether, as they
could happen asychronously, but it mitigates the problem.
2023-09-27 12:25:14 +02:00
Slack Coder 8e58ba6433
cli: Implement DDiff
Define types to support Diff of Diffs leaning on the Radicle Surf types.

Use Radicle Surf's Hunk type, but custom Diff, FileDiff, and
Modification types, and avoid Serde serialization as it does not yet
seem necessary.
2023-09-19 15:22:42 +02:00
Slack Coder cb78f144be
cli: Add diff parsing
Parse Git's unified diff format into Radicle Surf's types.  Support to
and from the format helps testing and debugging.

Split the UnifiedDiff trait into Decode and Encode traits so we
can offer Decode in cases where no data could be expected..
For example Option<Hunk<_>> and Hunk<_> allowing partial and repeated
decoding on a byte stream.

Avoid decoding `Diff`, `DiffContent::Binary`, `FileDiff`, and `FileHeader`
types.  `Diff` keeps fields and methods private which are necessary for
decoding.
2023-09-19 15:18:50 +02:00
cloudhead 112c940d81
cli: Add tests for `rad publish` 2023-09-05 11:16:09 +02:00
cloudhead f2e74fdad2
cli: Choose repo visibility on init
This allows a user to choose private or public visibility on `rad init`.
It also improves the output to tell the user what happened due to this
choice.
2023-09-03 17:21:37 +02:00
cloudhead 46b0dfb11c
cli: Improve `rad init` error when not in Git repo 2023-09-01 15:17:41 +02:00
cloudhead df0b5da559
cli: Improve node connection error 2023-09-01 12:22:50 +02:00
cloudhead 09a284f09c
node: Make fetch timeout configurable
When a fetch is user-requested, a timeout can be supplied that is passed
down to the worker.

When a fetch is service-requested, a default timeout is used.
2023-09-01 12:13:45 +02:00
cloudhead a1df6d3748
cli: Add private repo support to `rad sync`
We can't use `node::seeds` for private repos.
2023-09-01 12:13:45 +02:00
cloudhead 534503d002
cob: Add support for media embeds in COBs
This change allows for files (blobs) to be embedded into COB entries.
This allows for things like image attachments in issue comments for example.

For now, we only enable this in the `issue` COB.

The way it works is that relevant COB actions carry metadata about which
files are attached to them; and we store those files as blobs inside the
COB entry's *tree* object, under an `embeds/` folder.

The `Embed<T>` type is used for the above, and either carries actual
content, or carries a content-id. Retrieving the actual content is as
simple as asking the repository for a blob with that content-id.

As a possible future extension, MIME types could be stored alongside the
files in a "metadata" file. This could help clients display the content
appropriately.
2023-08-22 14:29:23 +02:00
cloudhead f282e09dce
cli: Fix test speed regression
These two tests were holding everything up.
2023-08-21 11:57:32 +02:00
cloudhead 9bc636ae6e
cli: Write test for merge commits with patches 2023-08-16 16:23:32 +02:00
cloudhead d973fd42f2
cli: Auto-connect on sync
This adds functionality so that on `rad sync` and `rad clone`, we
connect to known seeds if necessary, before attempting to fetch.

In passing, some related changes were made:

* The `rad sync` command's arguments were reworked:
  `--replicas <count>` can be used to specify a replica count when
    fetching
* The `rad patch` command no longer has a `--fetch` option
* It's now possible to tell the node not to automatically connect to
  peers in the background
* `AddressBook` is being used underneath `Seeds` to allow for shuffled
  iteration
2023-08-11 11:45:27 +02:00
cloudhead efb8de2728
Rename our custom `HashMap` to `RandomMap`
This makes it easier to distinguish with the stdlib.

Also, we add an env var that can control the RNG seed, for testing
purposes.
2023-08-10 16:51:02 +02:00
cloudhead fae518bca2
node: Improve `rad node connect` feedback
Only return once the connection is established or failed.

It's still not perfect, as several failure scenarios are not handled,
but it's an improvement.
2023-08-09 12:49:15 +02:00
cloudhead e888398519
node: Populate address book with bootstrap nodes
As a starting point, we populate the address book (if empty) with some
bootstrap nodes which are trusted.

To prevent these nodes being connected to during tests (including e2e
tests), we create a new constructor for `Config` that is used in tests.

Note that a `cfg(test)` check is not enough given that e2e tests don't
have that set.
2023-08-09 12:39:33 +02:00
Alexis Sellier 3bd5589b1a
cob: Stabilize formats
> I'm going to be making a set of breaking changes to COBs in order to
stabilize the data formats. This is hopefully a one-time change that
bundles various breaking changes.

All COBs have been reworked: issue, patch, id.

The changes included are:

* Revise the assign and tag actions to take a single list of
  assignees/tags to set, instead of an "add" and a "remove" list. This
  makes API usage simpler when editing issues, and simplifies the apply
  function
* Rename "tags" to "labels", and the tag action to label. This is
  because tag is confusing in the context of git, as it could mean a git
  tag. Using label removes that confusion.
* Use DIDs instead of PublicKeys for assignees -- this is more
  future-proof
* Modify the manifest file format in the COB tree. Mainly, remove the
  `history_type` key which is redundant, and use camelCase for keys
* Flatten the `Thread` actions into the parent action type
* Ensure that operations on redacted objects do not fail, since
  redactions could have happened concurrently
* Use a consistent naming scheme for actions, using `.` as separator
* Consolidate comment types and remove `CodeComment`, by adding an
  optional `location` field to `Comment`
* Add many placeholder actions that are not yet implemented

To preserve backwards compatibility, a `legacy` module is created with
the old `apply` function. When loading the manifest, we check whether it
is a legacy COB or a "stable" COB, and in the legacy case, use the
legacy code to materialize the state and then convert the object into
the stable type. Eventually, we'll delete the legacy code.
2023-08-07 11:05:14 +02:00
cloudhead 3898fece08
cli: `git pull` to update patches in working copy
We enable users to pull updates to a patch by calling `git pull`
on the patch branch.
2023-08-04 12:28:22 +02:00
cloudhead 2d79eecd66
cli-test: Update framework with new features
* Ability to switch between environments within the same test file
* Ability to expand env vars in `cd` command
2023-08-04 12:23:49 +02:00
Alexis Sellier 2ea9a911af
remote-helper: Handle patch update after merge
If you accidently merge updated patch code before updating the patch in
storage, you end up in this weird state where you can't update the patch
any longer. This fixes it.
2023-08-03 18:01:04 +02:00
Alexis Sellier 8a3133e137
node: Include addresses in `Command::Seeds` result
This will allow the CLI to connect to seeds on the go.

We also do some refactoring of some of the code involved in fulfilling
the `Seeds` command.
2023-08-01 15:48:44 +02:00
Sebastian Martinez 3366535c9d
rad: Disable tests that use `sed` on macos
Due to differences between how BSD sed and GNU sed work, we disable for
now tests that use sed on macos

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
2023-07-26 13:23:15 +02:00