diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-08-05 14:15:29 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-08-05 14:15:29 +0100 |
| commit | f238fc8c0a122487f4fb71bb78a2e365e147d747 (patch) | |
| tree | 5e8760c192f62fef67189bc82dcae4eef3ce883a /src/git.rs | |
| parent | e5750b5b3dfe2c0072902c2523fdf32986aa74b8 (diff) | |
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
Diffstat (limited to 'src/git.rs')
| -rw-r--r-- | src/git.rs | 16 |
1 files changed, 16 insertions, 0 deletions
| @@ -39,6 +39,7 @@ pub trait RepoActions { | |||
| 39 | fn get_main_or_master_branch(&self) -> Result<(&str, Sha1Hash)>; | 39 | fn get_main_or_master_branch(&self) -> Result<(&str, Sha1Hash)>; |
| 40 | fn get_checked_out_branch_name(&self) -> Result<String>; | 40 | fn get_checked_out_branch_name(&self) -> Result<String>; |
| 41 | fn get_tip_of_branch(&self, branch_name: &str) -> Result<Sha1Hash>; | 41 | fn get_tip_of_branch(&self, branch_name: &str) -> Result<Sha1Hash>; |
| 42 | fn get_commit_or_tip_of_reference(&self, reference: &str) -> Result<Sha1Hash>; | ||
| 42 | fn get_root_commit(&self) -> Result<Sha1Hash>; | 43 | fn get_root_commit(&self) -> Result<Sha1Hash>; |
| 43 | fn does_commit_exist(&self, commit: &str) -> Result<bool>; | 44 | fn does_commit_exist(&self, commit: &str) -> Result<bool>; |
| 44 | fn get_head_commit(&self) -> Result<Sha1Hash>; | 45 | fn get_head_commit(&self) -> Result<Sha1Hash>; |
| @@ -215,6 +216,21 @@ impl RepoActions for Repo { | |||
| 215 | Ok(oid_to_sha1(&branch.into_reference().peel_to_commit()?.id())) | 216 | Ok(oid_to_sha1(&branch.into_reference().peel_to_commit()?.id())) |
| 216 | } | 217 | } |
| 217 | 218 | ||
| 219 | fn get_commit_or_tip_of_reference(&self, sha1_or_reference: &str) -> Result<Sha1Hash> { | ||
| 220 | let oid = { | ||
| 221 | if let Ok(oid) = Oid::from_str(sha1_or_reference) { | ||
| 222 | self.git_repo.find_commit(oid)?; | ||
| 223 | oid | ||
| 224 | } else { | ||
| 225 | self.git_repo | ||
| 226 | .find_reference(sha1_or_reference)? | ||
| 227 | .peel_to_commit()? | ||
| 228 | .id() | ||
| 229 | } | ||
| 230 | }; | ||
| 231 | Ok(oid_to_sha1(&oid)) | ||
| 232 | } | ||
| 233 | |||
| 218 | fn get_root_commit(&self) -> Result<Sha1Hash> { | 234 | fn get_root_commit(&self) -> Result<Sha1Hash> { |
| 219 | let mut revwalk = self | 235 | let mut revwalk = self |
| 220 | .git_repo | 236 | .git_repo |