diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-22 14:56:13 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-22 14:56:33 +0000 |
| commit | 350c70bf1569815534d028eafa810b34d04f1f3d (patch) | |
| tree | 17ba54ac197f6ba1d2900f4cfb86a571da29a68c /src | |
| parent | e11ddc792864f9f0f84887701d919b6c8dc32fe0 (diff) | |
fix(pull): local rebase detected as ammendments
also updated copy and code comments
Diffstat (limited to 'src')
| -rw-r--r-- | src/git.rs | 13 | ||||
| -rw-r--r-- | src/sub_commands/pull.rs | 86 |
2 files changed, 60 insertions, 39 deletions
| @@ -68,6 +68,7 @@ pub trait RepoActions { | |||
| 68 | patch_and_ancestors: Vec<nostr::Event>, | 68 | patch_and_ancestors: Vec<nostr::Event>, |
| 69 | ) -> Result<Vec<nostr::Event>>; | 69 | ) -> Result<Vec<nostr::Event>>; |
| 70 | fn parse_starting_commits(&self, starting_commits: &str) -> Result<Vec<Sha1Hash>>; | 70 | fn parse_starting_commits(&self, starting_commits: &str) -> Result<Vec<Sha1Hash>>; |
| 71 | fn ancestor_of(&self, decendant: &Sha1Hash, ancestor: &Sha1Hash) -> Result<bool>; | ||
| 71 | } | 72 | } |
| 72 | 73 | ||
| 73 | impl RepoActions for Repo { | 74 | impl RepoActions for Repo { |
| @@ -461,6 +462,18 @@ impl RepoActions for Repo { | |||
| 461 | bail!("specified value not in a supported format") | 462 | bail!("specified value not in a supported format") |
| 462 | } | 463 | } |
| 463 | } | 464 | } |
| 465 | |||
| 466 | fn ancestor_of(&self, decendant: &Sha1Hash, ancestor: &Sha1Hash) -> Result<bool> { | ||
| 467 | if let Ok(res) = self | ||
| 468 | .git_repo | ||
| 469 | .graph_descendant_of(sha1_to_oid(decendant)?, sha1_to_oid(ancestor)?) | ||
| 470 | .context("could not run graph_descendant_of in gitlib2") | ||
| 471 | { | ||
| 472 | Ok(res) | ||
| 473 | } else { | ||
| 474 | Ok(false) | ||
| 475 | } | ||
| 476 | } | ||
| 464 | } | 477 | } |
| 465 | 478 | ||
| 466 | fn oid_to_u8_20_bytes(oid: &Oid) -> [u8; 20] { | 479 | fn oid_to_u8_20_bytes(oid: &Oid) -> [u8; 20] { |
diff --git a/src/sub_commands/pull.rs b/src/sub_commands/pull.rs index d832f6e..1e60a90 100644 --- a/src/sub_commands/pull.rs +++ b/src/sub_commands/pull.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | use anyhow::{bail, Context, Result}; | 1 | use anyhow::{anyhow, bail, Context, Result}; |
| 2 | 2 | ||
| 3 | use super::list::{get_commit_id_from_patch, tag_value}; | 3 | use super::list::{get_commit_id_from_patch, tag_value}; |
| 4 | #[cfg(not(test))] | 4 | #[cfg(not(test))] |
| @@ -110,8 +110,7 @@ pub async fn launch() -> Result<()> { | |||
| 110 | println!("your '{main_branch_name}' branch may not be up-to-date."); | 110 | println!("your '{main_branch_name}' branch may not be up-to-date."); |
| 111 | println!("manually run `git pull` on '{main_branch_name}' and try again"); | 111 | println!("manually run `git pull` on '{main_branch_name}' and try again"); |
| 112 | } | 112 | } |
| 113 | // if tip of local in proposal history (new, ammended or rebased version but no | 113 | // if new revision and no local changes (tip of local in proposal history) |
| 114 | // local changes) | ||
| 115 | else if commit_events.iter().any(|patch| { | 114 | else if commit_events.iter().any(|patch| { |
| 116 | get_commit_id_from_patch(patch) | 115 | get_commit_id_from_patch(patch) |
| 117 | .unwrap_or_default() | 116 | .unwrap_or_default() |
| @@ -134,51 +133,60 @@ pub async fn launch() -> Result<()> { | |||
| 134 | } | 133 | } |
| 135 | // if tip of proposal in branch in history (local appendments made to up-to-date | 134 | // if tip of proposal in branch in history (local appendments made to up-to-date |
| 136 | // proposal) | 135 | // proposal) |
| 137 | else if let Ok((local_ahead_of_proposal, _)) = | 136 | else if git_repo.ancestor_of(&local_branch_tip, &proposal_tip)? { |
| 138 | git_repo.get_commits_ahead_behind(&proposal_tip, &local_branch_tip) | 137 | let (local_ahead_of_proposal, _) = git_repo |
| 139 | { | 138 | .get_commits_ahead_behind(&proposal_tip, &local_branch_tip) |
| 139 | .context("cannot get commits ahead behind for propsal_top and local_branch_tip")?; | ||
| 140 | println!( | 140 | println!( |
| 141 | "local proposal branch exists with {} unpublished commits on top of the most up-to-date version of the proposal", | 141 | "local proposal branch exists with {} unpublished commits on top of the most up-to-date version of the proposal", |
| 142 | local_ahead_of_proposal.len() | 142 | local_ahead_of_proposal.len() |
| 143 | ); | 143 | ); |
| 144 | } | 144 | } else { |
| 145 | // user has probably has an unpublished rebase of the latest proposal version | 145 | println!("you have an ammended/rebase version the proposal that is unpublished"); |
| 146 | // if tip of proposal commits exist (were once part of branch but have been | 146 | // user probably has a unpublished ammended or rebase version of the latest |
| 147 | // ammended and git clean up job hasn't removed them) | 147 | // proposal version |
| 148 | else if git_repo.does_commit_exist(&proposal_tip.to_string())? { | 148 | // if tip of proposal commits exist (were once part of branch but have been |
| 149 | println!( | 149 | // ammended and git clean up job hasn't removed them) |
| 150 | "you have previously applied the latest version of the proposal ({} ahead {} behind '{main_branch_name}') but your local proposal branch has other unpublished changes ({} ahead {} behind '{main_branch_name}')", | 150 | if git_repo.does_commit_exist(&proposal_tip.to_string())? { |
| 151 | most_recent_proposal_patch_chain.len(), | 151 | println!( |
| 152 | proposal_behind_main.len(), | 152 | "you have previously applied the latest version of the proposal ({} ahead {} behind '{main_branch_name}') but your local proposal branch has ammended or rebased it ({} ahead {} behind '{main_branch_name}')", |
| 153 | local_ahead_of_main.len(), | 153 | most_recent_proposal_patch_chain.len(), |
| 154 | local_beind_main.len(), | 154 | proposal_behind_main.len(), |
| 155 | ); | 155 | local_ahead_of_main.len(), |
| 156 | println!( | 156 | local_beind_main.len(), |
| 157 | "if this sounds right then consider publishing your rebase `ngit push --force` or discarding your local branch" | 157 | ); |
| 158 | ); | 158 | } |
| 159 | } | 159 | // user probably has a unpublished ammended or rebase version of an older |
| 160 | // user has probaly has an unpublished rebase of an older version of the | 160 | // proposal version |
| 161 | // proposal | 161 | else { |
| 162 | else { | 162 | println!( |
| 163 | println!( | 163 | "your local proposal branch ({} ahead {} behind '{main_branch_name}') has conflicting changes with the latest published proposal ({} ahead {} behind '{main_branch_name}')", |
| 164 | "your local proposal branch ({} ahead {} behind '{main_branch_name}') has conflicting changes with the latest published proposal ({} ahead {} behind '{main_branch_name}')", | 164 | local_ahead_of_main.len(), |
| 165 | local_ahead_of_main.len(), | 165 | local_beind_main.len(), |
| 166 | local_beind_main.len(), | 166 | most_recent_proposal_patch_chain.len(), |
| 167 | most_recent_proposal_patch_chain.len(), | 167 | proposal_behind_main.len(), |
| 168 | proposal_behind_main.len(), | 168 | ); |
| 169 | ); | 169 | |
| 170 | println!( | 170 | println!( |
| 171 | "its likely that you are working off an old proposal version because git has no record of the latest proposal commit." | 171 | "its likely that you have rebased / ammended an old proposal version because git has no record of the latest proposal commit." |
| 172 | ); | 172 | ); |
| 173 | println!( | 173 | println!( |
| 174 | "it is possible that you have ammended the latest version and git has delete this commit as part of a clean up" | 174 | "it is possible that you have been working off the latest version and git has delete this commit as part of a clean up" |
| 175 | ); | 175 | ); |
| 176 | 176 | } | |
| 177 | println!("to view the latest proposal but retain your changes:"); | 177 | println!("to view the latest proposal but retain your changes:"); |
| 178 | println!(" 1) create a new branch off the tip commit of this one to store your changes"); | 178 | println!(" 1) create a new branch off the tip commit of this one to store your changes"); |
| 179 | println!(" 2) run `ngit list` and checkout the latest published version of this proposal"); | 179 | println!(" 2) run `ngit list` and checkout the latest published version of this proposal"); |
| 180 | 180 | ||
| 181 | println!("if you are confident in your changes consider running `ngit push --force`"); | 181 | println!("if you are confident in your changes consider running `ngit push --force`"); |
| 182 | |||
| 183 | // TODO: this copy could be refined further based on this: | ||
| 184 | // - amended commits in the proposal | ||
| 185 | // - if local_base eq proposal base | ||
| 186 | // - ammended an older version of proposal | ||
| 187 | // - if local_base is behind proposal_base | ||
| 188 | // - rebased the proposal | ||
| 189 | // - if local_base is ahead of proposal_base | ||
| 182 | } | 190 | } |
| 183 | Ok(()) | 191 | Ok(()) |
| 184 | } | 192 | } |