diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-18 22:00:35 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-18 22:00:35 +0000 |
| commit | 56b3c149df70af5d441e8527ec1225e5038bde8e (patch) | |
| tree | a73be853773a342158cb8032571502afdf369374 /src/bin/ngit/sub_commands/checkout.rs | |
| parent | 09db17fd719ddd42c5afad24e1a8e71735374f8e (diff) | |
fix: remove outdated patch_supports gate and fix fetch parent fallback
Remove the patch_supports_commit_ids gates in checkout.rs and list.rs
that pre-dated the mbox fallback logic. apply_patch_chain already
handles all fallback cases. Also replace the main-branch TODO fallback
in make_commits_for_proposal with get_parent_commit_from_patch, which
uses timestamp-based best-guess when the parent-commit tag is absent.
Diffstat (limited to 'src/bin/ngit/sub_commands/checkout.rs')
| -rw-r--r-- | src/bin/ngit/sub_commands/checkout.rs | 61 |
1 files changed, 19 insertions, 42 deletions
diff --git a/src/bin/ngit/sub_commands/checkout.rs b/src/bin/ngit/sub_commands/checkout.rs index 87f1ff2..67447ae 100644 --- a/src/bin/ngit/sub_commands/checkout.rs +++ b/src/bin/ngit/sub_commands/checkout.rs | |||
| @@ -24,7 +24,7 @@ use nostr_sdk::{EventId, FromBech32}; | |||
| 24 | use crate::{ | 24 | use crate::{ |
| 25 | client::{Client, Connect, fetching_with_report, get_repo_ref_from_cache}, | 25 | client::{Client, Connect, fetching_with_report, get_repo_ref_from_cache}, |
| 26 | git::{Repo, RepoActions, str_to_sha1}, | 26 | git::{Repo, RepoActions, str_to_sha1}, |
| 27 | git_events::{event_to_cover_letter, get_parent_commit_from_patch, patch_supports_commit_ids}, | 27 | git_events::event_to_cover_letter, |
| 28 | repo_ref::get_repo_coordinates_when_remote_unknown, | 28 | repo_ref::get_repo_coordinates_when_remote_unknown, |
| 29 | }; | 29 | }; |
| 30 | 30 | ||
| @@ -261,32 +261,7 @@ fn checkout_patch( | |||
| 261 | most_recent_proposal_patch_chain_or_pr_or_pr_update: &[nostr::Event], | 261 | most_recent_proposal_patch_chain_or_pr_or_pr_update: &[nostr::Event], |
| 262 | nostr_remote_name: Option<&str>, | 262 | nostr_remote_name: Option<&str>, |
| 263 | ) -> Result<()> { | 263 | ) -> Result<()> { |
| 264 | let no_support_for_patches_as_branch = most_recent_proposal_patch_chain_or_pr_or_pr_update | 264 | let (_, _master_tip) = git_repo.get_main_or_master_branch()?; |
| 265 | .iter() | ||
| 266 | .any(|event| !patch_supports_commit_ids(event)); | ||
| 267 | |||
| 268 | if no_support_for_patches_as_branch { | ||
| 269 | bail!( | ||
| 270 | "this proposal cannot be checked out as a branch because some patches do not have a parent commit.\n\ | ||
| 271 | Try `ngit apply --stdout` to apply patches to the current branch, or use `ngit list` for interactive options." | ||
| 272 | ); | ||
| 273 | } | ||
| 274 | |||
| 275 | let last_patch = most_recent_proposal_patch_chain_or_pr_or_pr_update | ||
| 276 | .last() | ||
| 277 | .context("there should be at least one patch")?; | ||
| 278 | |||
| 279 | let proposal_base_commit = str_to_sha1(&get_parent_commit_from_patch(last_patch, Some(git_repo))?) | ||
| 280 | .context("failed to get valid parent commit id from patch")?; | ||
| 281 | |||
| 282 | let (main_branch_name, _master_tip) = git_repo.get_main_or_master_branch()?; | ||
| 283 | |||
| 284 | if !git_repo.does_commit_exist(&proposal_base_commit.to_string())? { | ||
| 285 | bail!( | ||
| 286 | "the proposal parent commit doesn't exist in your local repository.\n\ | ||
| 287 | Try running `git pull` on '{main_branch_name}' first, or use `ngit apply --stdout` to apply patches to the current branch." | ||
| 288 | ); | ||
| 289 | } | ||
| 290 | 265 | ||
| 291 | if git_repo.has_outstanding_changes()? { | 266 | if git_repo.has_outstanding_changes()? { |
| 292 | bail!("working directory is not clean. Discard or stash (un)staged changes and try again."); | 267 | bail!("working directory is not clean. Discard or stash (un)staged changes and try again."); |
| @@ -322,23 +297,25 @@ fn checkout_patch( | |||
| 322 | 297 | ||
| 323 | let local_branch_tip = git_repo.get_tip_of_branch(&branch_name)?; | 298 | let local_branch_tip = git_repo.get_tip_of_branch(&branch_name)?; |
| 324 | 299 | ||
| 325 | let proposal_tip = str_to_sha1( | 300 | // If we can reliably determine the proposal tip commit, use it to skip |
| 326 | &get_commit_id_from_patch( | 301 | // re-applying when already up-to-date. If the commit tag is absent or |
| 327 | most_recent_proposal_patch_chain_or_pr_or_pr_update | 302 | // unreliable, skip this check and let apply_patch_chain handle idempotency. |
| 328 | .first() | 303 | if let Ok(proposal_tip_str) = get_commit_id_from_patch( |
| 329 | .context("there should be at least one patch")?, | 304 | most_recent_proposal_patch_chain_or_pr_or_pr_update |
| 330 | ) | 305 | .first() |
| 331 | .context("failed to get valid commit_id from patch")?, | 306 | .context("there should be at least one patch")?, |
| 332 | ) | 307 | ) { |
| 333 | .context("failed to get valid commit_id from patch")?; | 308 | if let Ok(proposal_tip) = str_to_sha1(&proposal_tip_str) { |
| 334 | 309 | if proposal_tip.eq(&local_branch_tip) { | |
| 335 | if proposal_tip.eq(&local_branch_tip) { | 310 | git_repo.checkout(&branch_name)?; |
| 336 | git_repo.checkout(&branch_name)?; | 311 | println!("branch '{branch_name}' checked out and up-to-date"); |
| 337 | println!("branch '{branch_name}' checked out and up-to-date"); | 312 | return Ok(()); |
| 338 | return Ok(()); | 313 | } |
| 314 | } | ||
| 339 | } | 315 | } |
| 340 | 316 | ||
| 341 | git_repo.create_branch_at_commit(&branch_name, &proposal_base_commit.to_string())?; | 317 | // Branch exists but may need updating — re-apply the chain. |
| 318 | // apply_patch_chain handles already-applied commits idempotently. | ||
| 342 | git_repo.checkout(&branch_name)?; | 319 | git_repo.checkout(&branch_name)?; |
| 343 | let _ = git_repo | 320 | let _ = git_repo |
| 344 | .apply_patch_chain( | 321 | .apply_patch_chain( |