Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: Handle non-symbolic existing ref in set_symbolic_ref
Fintan Halpenny committed 22 days ago
commit 5f8bb171656910d488c9455b751681f322c45a30
parent e6365455e3fae9eddd2b3942efc523363af9ce09
1 file changed +14 -7
modified crates/radicle/src/storage/git.rs
@@ -943,14 +943,21 @@ impl WriteRepository for Repository {
        message: &str,
    ) -> Result<(), RepositoryError> {
        match self.raw().find_reference(name.as_str()) {
-
            Ok(mut head_ref) => {
-
                if head_ref
-
                    .symbolic_target()
-
                    .is_some_and(|t| t != target.as_str())
-
                {
-
                    head_ref.symbolic_set_target(target.as_str(), message)?;
+
            Ok(mut existing) => match existing.symbolic_target() {
+
                Some(current) if current == target.as_str() => {
+
                    // Already points to the correct target, nothing to do.
                }
-
            }
+
                Some(_) => {
+
                    // Symbolic ref pointing to a different target, update it.
+
                    existing.symbolic_set_target(target.as_str(), message)?;
+
                }
+
                None => {
+
                    // A direct (non-symbolic) ref exists where we expect a
+
                    // symbolic one. Overwrite it with force.
+
                    self.raw()
+
                        .reference_symbolic(name.as_str(), target.as_str(), true, message)?;
+
                }
+
            },
            Err(err) if err.is_not_found() => {
                self.raw()
                    .reference_symbolic(name.as_str(), target.as_str(), true, message)?;