diff options
Diffstat (limited to 'src/bin/ngit/sub_commands')
| -rw-r--r-- | src/bin/ngit/sub_commands/init.rs | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 238ae29..2f34ecb 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs | |||
| @@ -531,6 +531,8 @@ fn validate_pre_fetch( | |||
| 531 | args: &SubCommandArgs, | 531 | args: &SubCommandArgs, |
| 532 | repo_coordinate: Option<&Nip19Coordinate>, | 532 | repo_coordinate: Option<&Nip19Coordinate>, |
| 533 | user_has_grasp_list: bool, | 533 | user_has_grasp_list: bool, |
| 534 | cached_repo_ref: Option<&RepoRef>, | ||
| 535 | my_pubkey: &PublicKey, | ||
| 534 | ) -> Result<()> { | 536 | ) -> Result<()> { |
| 535 | // Interactive mode bypasses pre-fetch validation | 537 | // Interactive mode bypasses pre-fetch validation |
| 536 | if cli.interactive { | 538 | if cli.interactive { |
| @@ -542,7 +544,30 @@ fn validate_pre_fetch( | |||
| 542 | return validate_fresh(cli, args, user_has_grasp_list); | 544 | return validate_fresh(cli, args, user_has_grasp_list); |
| 543 | } | 545 | } |
| 544 | 546 | ||
| 545 | // Coordinate exists - we need to fetch before we can validate further | 547 | // If we have cached data and it's MyAnnouncement state, validate early |
| 548 | if let (Some(coord), Some(repo_ref)) = (repo_coordinate, cached_repo_ref) { | ||
| 549 | if coord.coordinate.public_key == *my_pubkey { | ||
| 550 | // MyAnnouncement state - validate before network fetch | ||
| 551 | if let Some(new_id) = &args.identifier { | ||
| 552 | if *new_id != repo_ref.identifier && !cli.force { | ||
| 553 | let suggestion = format!("ngit init --identifier {new_id} --force"); | ||
| 554 | return Err(cli_error( | ||
| 555 | "changing identifier creates a new repository", | ||
| 556 | &[], | ||
| 557 | &[&suggestion], | ||
| 558 | )); | ||
| 559 | } | ||
| 560 | } | ||
| 561 | if !args.has_substantive_flags() && !cli.force { | ||
| 562 | return Err(cli_error( | ||
| 563 | "no arguments specified, use --force to publish with new timestamp", | ||
| 564 | &[], | ||
| 565 | &["ngit init --force"], | ||
| 566 | )); | ||
| 567 | } | ||
| 568 | } | ||
| 569 | } | ||
| 570 | |||
| 546 | Ok(()) | 571 | Ok(()) |
| 547 | } | 572 | } |
| 548 | 573 | ||
| @@ -1479,16 +1504,25 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 1479 | 1504 | ||
| 1480 | let repo_coordinate = (try_and_get_repo_coordinates_when_remote_unknown(&git_repo).await).ok(); | 1505 | let repo_coordinate = (try_and_get_repo_coordinates_when_remote_unknown(&git_repo).await).ok(); |
| 1481 | 1506 | ||
| 1482 | // Phase 2: Pre-fetch validation (fail fast) | 1507 | // Phase 2: Try to get cached repo_ref for early validation |
| 1508 | let cached_repo_ref = if let Some(coord) = &repo_coordinate { | ||
| 1509 | (get_repo_ref_from_cache(Some(git_repo_path), coord).await).ok() | ||
| 1510 | } else { | ||
| 1511 | None | ||
| 1512 | }; | ||
| 1513 | |||
| 1514 | // Phase 3: Pre-fetch validation (fail fast) | ||
| 1483 | let user_has_grasp_list = !user_ref.grasp_list.urls.is_empty(); | 1515 | let user_has_grasp_list = !user_ref.grasp_list.urls.is_empty(); |
| 1484 | validate_pre_fetch( | 1516 | validate_pre_fetch( |
| 1485 | cli_args, | 1517 | cli_args, |
| 1486 | args, | 1518 | args, |
| 1487 | repo_coordinate.as_ref(), | 1519 | repo_coordinate.as_ref(), |
| 1488 | user_has_grasp_list, | 1520 | user_has_grasp_list, |
| 1521 | cached_repo_ref.as_ref(), | ||
| 1522 | &user_ref.public_key, | ||
| 1489 | )?; | 1523 | )?; |
| 1490 | 1524 | ||
| 1491 | // Phase 3: Network fetch (only if coordinate exists) | 1525 | // Phase 4: Network fetch (only if coordinate exists) |
| 1492 | let repo_ref = if let Some(repo_coordinate) = &repo_coordinate { | 1526 | let repo_ref = if let Some(repo_coordinate) = &repo_coordinate { |
| 1493 | fetching_with_report(git_repo_path, &client, repo_coordinate).await?; | 1527 | fetching_with_report(git_repo_path, &client, repo_coordinate).await?; |
| 1494 | (get_repo_ref_from_cache(Some(git_repo_path), repo_coordinate).await).ok() | 1528 | (get_repo_ref_from_cache(Some(git_repo_path), repo_coordinate).await).ok() |