A tip that moved backwards onto an already-interpreted commit (`git reset --hard HEAD~1`, a rebase dropping the newest commit, a force-pull to an ancestor) plans no commits, so the per-commit supersede gate never ran: the view kept the dropped history, every later command refused with `HeadChanged`, and `shim status` called the mapping synchronized. Apply the same gate against the tip: view member
(
&self,
repo: &mut Repository,
branch_name: &str,
)
| 4759 | /// members whose Git origin lies outside the tip's ancestry and |
| 4760 | /// interpreted closure leave the view, dependents included. |
| 4761 | fn rewind_view_to_interpreted_tip( |
| 4762 | &self, |
| 4763 | repo: &mut Repository, |
| 4764 | branch_name: &str, |
| 4765 | ) -> CliResult<usize> { |
| 4766 | let Ok(git) = self.open_git_repo() else { |
| 4767 | return Ok(0); |
| 4768 | }; |
| 4769 | let Some(tip) = git |
| 4770 | .find_branch(branch_name, git2::BranchType::Local) |
| 4771 | .ok() |
| 4772 | .and_then(|branch| branch.get().target()) |
| 4773 | else { |
| 4774 | return Ok(0); |
| 4775 | }; |
| 4776 | let tip_sha = tip.to_string(); |
| 4777 | let view = self.options.target_view.clone(); |
| 4778 | let Some(tip_hash) = repo |
| 4779 | .checked_git_sha(&tip_sha) |
| 4780 | .map_err(|e| CliError::Internal(e.into()))? |
| 4781 | else { |
| 4782 | return Ok(0); |
| 4783 | }; |
| 4784 | let is_member = |repo: &Repository, hash: &ContentHash| -> CliResult<bool> { |
| 4785 | Ok(repo |
| 4786 | .effective_history(Some(&view)) |
| 4787 | .map_err(|e| CliError::Internal(e.into()))? |
| 4788 | .iter() |
| 4789 | .any(|entry| entry.hash == *hash)) |
| 4790 | }; |
| 4791 | if !is_member(repo, &tip_hash)? { |
| 4792 | return Ok(0); |
| 4793 | } |
| 4794 | let mut ledger = ClosureLedger::default(); |
| 4795 | let ancestry = ledger.ancestry_of(&git, &tip_sha)?; |
| 4796 | ledger.target_closure = Some(ancestry); |
| 4797 | let superseded = ledger.supersede_exclusions_for(repo, &git, &tip_sha, &view, true)?; |
| 4798 | let mut removed = 0usize; |
| 4799 | for hash in superseded { |
| 4800 | if !is_member(repo, &hash)? { |
| 4801 | continue; |
| 4802 | } |
| 4803 | let outcome = repo |
| 4804 | .unrecord( |
| 4805 | &hash, |
| 4806 | atomic_repository::unrecord::UnrecordOptions { |
| 4807 | view: Some(view.clone()), |
| 4808 | cascade: true, |
| 4809 | update_working_copy: false, |
| 4810 | ..Default::default() |
| 4811 | }, |
| 4812 | ) |
| 4813 | .map_err(|e| CliError::Internal(e.into()))?; |
| 4814 | trace_git_import(format!( |
| 4815 | "rewind '{branch_name}': unrecorded {} change(s) behind {}", |
| 4816 | outcome.unrecorded.len(), |
| 4817 | hash.to_base32() |
| 4818 | )); |
no test coverage detected