Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Don't allow the default branch to be deleted
Browse files Browse the repository at this point in the history
As a delegate, you shouldn't be able to delete your default branch.
This would most likely happen by mistake, and it prevents the canonical
head from being calculated correctly.
  • Loading branch information
cloudhead committed Sep 27, 2023
1 parent c0271c3 commit 7e32f91
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions radicle-cli/examples/git/git-push.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,11 @@ f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 refs/heads/master
$ rad sync --announce
✓ Synced with 1 node(s)
```

Note that it is forbidden to delete the default/canonical branch:

``` (fail) (stderr)
$ git push rad :master
error: refusing to delete default branch ref 'refs/heads/master'
error: failed to push some refs to 'rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi'
```
8 changes: 8 additions & 0 deletions radicle-remote-helper/src/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ pub enum Error {
/// Head being pushed diverges from canonical head.
#[error("refusing to update branch to commit that is not a descendant of canonical head")]
HeadsDiverge(git::Oid, git::Oid),
/// User tried to delete the canonical branch.
#[error("refusing to delete default branch ref '{0}'")]
DeleteForbidden(git::RefString),
/// Identity document error.
#[error("doc: {0}")]
Doc(#[from] radicle::identity::doc::DocError),
Expand Down Expand Up @@ -184,6 +187,11 @@ pub fn run(
Command::Delete(dst) => {
// Delete refs.
let refname = nid.to_namespace().join(dst);
let (canonical_ref, _) = &canonical;

if *dst == canonical_ref.to_ref_string() && delegates.contains(&Did::from(nid)) {
return Err(Error::DeleteForbidden(dst.clone()));
}
stored
.raw()
.find_reference(&refname)
Expand Down

0 comments on commit 7e32f91

Please sign in to comment.