From f238fc8c0a122487f4fb71bb78a2e365e147d747 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 5 Aug 2024 14:15:29 +0100 Subject: feat(remote): `push` handle out-of-sync servers 1. don't attempt to push to a remote which is already up-to-date 2. don't attempt to delete branch on remote if it is already deleted 3. only push when out of sync if remote tip is ancestor of pushed commit 4. force push to remote if user force pushed and remote is in sync with nostr --- src/git.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/git.rs') diff --git a/src/git.rs b/src/git.rs index eaea512..0794788 100644 --- a/src/git.rs +++ b/src/git.rs @@ -39,6 +39,7 @@ pub trait RepoActions { fn get_main_or_master_branch(&self) -> Result<(&str, Sha1Hash)>; fn get_checked_out_branch_name(&self) -> Result; fn get_tip_of_branch(&self, branch_name: &str) -> Result; + fn get_commit_or_tip_of_reference(&self, reference: &str) -> Result; fn get_root_commit(&self) -> Result; fn does_commit_exist(&self, commit: &str) -> Result; fn get_head_commit(&self) -> Result; @@ -215,6 +216,21 @@ impl RepoActions for Repo { Ok(oid_to_sha1(&branch.into_reference().peel_to_commit()?.id())) } + fn get_commit_or_tip_of_reference(&self, sha1_or_reference: &str) -> Result { + let oid = { + if let Ok(oid) = Oid::from_str(sha1_or_reference) { + self.git_repo.find_commit(oid)?; + oid + } else { + self.git_repo + .find_reference(sha1_or_reference)? + .peel_to_commit()? + .id() + } + }; + Ok(oid_to_sha1(&oid)) + } + fn get_root_commit(&self) -> Result { let mut revwalk = self .git_repo -- cgit v1.2.3