diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-11-26 07:48:30 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-11-26 12:26:47 +0000 |
| commit | a0593e3aa9b19b9ca3c3881cbe0d9d207fe46d2c (patch) | |
| tree | 3482e7c558eff09cc91604ad6ddcd02cf2c94699 /src | |
| parent | 1332c625b75fce616e06b415c99a068bc45c8210 (diff) | |
refactor: err msgs 'cannot' > 'failed to'
in nearly all cases 'cannot' was used when an action was tried and
failed. 'failed to' is strictly better because:
* just because the action didn't work that time doesnt mean it
cannot work
* it is better at drawing the users attention to a problem
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/git_remote_nostr/fetch.rs | 4 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/list.rs | 2 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 16 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/fetch.rs | 2 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/init.rs | 2 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/list.rs | 26 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/login.rs | 2 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/pull.rs | 22 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/push.rs | 10 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/send.rs | 4 | ||||
| -rw-r--r-- | src/lib/client.rs | 22 | ||||
| -rw-r--r-- | src/lib/git/identify_ahead_behind.rs | 8 | ||||
| -rw-r--r-- | src/lib/git/mod.rs | 73 | ||||
| -rw-r--r-- | src/lib/git/nostr_url.rs | 2 | ||||
| -rw-r--r-- | src/lib/git_events.rs | 4 | ||||
| -rw-r--r-- | src/lib/login/existing.rs | 8 | ||||
| -rw-r--r-- | src/lib/login/fresh.rs | 2 | ||||
| -rw-r--r-- | src/lib/login/mod.rs | 6 | ||||
| -rw-r--r-- | src/lib/repo_ref.rs | 15 |
19 files changed, 123 insertions, 107 deletions
diff --git a/src/bin/git_remote_nostr/fetch.rs b/src/bin/git_remote_nostr/fetch.rs index a972a2f..90387f3 100644 --- a/src/bin/git_remote_nostr/fetch.rs +++ b/src/bin/git_remote_nostr/fetch.rs | |||
| @@ -110,7 +110,7 @@ pub fn make_commits_for_proposal( | |||
| 110 | let commit_id = git_repo | 110 | let commit_id = git_repo |
| 111 | .create_commit_from_patch(patch, Some(tip_commit_id.clone())) | 111 | .create_commit_from_patch(patch, Some(tip_commit_id.clone())) |
| 112 | .context(format!( | 112 | .context(format!( |
| 113 | "cannot create commit for patch {}", | 113 | "failed to create commit for patch {}", |
| 114 | nip19::Nip19Event { | 114 | nip19::Nip19Event { |
| 115 | event_id: patch.id, | 115 | event_id: patch.id, |
| 116 | author: Some(patch.pubkey), | 116 | author: Some(patch.pubkey), |
| @@ -146,7 +146,7 @@ async fn fetch_proposals( | |||
| 146 | { | 146 | { |
| 147 | if let Err(error) = make_commits_for_proposal(git_repo, repo_ref, patches) { | 147 | if let Err(error) = make_commits_for_proposal(git_repo, repo_ref, patches) { |
| 148 | term.write_line( | 148 | term.write_line( |
| 149 | format!("WARNING: cannot create branch for {refstr}, error: {error}",) | 149 | format!("WARNING: failed to create branch for {refstr}, error: {error}",) |
| 150 | .as_str(), | 150 | .as_str(), |
| 151 | )?; | 151 | )?; |
| 152 | break; | 152 | break; |
diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs index daff1b6..9171544 100644 --- a/src/bin/git_remote_nostr/list.rs +++ b/src/bin/git_remote_nostr/list.rs | |||
| @@ -163,7 +163,7 @@ async fn get_open_proposals_state( | |||
| 163 | } | 163 | } |
| 164 | Err(error) => { | 164 | Err(error) => { |
| 165 | let _ = term.write_line( | 165 | let _ = term.write_line( |
| 166 | format!("WARNING: cannot fetch branch {branch_name} error: {error}") | 166 | format!("WARNING: failed to fetch branch {branch_name} error: {error}") |
| 167 | .as_str(), | 167 | .as_str(), |
| 168 | ); | 168 | ); |
| 169 | } | 169 | } |
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index 7161c5d..381a45e 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs | |||
| @@ -92,7 +92,7 @@ pub async fn run_push( | |||
| 92 | list_outputs.get(url).unwrap().to_owned() | 92 | list_outputs.get(url).unwrap().to_owned() |
| 93 | } else { | 93 | } else { |
| 94 | bail!( | 94 | bail!( |
| 95 | "cannot connect to git servers: {}", | 95 | "failed to connect to git servers: {}", |
| 96 | repo_ref.git_server.join(" ") | 96 | repo_ref.git_server.join(" ") |
| 97 | ); | 97 | ); |
| 98 | } | 98 | } |
| @@ -245,7 +245,7 @@ pub async fn run_push( | |||
| 245 | &[], | 245 | &[], |
| 246 | ) | 246 | ) |
| 247 | .await | 247 | .await |
| 248 | .context("cannot make patch event from commit")?; | 248 | .context("failed to make patch event from commit")?; |
| 249 | events.push(new_patch.clone()); | 249 | events.push(new_patch.clone()); |
| 250 | parent_patch = new_patch; | 250 | parent_patch = new_patch; |
| 251 | } | 251 | } |
| @@ -259,7 +259,7 @@ pub async fn run_push( | |||
| 259 | ) | 259 | ) |
| 260 | .unwrap(); | 260 | .unwrap(); |
| 261 | println!( | 261 | println!( |
| 262 | "error {to} cannot fastforward as newer patches found on proposal" | 262 | "error {to} failed to fastforward as newer patches found on proposal" |
| 263 | ); | 263 | ); |
| 264 | rejected_proposal_refspecs.push(refspec.to_string()); | 264 | rejected_proposal_refspecs.push(refspec.to_string()); |
| 265 | } | 265 | } |
| @@ -1089,7 +1089,7 @@ fn update_remote_refs_pushed( | |||
| 1089 | } | 1089 | } |
| 1090 | } else { | 1090 | } else { |
| 1091 | let commit = reference_to_commit(git_repo, from) | 1091 | let commit = reference_to_commit(git_repo, from) |
| 1092 | .context(format!("cannot get commit of reference {from}"))?; | 1092 | .context(format!("failed to get commit of reference {from}"))?; |
| 1093 | if let Ok(mut remote_ref) = git_repo.find_reference(&target_ref_name) { | 1093 | if let Ok(mut remote_ref) = git_repo.find_reference(&target_ref_name) { |
| 1094 | remote_ref.set_target(commit, "updated by nostr remote helper")?; | 1094 | remote_ref.set_target(commit, "updated by nostr remote helper")?; |
| 1095 | } else { | 1095 | } else { |
| @@ -1142,9 +1142,9 @@ fn refspec_remote_ref_name( | |||
| 1142 | fn reference_to_commit(git_repo: &Repository, reference: &str) -> Result<Oid> { | 1142 | fn reference_to_commit(git_repo: &Repository, reference: &str) -> Result<Oid> { |
| 1143 | Ok(git_repo | 1143 | Ok(git_repo |
| 1144 | .find_reference(reference) | 1144 | .find_reference(reference) |
| 1145 | .context(format!("cannot find reference: {reference}"))? | 1145 | .context(format!("failed to find reference: {reference}"))? |
| 1146 | .peel_to_commit() | 1146 | .peel_to_commit() |
| 1147 | .context(format!("cannot get commit from reference: {reference}"))? | 1147 | .context(format!("failed to get commit from reference: {reference}"))? |
| 1148 | .id()) | 1148 | .id()) |
| 1149 | } | 1149 | } |
| 1150 | 1150 | ||
| @@ -1152,13 +1152,13 @@ fn reference_to_commit(git_repo: &Repository, reference: &str) -> Result<Oid> { | |||
| 1152 | fn reference_to_ref_value(git_repo: &Repository, reference: &str) -> Result<String> { | 1152 | fn reference_to_ref_value(git_repo: &Repository, reference: &str) -> Result<String> { |
| 1153 | let reference_obj = git_repo | 1153 | let reference_obj = git_repo |
| 1154 | .find_reference(reference) | 1154 | .find_reference(reference) |
| 1155 | .context(format!("cannot find reference: {reference}"))?; | 1155 | .context(format!("failed to find reference: {reference}"))?; |
| 1156 | if let Some(symref) = reference_obj.symbolic_target() { | 1156 | if let Some(symref) = reference_obj.symbolic_target() { |
| 1157 | Ok(symref.to_string()) | 1157 | Ok(symref.to_string()) |
| 1158 | } else { | 1158 | } else { |
| 1159 | Ok(reference_obj | 1159 | Ok(reference_obj |
| 1160 | .peel_to_commit() | 1160 | .peel_to_commit() |
| 1161 | .context(format!("cannot get commit from reference: {reference}"))? | 1161 | .context(format!("failed to get commit from reference: {reference}"))? |
| 1162 | .id() | 1162 | .id() |
| 1163 | .to_string()) | 1163 | .to_string()) |
| 1164 | } | 1164 | } |
diff --git a/src/bin/ngit/sub_commands/fetch.rs b/src/bin/ngit/sub_commands/fetch.rs index c69f1c5..dc548fd 100644 --- a/src/bin/ngit/sub_commands/fetch.rs +++ b/src/bin/ngit/sub_commands/fetch.rs | |||
| @@ -20,7 +20,7 @@ pub struct SubCommandArgs { | |||
| 20 | 20 | ||
| 21 | pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { | 21 | pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { |
| 22 | let _ = args; | 22 | let _ = args; |
| 23 | let git_repo = Repo::discover().context("cannot find a git repository")?; | 23 | let git_repo = Repo::discover().context("failed to find a git repository")?; |
| 24 | let client = Client::default(); | 24 | let client = Client::default(); |
| 25 | let repo_coordinates = if command_args.repo.is_empty() { | 25 | let repo_coordinates = if command_args.repo.is_empty() { |
| 26 | get_repo_coordinates(&git_repo, &client).await? | 26 | get_repo_coordinates(&git_repo, &client).await? |
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 146a29c..9f5093e 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs | |||
| @@ -47,7 +47,7 @@ pub struct SubCommandArgs { | |||
| 47 | 47 | ||
| 48 | #[allow(clippy::too_many_lines)] | 48 | #[allow(clippy::too_many_lines)] |
| 49 | pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | 49 | pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { |
| 50 | let git_repo = Repo::discover().context("cannot find a git repository")?; | 50 | let git_repo = Repo::discover().context("failed to find a git repository")?; |
| 51 | let git_repo_path = git_repo.get_path()?; | 51 | let git_repo_path = git_repo.get_path()?; |
| 52 | 52 | ||
| 53 | let root_commit = git_repo | 53 | let root_commit = git_repo |
diff --git a/src/bin/ngit/sub_commands/list.rs b/src/bin/ngit/sub_commands/list.rs index 7717dce..1e8ecc4 100644 --- a/src/bin/ngit/sub_commands/list.rs +++ b/src/bin/ngit/sub_commands/list.rs | |||
| @@ -24,7 +24,7 @@ use crate::{ | |||
| 24 | 24 | ||
| 25 | #[allow(clippy::too_many_lines)] | 25 | #[allow(clippy::too_many_lines)] |
| 26 | pub async fn launch() -> Result<()> { | 26 | pub async fn launch() -> Result<()> { |
| 27 | let git_repo = Repo::discover().context("cannot find a git repository")?; | 27 | let git_repo = Repo::discover().context("failed to find a git repository")?; |
| 28 | let git_repo_path = git_repo.get_path()?; | 28 | let git_repo_path = git_repo.get_path()?; |
| 29 | 29 | ||
| 30 | // TODO: check for empty repo | 30 | // TODO: check for empty repo |
| @@ -179,7 +179,7 @@ pub async fn launch() -> Result<()> { | |||
| 179 | } | 179 | } |
| 180 | 180 | ||
| 181 | let cover_letter = event_to_cover_letter(proposals_for_status[selected_index]) | 181 | let cover_letter = event_to_cover_letter(proposals_for_status[selected_index]) |
| 182 | .context("cannot extract proposal details from proposal root event")?; | 182 | .context("failed to extract proposal details from proposal root event")?; |
| 183 | 183 | ||
| 184 | let commits_events: Vec<nostr::Event> = get_all_proposal_patch_events_from_cache( | 184 | let commits_events: Vec<nostr::Event> = get_all_proposal_patch_events_from_cache( |
| 185 | git_repo_path, | 185 | git_repo_path, |
| @@ -195,7 +195,7 @@ pub async fn launch() -> Result<()> { | |||
| 195 | PromptConfirmParms::default() | 195 | PromptConfirmParms::default() |
| 196 | .with_default(true) | 196 | .with_default(true) |
| 197 | .with_prompt( | 197 | .with_prompt( |
| 198 | "cannot find any patches on this proposal. choose another proposal?", | 198 | "failed to find any patches on this proposal. choose another proposal?", |
| 199 | ), | 199 | ), |
| 200 | )? { | 200 | )? { |
| 201 | continue; | 201 | continue; |
| @@ -275,7 +275,7 @@ pub async fn launch() -> Result<()> { | |||
| 275 | )?, | 275 | )?, |
| 276 | "parent-commit", | 276 | "parent-commit", |
| 277 | )?) | 277 | )?) |
| 278 | .context("cannot get valid parent commit id from patch")?; | 278 | .context("failed to get valid parent commit id from patch")?; |
| 279 | 279 | ||
| 280 | let (main_branch_name, master_tip) = git_repo.get_main_or_master_branch()?; | 280 | let (main_branch_name, master_tip) = git_repo.get_main_or_master_branch()?; |
| 281 | 281 | ||
| @@ -305,9 +305,9 @@ pub async fn launch() -> Result<()> { | |||
| 305 | &get_commit_id_from_patch(most_recent_proposal_patch_chain.first().context( | 305 | &get_commit_id_from_patch(most_recent_proposal_patch_chain.first().context( |
| 306 | "there should be at least one patch as we have already checked for this", | 306 | "there should be at least one patch as we have already checked for this", |
| 307 | )?) | 307 | )?) |
| 308 | .context("cannot get valid commit_id from patch")?, | 308 | .context("failed to get valid commit_id from patch")?, |
| 309 | ) | 309 | ) |
| 310 | .context("cannot get valid commit_id from patch")?; | 310 | .context("failed to get valid commit_id from patch")?; |
| 311 | 311 | ||
| 312 | let (_, proposal_behind_main) = | 312 | let (_, proposal_behind_main) = |
| 313 | git_repo.get_commits_ahead_behind(&master_tip, &proposal_base_commit)?; | 313 | git_repo.get_commits_ahead_behind(&master_tip, &proposal_base_commit)?; |
| @@ -332,7 +332,7 @@ pub async fn launch() -> Result<()> { | |||
| 332 | &cover_letter.get_branch_name()?, | 332 | &cover_letter.get_branch_name()?, |
| 333 | most_recent_proposal_patch_chain, | 333 | most_recent_proposal_patch_chain, |
| 334 | ) | 334 | ) |
| 335 | .context("cannot apply patch chain")?; | 335 | .context("failed to apply patch chain")?; |
| 336 | 336 | ||
| 337 | println!( | 337 | println!( |
| 338 | "checked out proposal as '{}' branch", | 338 | "checked out proposal as '{}' branch", |
| @@ -427,7 +427,7 @@ pub async fn launch() -> Result<()> { | |||
| 427 | &cover_letter.get_branch_name()?, | 427 | &cover_letter.get_branch_name()?, |
| 428 | most_recent_proposal_patch_chain, | 428 | most_recent_proposal_patch_chain, |
| 429 | ) | 429 | ) |
| 430 | .context("cannot apply patch chain")?; | 430 | .context("failed to apply patch chain")?; |
| 431 | println!( | 431 | println!( |
| 432 | "checked out proposal branch and applied {} appendments ({} ahead {} behind '{main_branch_name}')", | 432 | "checked out proposal branch and applied {} appendments ({} ahead {} behind '{main_branch_name}')", |
| 433 | &index, | 433 | &index, |
| @@ -484,7 +484,7 @@ pub async fn launch() -> Result<()> { | |||
| 484 | &cover_letter.get_branch_name()?, | 484 | &cover_letter.get_branch_name()?, |
| 485 | most_recent_proposal_patch_chain, | 485 | most_recent_proposal_patch_chain, |
| 486 | ) | 486 | ) |
| 487 | .context("cannot apply patch chain")?; | 487 | .context("failed to apply patch chain")?; |
| 488 | println!( | 488 | println!( |
| 489 | "checked out new version of proposal ({} ahead {} behind '{main_branch_name}'), replacing old version ({} ahead {} behind '{main_branch_name}')", | 489 | "checked out new version of proposal ({} ahead {} behind '{main_branch_name}'), replacing old version ({} ahead {} behind '{main_branch_name}')", |
| 490 | chain_length, | 490 | chain_length, |
| @@ -517,7 +517,9 @@ pub async fn launch() -> Result<()> { | |||
| 517 | else if git_repo.ancestor_of(&local_branch_tip, &proposal_tip)? { | 517 | else if git_repo.ancestor_of(&local_branch_tip, &proposal_tip)? { |
| 518 | let (local_ahead_of_proposal, _) = git_repo | 518 | let (local_ahead_of_proposal, _) = git_repo |
| 519 | .get_commits_ahead_behind(&proposal_tip, &local_branch_tip) | 519 | .get_commits_ahead_behind(&proposal_tip, &local_branch_tip) |
| 520 | .context("cannot get commits ahead behind for propsal_top and local_branch_tip")?; | 520 | .context( |
| 521 | "failed to get commits ahead behind for propsal_top and local_branch_tip", | ||
| 522 | )?; | ||
| 521 | 523 | ||
| 522 | println!( | 524 | println!( |
| 523 | "local proposal branch exists with {} unpublished commits on top of the most up-to-date version of the proposal ({} ahead {} behind '{main_branch_name}')", | 525 | "local proposal branch exists with {} unpublished commits on top of the most up-to-date version of the proposal ({} ahead {} behind '{main_branch_name}')", |
| @@ -624,7 +626,7 @@ pub async fn launch() -> Result<()> { | |||
| 624 | &cover_letter.get_branch_name()?, | 626 | &cover_letter.get_branch_name()?, |
| 625 | most_recent_proposal_patch_chain, | 627 | most_recent_proposal_patch_chain, |
| 626 | ) | 628 | ) |
| 627 | .context("cannot apply patch chain")?; | 629 | .context("failed to apply patch chain")?; |
| 628 | 630 | ||
| 629 | git_repo.checkout(&cover_letter.get_branch_name()?)?; | 631 | git_repo.checkout(&cover_letter.get_branch_name()?)?; |
| 630 | println!( | 632 | println!( |
| @@ -715,7 +717,7 @@ fn save_patches_to_dir(mut patches: Vec<nostr::Event>, git_repo: &Repo) -> Resul | |||
| 715 | fn check_clean(git_repo: &Repo) -> Result<()> { | 717 | fn check_clean(git_repo: &Repo) -> Result<()> { |
| 716 | if git_repo.has_outstanding_changes()? { | 718 | if git_repo.has_outstanding_changes()? { |
| 717 | bail!( | 719 | bail!( |
| 718 | "cannot pull proposal branch when repository is not clean. discard or stash (un)staged changes and try again." | 720 | "failed to pull proposal branch when repository is not clean. discard or stash (un)staged changes and try again." |
| 719 | ); | 721 | ); |
| 720 | } | 722 | } |
| 721 | Ok(()) | 723 | Ok(()) |
diff --git a/src/bin/ngit/sub_commands/login.rs b/src/bin/ngit/sub_commands/login.rs index 53da154..16026dd 100644 --- a/src/bin/ngit/sub_commands/login.rs +++ b/src/bin/ngit/sub_commands/login.rs | |||
| @@ -33,7 +33,7 @@ pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { | |||
| 33 | Some(Client::default()) | 33 | Some(Client::default()) |
| 34 | }; | 34 | }; |
| 35 | 35 | ||
| 36 | let git_repo_result = Repo::discover().context("cannot find a git repository"); | 36 | let git_repo_result = Repo::discover().context("failed to find a git repository"); |
| 37 | let git_repo = { | 37 | let git_repo = { |
| 38 | match git_repo_result { | 38 | match git_repo_result { |
| 39 | Ok(git_repo) => Some(git_repo), | 39 | Ok(git_repo) => Some(git_repo), |
diff --git a/src/bin/ngit/sub_commands/pull.rs b/src/bin/ngit/sub_commands/pull.rs index 77a65e9..f459c8e 100644 --- a/src/bin/ngit/sub_commands/pull.rs +++ b/src/bin/ngit/sub_commands/pull.rs | |||
| @@ -14,7 +14,7 @@ use crate::{ | |||
| 14 | 14 | ||
| 15 | #[allow(clippy::too_many_lines)] | 15 | #[allow(clippy::too_many_lines)] |
| 16 | pub async fn launch() -> Result<()> { | 16 | pub async fn launch() -> Result<()> { |
| 17 | let git_repo = Repo::discover().context("cannot find a git repository")?; | 17 | let git_repo = Repo::discover().context("failed to find a git repository")?; |
| 18 | let git_repo_path = git_repo.get_path()?; | 18 | let git_repo_path = git_repo.get_path()?; |
| 19 | 19 | ||
| 20 | let (main_or_master_branch_name, _) = git_repo | 20 | let (main_or_master_branch_name, _) = git_repo |
| @@ -23,7 +23,7 @@ pub async fn launch() -> Result<()> { | |||
| 23 | 23 | ||
| 24 | let branch_name = git_repo | 24 | let branch_name = git_repo |
| 25 | .get_checked_out_branch_name() | 25 | .get_checked_out_branch_name() |
| 26 | .context("cannot get checked out branch name")?; | 26 | .context("failed to get checked out branch name")?; |
| 27 | 27 | ||
| 28 | if branch_name == main_or_master_branch_name { | 28 | if branch_name == main_or_master_branch_name { |
| 29 | bail!("checkout a branch associated with a proposal first") | 29 | bail!("checkout a branch associated with a proposal first") |
| @@ -50,7 +50,7 @@ pub async fn launch() -> Result<()> { | |||
| 50 | is_event_proposal_root_for_branch(e, &branch_name, &logged_in_public_key) | 50 | is_event_proposal_root_for_branch(e, &branch_name, &logged_in_public_key) |
| 51 | .unwrap_or(false) | 51 | .unwrap_or(false) |
| 52 | }) | 52 | }) |
| 53 | .context("cannot find proposal that matches the current branch name")? | 53 | .context("failed to find proposal that matches the current branch name")? |
| 54 | .clone(); | 54 | .clone(); |
| 55 | 55 | ||
| 56 | let commit_events = | 56 | let commit_events = |
| @@ -59,7 +59,7 @@ pub async fn launch() -> Result<()> { | |||
| 59 | 59 | ||
| 60 | let most_recent_proposal_patch_chain = | 60 | let most_recent_proposal_patch_chain = |
| 61 | get_most_recent_patch_with_ancestors(commit_events.clone()) | 61 | get_most_recent_patch_with_ancestors(commit_events.clone()) |
| 62 | .context("cannot get most recent patch for proposal")?; | 62 | .context("failed to get most recent patch for proposal")?; |
| 63 | 63 | ||
| 64 | let local_branch_tip = git_repo.get_tip_of_branch(&branch_name)?; | 64 | let local_branch_tip = git_repo.get_tip_of_branch(&branch_name)?; |
| 65 | 65 | ||
| @@ -74,7 +74,7 @@ pub async fn launch() -> Result<()> { | |||
| 74 | .context("there should be at least one patch as we have already checked for this")?, | 74 | .context("there should be at least one patch as we have already checked for this")?, |
| 75 | "parent-commit", | 75 | "parent-commit", |
| 76 | )?) | 76 | )?) |
| 77 | .context("cannot get valid parent commit id from patch")?; | 77 | .context("failed to get valid parent commit id from patch")?; |
| 78 | 78 | ||
| 79 | let (_, proposal_behind_main) = | 79 | let (_, proposal_behind_main) = |
| 80 | git_repo.get_commits_ahead_behind(&master_tip, &proposal_base_commit)?; | 80 | git_repo.get_commits_ahead_behind(&master_tip, &proposal_base_commit)?; |
| @@ -84,9 +84,9 @@ pub async fn launch() -> Result<()> { | |||
| 84 | &get_commit_id_from_patch(most_recent_proposal_patch_chain.first().context( | 84 | &get_commit_id_from_patch(most_recent_proposal_patch_chain.first().context( |
| 85 | "there should be at least one patch as we have already checked for this", | 85 | "there should be at least one patch as we have already checked for this", |
| 86 | )?) | 86 | )?) |
| 87 | .context("cannot get valid commit_id from patch")?, | 87 | .context("failed to get valid commit_id from patch")?, |
| 88 | ) | 88 | ) |
| 89 | .context("cannot get valid commit_id from patch")?; | 89 | .context("failed to get valid commit_id from patch")?; |
| 90 | 90 | ||
| 91 | // if uptodate | 91 | // if uptodate |
| 92 | if proposal_tip.eq(&local_branch_tip) { | 92 | if proposal_tip.eq(&local_branch_tip) { |
| @@ -101,7 +101,7 @@ pub async fn launch() -> Result<()> { | |||
| 101 | check_clean(&git_repo)?; | 101 | check_clean(&git_repo)?; |
| 102 | let applied = git_repo | 102 | let applied = git_repo |
| 103 | .apply_patch_chain(&branch_name, most_recent_proposal_patch_chain) | 103 | .apply_patch_chain(&branch_name, most_recent_proposal_patch_chain) |
| 104 | .context("cannot apply patch chain")?; | 104 | .context("failed to apply patch chain")?; |
| 105 | println!("applied {} new commits", applied.len(),); | 105 | println!("applied {} new commits", applied.len(),); |
| 106 | } | 106 | } |
| 107 | // if parent commit doesnt exist | 107 | // if parent commit doesnt exist |
| @@ -123,7 +123,7 @@ pub async fn launch() -> Result<()> { | |||
| 123 | git_repo.create_branch_at_commit(&branch_name, &proposal_base_commit.to_string())?; | 123 | git_repo.create_branch_at_commit(&branch_name, &proposal_base_commit.to_string())?; |
| 124 | let applied = git_repo | 124 | let applied = git_repo |
| 125 | .apply_patch_chain(&branch_name, most_recent_proposal_patch_chain) | 125 | .apply_patch_chain(&branch_name, most_recent_proposal_patch_chain) |
| 126 | .context("cannot apply patch chain")?; | 126 | .context("failed to apply patch chain")?; |
| 127 | 127 | ||
| 128 | println!( | 128 | println!( |
| 129 | "pulled new version of proposal ({} ahead {} behind '{main_branch_name}'), replacing old version ({} ahead {} behind '{main_branch_name}')", | 129 | "pulled new version of proposal ({} ahead {} behind '{main_branch_name}'), replacing old version ({} ahead {} behind '{main_branch_name}')", |
| @@ -138,7 +138,7 @@ pub async fn launch() -> Result<()> { | |||
| 138 | else if git_repo.ancestor_of(&local_branch_tip, &proposal_tip)? { | 138 | else if git_repo.ancestor_of(&local_branch_tip, &proposal_tip)? { |
| 139 | let (local_ahead_of_proposal, _) = git_repo | 139 | let (local_ahead_of_proposal, _) = git_repo |
| 140 | .get_commits_ahead_behind(&proposal_tip, &local_branch_tip) | 140 | .get_commits_ahead_behind(&proposal_tip, &local_branch_tip) |
| 141 | .context("cannot get commits ahead behind for propsal_top and local_branch_tip")?; | 141 | .context("failed to get commits ahead behind for propsal_top and local_branch_tip")?; |
| 142 | println!( | 142 | println!( |
| 143 | "local proposal branch exists with {} unpublished commits on top of the most up-to-date version of the proposal", | 143 | "local proposal branch exists with {} unpublished commits on top of the most up-to-date version of the proposal", |
| 144 | local_ahead_of_proposal.len() | 144 | local_ahead_of_proposal.len() |
| @@ -196,7 +196,7 @@ pub async fn launch() -> Result<()> { | |||
| 196 | fn check_clean(git_repo: &Repo) -> Result<()> { | 196 | fn check_clean(git_repo: &Repo) -> Result<()> { |
| 197 | if git_repo.has_outstanding_changes()? { | 197 | if git_repo.has_outstanding_changes()? { |
| 198 | bail!( | 198 | bail!( |
| 199 | "cannot pull proposal branch when repository is not clean. discard or stash (un)staged changes and try again." | 199 | "failed to pull proposal branch when repository is not clean. discard or stash (un)staged changes and try again." |
| 200 | ); | 200 | ); |
| 201 | } | 201 | } |
| 202 | Ok(()) | 202 | Ok(()) |
diff --git a/src/bin/ngit/sub_commands/push.rs b/src/bin/ngit/sub_commands/push.rs index aaf1009..89b2364 100644 --- a/src/bin/ngit/sub_commands/push.rs +++ b/src/bin/ngit/sub_commands/push.rs | |||
| @@ -29,7 +29,7 @@ pub struct SubCommandArgs { | |||
| 29 | 29 | ||
| 30 | #[allow(clippy::too_many_lines)] | 30 | #[allow(clippy::too_many_lines)] |
| 31 | pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | 31 | pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { |
| 32 | let git_repo = Repo::discover().context("cannot find a git repository")?; | 32 | let git_repo = Repo::discover().context("failed to find a git repository")?; |
| 33 | let git_repo_path = git_repo.get_path()?; | 33 | let git_repo_path = git_repo.get_path()?; |
| 34 | 34 | ||
| 35 | let (main_or_master_branch_name, _) = git_repo | 35 | let (main_or_master_branch_name, _) = git_repo |
| @@ -42,7 +42,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 42 | 42 | ||
| 43 | let branch_name = git_repo | 43 | let branch_name = git_repo |
| 44 | .get_checked_out_branch_name() | 44 | .get_checked_out_branch_name() |
| 45 | .context("cannot get checked out branch name")?; | 45 | .context("failed to get checked out branch name")?; |
| 46 | 46 | ||
| 47 | if branch_name == main_or_master_branch_name { | 47 | if branch_name == main_or_master_branch_name { |
| 48 | bail!("checkout a branch associated with a proposal first") | 48 | bail!("checkout a branch associated with a proposal first") |
| @@ -70,7 +70,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 70 | is_event_proposal_root_for_branch(e, &branch_name, &logged_in_public_key) | 70 | is_event_proposal_root_for_branch(e, &branch_name, &logged_in_public_key) |
| 71 | .unwrap_or(false) | 71 | .unwrap_or(false) |
| 72 | }) | 72 | }) |
| 73 | .context("cannot find proposal that matches the current branch name")? | 73 | .context("failed to find proposal that matches the current branch name")? |
| 74 | .clone(); | 74 | .clone(); |
| 75 | 75 | ||
| 76 | let commit_events = | 76 | let commit_events = |
| @@ -78,7 +78,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 78 | .await?; | 78 | .await?; |
| 79 | 79 | ||
| 80 | let most_recent_proposal_patch_chain = get_most_recent_patch_with_ancestors(commit_events) | 80 | let most_recent_proposal_patch_chain = get_most_recent_patch_with_ancestors(commit_events) |
| 81 | .context("cannot get most recent patch for proposal")?; | 81 | .context("failed to get most recent patch for proposal")?; |
| 82 | 82 | ||
| 83 | let branch_tip = git_repo.get_tip_of_branch(&branch_name)?; | 83 | let branch_tip = git_repo.get_tip_of_branch(&branch_name)?; |
| 84 | 84 | ||
| @@ -191,7 +191,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 191 | &[], | 191 | &[], |
| 192 | ) | 192 | ) |
| 193 | .await | 193 | .await |
| 194 | .context("cannot make patch event from commit")?, | 194 | .context("failed to make patch event from commit")?, |
| 195 | ); | 195 | ); |
| 196 | } | 196 | } |
| 197 | println!("pushing {} commits", ahead.len()); | 197 | println!("pushing {} commits", ahead.len()); |
diff --git a/src/bin/ngit/sub_commands/send.rs b/src/bin/ngit/sub_commands/send.rs index 114a021..1965875 100644 --- a/src/bin/ngit/sub_commands/send.rs +++ b/src/bin/ngit/sub_commands/send.rs | |||
| @@ -45,7 +45,7 @@ pub struct SubCommandArgs { | |||
| 45 | 45 | ||
| 46 | #[allow(clippy::too_many_lines)] | 46 | #[allow(clippy::too_many_lines)] |
| 47 | pub async fn launch(cli_args: &Cli, args: &SubCommandArgs, no_fetch: bool) -> Result<()> { | 47 | pub async fn launch(cli_args: &Cli, args: &SubCommandArgs, no_fetch: bool) -> Result<()> { |
| 48 | let git_repo = Repo::discover().context("cannot find a git repository")?; | 48 | let git_repo = Repo::discover().context("failed to find a git repository")?; |
| 49 | let git_repo_path = git_repo.get_path()?; | 49 | let git_repo_path = git_repo.get_path()?; |
| 50 | 50 | ||
| 51 | let (main_branch_name, main_tip) = git_repo | 51 | let (main_branch_name, main_tip) = git_repo |
| @@ -83,7 +83,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs, no_fetch: bool) -> Re | |||
| 83 | } else { | 83 | } else { |
| 84 | git_repo | 84 | git_repo |
| 85 | .parse_starting_commits(&args.since_or_range) | 85 | .parse_starting_commits(&args.since_or_range) |
| 86 | .context("cannot parse specified starting commit or range")? | 86 | .context("failed to parse specified starting commit or range")? |
| 87 | } | 87 | } |
| 88 | }; | 88 | }; |
| 89 | 89 | ||
diff --git a/src/lib/client.rs b/src/lib/client.rs index a8b48f4..7093dd5 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs | |||
| @@ -176,7 +176,7 @@ impl Connect for Client { | |||
| 176 | self.client | 176 | self.client |
| 177 | .add_relay(relay_url) | 177 | .add_relay(relay_url) |
| 178 | .await | 178 | .await |
| 179 | .context("cannot add relay")?; | 179 | .context("failed to add relay")?; |
| 180 | 180 | ||
| 181 | let relay = self.client.relay(relay_url).await?; | 181 | let relay = self.client.relay(relay_url).await?; |
| 182 | 182 | ||
| @@ -263,7 +263,7 @@ impl Connect for Client { | |||
| 263 | self.client | 263 | self.client |
| 264 | .add_relay(relay.as_str()) | 264 | .add_relay(relay.as_str()) |
| 265 | .await | 265 | .await |
| 266 | .context("cannot add relay")?; | 266 | .context("failed to add relay")?; |
| 267 | } | 267 | } |
| 268 | 268 | ||
| 269 | let relays_map = self.client.relays().await; | 269 | let relays_map = self.client.relays().await; |
| @@ -374,7 +374,7 @@ impl Connect for Client { | |||
| 374 | self.client | 374 | self.client |
| 375 | .add_relay(relay.as_str()) | 375 | .add_relay(relay.as_str()) |
| 376 | .await | 376 | .await |
| 377 | .context("cannot add relay")?; | 377 | .context("failed to add relay")?; |
| 378 | } | 378 | } |
| 379 | 379 | ||
| 380 | let dim = Style::new().color256(247); | 380 | let dim = Style::new().color256(247); |
| @@ -741,7 +741,7 @@ fn pb_after_style(succeed: bool) -> indicatif::ProgressStyle { | |||
| 741 | 741 | ||
| 742 | async fn get_local_cache_database(git_repo_path: &Path) -> Result<NostrLMDB> { | 742 | async fn get_local_cache_database(git_repo_path: &Path) -> Result<NostrLMDB> { |
| 743 | NostrLMDB::open(git_repo_path.join(".git/nostr-cache.lmdb")) | 743 | NostrLMDB::open(git_repo_path.join(".git/nostr-cache.lmdb")) |
| 744 | .context("cannot open or create nostr cache database at .git/nostr-cache.lmdb") | 744 | .context("failed to open or create nostr cache database at .git/nostr-cache.lmdb") |
| 745 | } | 745 | } |
| 746 | 746 | ||
| 747 | async fn get_global_cache_database(git_repo_path: Option<&Path>) -> Result<NostrLMDB> { | 747 | async fn get_global_cache_database(git_repo_path: Option<&Path>) -> Result<NostrLMDB> { |
| @@ -753,13 +753,13 @@ async fn get_global_cache_database(git_repo_path: Option<&Path>) -> Result<Nostr | |||
| 753 | } | 753 | } |
| 754 | } else { | 754 | } else { |
| 755 | create_dir_all(get_dirs()?.cache_dir()).context(format!( | 755 | create_dir_all(get_dirs()?.cache_dir()).context(format!( |
| 756 | "cannot create cache directory in: {:?}", | 756 | "failed to create cache directory in: {:?}", |
| 757 | get_dirs()?.cache_dir() | 757 | get_dirs()?.cache_dir() |
| 758 | ))?; | 758 | ))?; |
| 759 | get_dirs()?.cache_dir().join("nostr-cache.lmdb") | 759 | get_dirs()?.cache_dir().join("nostr-cache.lmdb") |
| 760 | }; | 760 | }; |
| 761 | 761 | ||
| 762 | NostrLMDB::open(path).context("cannot open ngit global nostr cache database") | 762 | NostrLMDB::open(path).context("failed to open ngit global nostr cache database") |
| 763 | } | 763 | } |
| 764 | 764 | ||
| 765 | pub async fn get_events_from_local_cache( | 765 | pub async fn get_events_from_local_cache( |
| @@ -771,7 +771,7 @@ pub async fn get_events_from_local_cache( | |||
| 771 | .query(filters.clone()) | 771 | .query(filters.clone()) |
| 772 | .await | 772 | .await |
| 773 | .context( | 773 | .context( |
| 774 | "cannot execute query on opened git repo nostr cache database .git/nostr-cache.lmdb", | 774 | "failed to execute query on opened git repo nostr cache database .git/nostr-cache.lmdb", |
| 775 | )? | 775 | )? |
| 776 | .to_vec()) | 776 | .to_vec()) |
| 777 | } | 777 | } |
| @@ -784,7 +784,7 @@ pub async fn get_event_from_global_cache( | |||
| 784 | .await? | 784 | .await? |
| 785 | .query(filters.clone()) | 785 | .query(filters.clone()) |
| 786 | .await | 786 | .await |
| 787 | .context("cannot execute query on opened ngit nostr cache database")? | 787 | .context("failed to execute query on opened ngit nostr cache database")? |
| 788 | .to_vec()) | 788 | .to_vec()) |
| 789 | } | 789 | } |
| 790 | 790 | ||
| @@ -793,7 +793,7 @@ pub async fn save_event_in_local_cache(git_repo_path: &Path, event: &nostr::Even | |||
| 793 | .await? | 793 | .await? |
| 794 | .save_event(event) | 794 | .save_event(event) |
| 795 | .await | 795 | .await |
| 796 | .context("cannot save event in local cache") | 796 | .context("failed to save event in local cache") |
| 797 | } | 797 | } |
| 798 | 798 | ||
| 799 | pub async fn save_event_in_global_cache( | 799 | pub async fn save_event_in_global_cache( |
| @@ -804,7 +804,7 @@ pub async fn save_event_in_global_cache( | |||
| 804 | .await? | 804 | .await? |
| 805 | .save_event(event) | 805 | .save_event(event) |
| 806 | .await | 806 | .await |
| 807 | .context("cannot save event in local cache") | 807 | .context("failed to save event in local cache") |
| 808 | } | 808 | } |
| 809 | 809 | ||
| 810 | pub async fn get_repo_ref_from_cache( | 810 | pub async fn get_repo_ref_from_cache( |
| @@ -1634,7 +1634,7 @@ pub async fn get_event_from_cache_by_id(git_repo: &Repo, event_id: &EventId) -> | |||
| 1634 | ) | 1634 | ) |
| 1635 | .await? | 1635 | .await? |
| 1636 | .first() | 1636 | .first() |
| 1637 | .context("cannot find event in cache")? | 1637 | .context("failed to find event in cache")? |
| 1638 | .clone()) | 1638 | .clone()) |
| 1639 | } | 1639 | } |
| 1640 | 1640 | ||
diff --git a/src/lib/git/identify_ahead_behind.rs b/src/lib/git/identify_ahead_behind.rs index c98c994..d736522 100644 --- a/src/lib/git/identify_ahead_behind.rs +++ b/src/lib/git/identify_ahead_behind.rs | |||
| @@ -16,7 +16,7 @@ pub fn identify_ahead_behind( | |||
| 16 | name.to_string(), | 16 | name.to_string(), |
| 17 | git_repo | 17 | git_repo |
| 18 | .get_tip_of_branch(name) | 18 | .get_tip_of_branch(name) |
| 19 | .context(format!("cannot find from_branch '{name}'"))?, | 19 | .context(format!("failed to find from_branch '{name}'"))?, |
| 20 | ), | 20 | ), |
| 21 | None => ( | 21 | None => ( |
| 22 | if let Ok(name) = git_repo.get_checked_out_branch_name() { | 22 | if let Ok(name) = git_repo.get_checked_out_branch_name() { |
| @@ -38,7 +38,7 @@ pub fn identify_ahead_behind( | |||
| 38 | name.to_string(), | 38 | name.to_string(), |
| 39 | git_repo | 39 | git_repo |
| 40 | .get_tip_of_branch(name) | 40 | .get_tip_of_branch(name) |
| 41 | .context(format!("cannot find to_branch '{name}'"))?, | 41 | .context(format!("failed to find to_branch '{name}'"))?, |
| 42 | ), | 42 | ), |
| 43 | None => { | 43 | None => { |
| 44 | let (name, commit) = git_repo | 44 | let (name, commit) = git_repo |
| @@ -82,7 +82,7 @@ mod tests { | |||
| 82 | identify_ahead_behind(&git_repo, &Some(branch_name.to_string()), &None) | 82 | identify_ahead_behind(&git_repo, &Some(branch_name.to_string()), &None) |
| 83 | .unwrap_err() | 83 | .unwrap_err() |
| 84 | .to_string(), | 84 | .to_string(), |
| 85 | format!("cannot find from_branch '{}'", &branch_name), | 85 | format!("failed to find from_branch '{}'", &branch_name), |
| 86 | ); | 86 | ); |
| 87 | Ok(()) | 87 | Ok(()) |
| 88 | } | 88 | } |
| @@ -98,7 +98,7 @@ mod tests { | |||
| 98 | identify_ahead_behind(&git_repo, &None, &Some(branch_name.to_string())) | 98 | identify_ahead_behind(&git_repo, &None, &Some(branch_name.to_string())) |
| 99 | .unwrap_err() | 99 | .unwrap_err() |
| 100 | .to_string(), | 100 | .to_string(), |
| 101 | format!("cannot find to_branch '{}'", &branch_name), | 101 | format!("failed to find to_branch '{}'", &branch_name), |
| 102 | ); | 102 | ); |
| 103 | Ok(()) | 103 | Ok(()) |
| 104 | } | 104 | } |
diff --git a/src/lib/git/mod.rs b/src/lib/git/mod.rs index 45ac58c..a49d306 100644 --- a/src/lib/git/mod.rs +++ b/src/lib/git/mod.rs | |||
| @@ -99,16 +99,16 @@ impl RepoActions for Repo { | |||
| 99 | self.git_repo | 99 | self.git_repo |
| 100 | .path() | 100 | .path() |
| 101 | .parent() | 101 | .parent() |
| 102 | .context("cannot find repositiory path as .git has no parent") | 102 | .context("failed to find repositiory path as .git has no parent") |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | fn get_origin_url(&self) -> Result<String> { | 105 | fn get_origin_url(&self) -> Result<String> { |
| 106 | Ok(self | 106 | Ok(self |
| 107 | .git_repo | 107 | .git_repo |
| 108 | .find_remote("origin") | 108 | .find_remote("origin") |
| 109 | .context("cannot find origin")? | 109 | .context("failed to find origin")? |
| 110 | .url() | 110 | .url() |
| 111 | .context("cannot find origin url")? | 111 | .context("failed to find origin url")? |
| 112 | .to_string()) | 112 | .to_string()) |
| 113 | } | 113 | } |
| 114 | 114 | ||
| @@ -116,7 +116,7 @@ impl RepoActions for Repo { | |||
| 116 | let main_branch_name = { | 116 | let main_branch_name = { |
| 117 | let remote_branches = self | 117 | let remote_branches = self |
| 118 | .get_remote_branch_names() | 118 | .get_remote_branch_names() |
| 119 | .context("cannot find any local branches")?; | 119 | .context("failed to find any local branches")?; |
| 120 | if remote_branches.contains(&"origin/main".to_string()) { | 120 | if remote_branches.contains(&"origin/main".to_string()) { |
| 121 | "origin/main" | 121 | "origin/main" |
| 122 | } else if remote_branches.contains(&"origin/master".to_string()) { | 122 | } else if remote_branches.contains(&"origin/master".to_string()) { |
| @@ -129,7 +129,7 @@ impl RepoActions for Repo { | |||
| 129 | let tip = self | 129 | let tip = self |
| 130 | .get_tip_of_branch(main_branch_name) | 130 | .get_tip_of_branch(main_branch_name) |
| 131 | .context(format!( | 131 | .context(format!( |
| 132 | "branch {main_branch_name} was listed as a remote branch but cannot get its tip commit id", | 132 | "branch {main_branch_name} was listed as a remote branch but failed to get its tip commit id", |
| 133 | ))?; | 133 | ))?; |
| 134 | 134 | ||
| 135 | Ok((main_branch_name, tip)) | 135 | Ok((main_branch_name, tip)) |
| @@ -139,7 +139,7 @@ impl RepoActions for Repo { | |||
| 139 | let main_branch_name = { | 139 | let main_branch_name = { |
| 140 | let local_branches = self | 140 | let local_branches = self |
| 141 | .get_local_branch_names() | 141 | .get_local_branch_names() |
| 142 | .context("cannot find any local branches")?; | 142 | .context("failed to find any local branches")?; |
| 143 | if local_branches.contains(&"main".to_string()) { | 143 | if local_branches.contains(&"main".to_string()) { |
| 144 | "main" | 144 | "main" |
| 145 | } else if local_branches.contains(&"master".to_string()) { | 145 | } else if local_branches.contains(&"master".to_string()) { |
| @@ -152,7 +152,7 @@ impl RepoActions for Repo { | |||
| 152 | let tip = self | 152 | let tip = self |
| 153 | .get_tip_of_branch(main_branch_name) | 153 | .get_tip_of_branch(main_branch_name) |
| 154 | .context(format!( | 154 | .context(format!( |
| 155 | "branch {main_branch_name} was listed as a local branch but cannot get its tip commit id", | 155 | "branch {main_branch_name} was listed as a local branch but failed to get its tip commit id", |
| 156 | ))?; | 156 | ))?; |
| 157 | 157 | ||
| 158 | Ok((main_branch_name, tip)) | 158 | Ok((main_branch_name, tip)) |
| @@ -217,13 +217,15 @@ impl RepoActions for Repo { | |||
| 217 | let branch = if let Ok(branch) = self | 217 | let branch = if let Ok(branch) = self |
| 218 | .git_repo | 218 | .git_repo |
| 219 | .find_branch(branch_name, git2::BranchType::Local) | 219 | .find_branch(branch_name, git2::BranchType::Local) |
| 220 | .context(format!("cannot find local branch {branch_name}")) | 220 | .context(format!("failed to find local branch {branch_name}")) |
| 221 | { | 221 | { |
| 222 | branch | 222 | branch |
| 223 | } else { | 223 | } else { |
| 224 | self.git_repo | 224 | self.git_repo |
| 225 | .find_branch(branch_name, git2::BranchType::Remote) | 225 | .find_branch(branch_name, git2::BranchType::Remote) |
| 226 | .context(format!("cannot find local or remote branch {branch_name}"))? | 226 | .context(format!( |
| 227 | "failed to find local or remote branch {branch_name}" | ||
| 228 | ))? | ||
| 227 | }; | 229 | }; |
| 228 | Ok(oid_to_sha1(&branch.into_reference().peel_to_commit()?.id())) | 230 | Ok(oid_to_sha1(&branch.into_reference().peel_to_commit()?.id())) |
| 229 | } | 231 | } |
| @@ -385,7 +387,7 @@ impl RepoActions for Repo { | |||
| 385 | .context("failed to extract signature - perhaps there is no signature?")?; | 387 | .context("failed to extract signature - perhaps there is no signature?")?; |
| 386 | 388 | ||
| 387 | Ok(std::str::from_utf8(&sign) | 389 | Ok(std::str::from_utf8(&sign) |
| 388 | .context("commit signature cannot be converted to a utf8 string")? | 390 | .context("commit signature failed to be converted to a utf8 string")? |
| 389 | .to_owned()) | 391 | .to_owned()) |
| 390 | } | 392 | } |
| 391 | 393 | ||
| @@ -525,7 +527,7 @@ impl RepoActions for Repo { | |||
| 525 | last_patch | 527 | last_patch |
| 526 | } else { | 528 | } else { |
| 527 | self.checkout(branch_name) | 529 | self.checkout(branch_name) |
| 528 | .context("no patches and so cannot create a proposal branch")?; | 530 | .context("no patches and so failed to create a proposal branch")?; |
| 529 | return Ok(vec![]); | 531 | return Ok(vec![]); |
| 530 | }, | 532 | }, |
| 531 | "parent-commit", | 533 | "parent-commit", |
| @@ -533,7 +535,7 @@ impl RepoActions for Repo { | |||
| 533 | 535 | ||
| 534 | // check patches can be applied | 536 | // check patches can be applied |
| 535 | if !self.does_commit_exist(&parent_commit_id)? { | 537 | if !self.does_commit_exist(&parent_commit_id)? { |
| 536 | bail!("cannot find parent commit ({parent_commit_id}). run git pull and try again.") | 538 | bail!("failed to find parent commit ({parent_commit_id}). run git pull and try again.") |
| 537 | } | 539 | } |
| 538 | 540 | ||
| 539 | // checkout branch | 541 | // checkout branch |
| @@ -644,7 +646,7 @@ impl RepoActions for Repo { | |||
| 644 | None, | 646 | None, |
| 645 | None, | 647 | None, |
| 646 | ) | 648 | ) |
| 647 | .context("cannot amend commit to produce new oid")?; | 649 | .context("failed to amend commit to produce new oid")?; |
| 648 | } | 650 | } |
| 649 | if !applied_oid.to_string().eq(commit_id) { | 651 | if !applied_oid.to_string().eq(commit_id) { |
| 650 | bail!( | 652 | bail!( |
| @@ -669,12 +671,12 @@ impl RepoActions for Repo { | |||
| 669 | &oid_to_sha1( | 671 | &oid_to_sha1( |
| 670 | &revspec | 672 | &revspec |
| 671 | .from() | 673 | .from() |
| 672 | .context("cannot get starting commit from specified value")? | 674 | .context("failed to get starting commit from specified value")? |
| 673 | .id(), | 675 | .id(), |
| 674 | ), | 676 | ), |
| 675 | &self | 677 | &self |
| 676 | .get_head_commit() | 678 | .get_head_commit() |
| 677 | .context("cannot get head commit with gitlib2")?, | 679 | .context("failed to get head commit with gitlib2")?, |
| 678 | ) | 680 | ) |
| 679 | .context("specified commit is not an ancestor of current head")?; | 681 | .context("specified commit is not an ancestor of current head")?; |
| 680 | Ok(ahead) | 682 | Ok(ahead) |
| @@ -684,13 +686,13 @@ impl RepoActions for Repo { | |||
| 684 | &oid_to_sha1( | 686 | &oid_to_sha1( |
| 685 | &revspec | 687 | &revspec |
| 686 | .from() | 688 | .from() |
| 687 | .context("cannot get starting commit of range from specified value")? | 689 | .context("failed to get starting commit of range from specified value")? |
| 688 | .id(), | 690 | .id(), |
| 689 | ), | 691 | ), |
| 690 | &oid_to_sha1( | 692 | &oid_to_sha1( |
| 691 | &revspec | 693 | &revspec |
| 692 | .to() | 694 | .to() |
| 693 | .context("cannot get end of range commit from specified value")? | 695 | .context("failed to get end of range commit from specified value")? |
| 694 | .id(), | 696 | .id(), |
| 695 | ), | 697 | ), |
| 696 | ) | 698 | ) |
| @@ -720,11 +722,13 @@ impl RepoActions for Repo { | |||
| 720 | match if just_global { | 722 | match if just_global { |
| 721 | self.git_repo | 723 | self.git_repo |
| 722 | .config() | 724 | .config() |
| 723 | .context("cannot open git config")? | 725 | .context("failed to open git config")? |
| 724 | .open_global() | 726 | .open_global() |
| 725 | .context("cannot open global git config")? | 727 | .context("failed to open global git config")? |
| 726 | } else { | 728 | } else { |
| 727 | self.git_repo.config().context("cannot open git config")? | 729 | self.git_repo |
| 730 | .config() | ||
| 731 | .context("failed to open git config")? | ||
| 728 | } | 732 | } |
| 729 | .get_entry(item) | 733 | .get_entry(item) |
| 730 | { | 734 | { |
| @@ -742,7 +746,7 @@ impl RepoActions for Repo { | |||
| 742 | } | 746 | } |
| 743 | Ok(Some( | 747 | Ok(Some( |
| 744 | item.value() | 748 | item.value() |
| 745 | .context("cannot find git config item")? | 749 | .context("failed to find git config item")? |
| 746 | .to_string(), | 750 | .to_string(), |
| 747 | )) | 751 | )) |
| 748 | } | 752 | } |
| @@ -754,15 +758,17 @@ impl RepoActions for Repo { | |||
| 754 | if global { | 758 | if global { |
| 755 | self.git_repo | 759 | self.git_repo |
| 756 | .config() | 760 | .config() |
| 757 | .context("cannot open git config")? | 761 | .context("failed to open git config")? |
| 758 | .open_global() | 762 | .open_global() |
| 759 | .context("cannot open global git config")? | 763 | .context("failed to open global git config")? |
| 760 | } else { | 764 | } else { |
| 761 | self.git_repo.config().context("cannot open git config")? | 765 | self.git_repo |
| 766 | .config() | ||
| 767 | .context("failed to open git config")? | ||
| 762 | } | 768 | } |
| 763 | .set_str(item, value) | 769 | .set_str(item, value) |
| 764 | .context(format!( | 770 | .context(format!( |
| 765 | "cannot set {} git config item {}", | 771 | "failed to set {} git config item {}", |
| 766 | if global { "global" } else { "local" }, | 772 | if global { "global" } else { "local" }, |
| 767 | item | 773 | item |
| 768 | ))?; | 774 | ))?; |
| @@ -777,14 +783,16 @@ impl RepoActions for Repo { | |||
| 777 | if global { | 783 | if global { |
| 778 | self.git_repo | 784 | self.git_repo |
| 779 | .config() | 785 | .config() |
| 780 | .context("cannot open git config")? | 786 | .context("failed to open git config")? |
| 781 | .open_global() | 787 | .open_global() |
| 782 | .context("cannot open global git config")? | 788 | .context("failed to open global git config")? |
| 783 | } else { | 789 | } else { |
| 784 | self.git_repo.config().context("cannot open git config")? | 790 | self.git_repo |
| 791 | .config() | ||
| 792 | .context("failed to open git config")? | ||
| 785 | } | 793 | } |
| 786 | .remove(item) | 794 | .remove(item) |
| 787 | .context("cannot remove existing git config item")?; | 795 | .context("failed to remove existing git config item")?; |
| 788 | Ok(true) | 796 | Ok(true) |
| 789 | } | 797 | } |
| 790 | } | 798 | } |
| @@ -880,7 +888,7 @@ pub fn save_git_config_item(git_repo: &Option<&Repo>, item: &str, value: &str) - | |||
| 880 | git2::Config::open_default()? | 888 | git2::Config::open_default()? |
| 881 | .open_global()? | 889 | .open_global()? |
| 882 | .set_str(item, value) | 890 | .set_str(item, value) |
| 883 | .context(format!("cannot set global git config item {}", item)) | 891 | .context(format!("failed to set global git config item {}", item)) |
| 884 | } | 892 | } |
| 885 | } | 893 | } |
| 886 | 894 | ||
| @@ -893,7 +901,10 @@ pub fn remove_git_config_item(git_repo: &Option<&Repo>, item: &str) -> Result<bo | |||
| 893 | git2::Config::open_default()? | 901 | git2::Config::open_default()? |
| 894 | .open_global()? | 902 | .open_global()? |
| 895 | .remove(item) | 903 | .remove(item) |
| 896 | .context(format!("cannot remove existing git config item {}", item))?; | 904 | .context(format!( |
| 905 | "failed to remove existing git config item {}", | ||
| 906 | item | ||
| 907 | ))?; | ||
| 897 | Ok(true) | 908 | Ok(true) |
| 898 | } | 909 | } |
| 899 | } | 910 | } |
diff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs index 42b0ac9..b310782 100644 --- a/src/lib/git/nostr_url.rs +++ b/src/lib/git/nostr_url.rs | |||
| @@ -308,7 +308,7 @@ impl CloneUrl { | |||
| 308 | // Set the port if present | 308 | // Set the port if present |
| 309 | if let Some(port) = self.port { | 309 | if let Some(port) = self.port { |
| 310 | url.set_port(Some(port)) | 310 | url.set_port(Some(port)) |
| 311 | .map_err(|_| anyhow!("cannot add port"))?; | 311 | .map_err(|_| anyhow!("failed to add port"))?; |
| 312 | } | 312 | } |
| 313 | 313 | ||
| 314 | // Set the query parameters if present | 314 | // Set the query parameters if present |
diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs index 29c4cf2..bfe5b30 100644 --- a/src/lib/git_events.rs +++ b/src/lib/git_events.rs | |||
| @@ -103,7 +103,7 @@ pub async fn generate_patch_event( | |||
| 103 | nostr::event::Kind::GitPatch, | 103 | nostr::event::Kind::GitPatch, |
| 104 | git_repo | 104 | git_repo |
| 105 | .make_patch_from_commit(commit, &series_count) | 105 | .make_patch_from_commit(commit, &series_count) |
| 106 | .context(format!("cannot make patch for commit {commit}"))?, | 106 | .context(format!("failed to make patch for commit {commit}"))?, |
| 107 | [ | 107 | [ |
| 108 | repo_ref | 108 | repo_ref |
| 109 | .maintainers | 109 | .maintainers |
| @@ -558,7 +558,7 @@ pub fn get_most_recent_patch_with_ancestors( | |||
| 558 | } | 558 | } |
| 559 | }) | 559 | }) |
| 560 | }) | 560 | }) |
| 561 | .context("cannot find patches_with_youngest_created_at")? | 561 | .context("failed to find patches_with_youngest_created_at")? |
| 562 | .id | 562 | .id |
| 563 | .to_string(); | 563 | .to_string(); |
| 564 | 564 | ||
diff --git a/src/lib/login/existing.rs b/src/lib/login/existing.rs index e388a34..342f792 100644 --- a/src/lib/login/existing.rs +++ b/src/lib/login/existing.rs | |||
| @@ -81,13 +81,13 @@ fn get_signer_info( | |||
| 81 | break; | 81 | break; |
| 82 | } | 82 | } |
| 83 | } | 83 | } |
| 84 | result.context("cannot get or find signer info in cli arguments, local git config or global git config")? | 84 | result.context("failed to get or find signer info in cli arguments, local git config or global git config")? |
| 85 | } | 85 | } |
| 86 | Some(SignerInfoSource::CommandLineArguments) => { | 86 | Some(SignerInfoSource::CommandLineArguments) => { |
| 87 | if let Some(signer_info) = signer_info { | 87 | if let Some(signer_info) = signer_info { |
| 88 | (signer_info.clone(), SignerInfoSource::CommandLineArguments) | 88 | (signer_info.clone(), SignerInfoSource::CommandLineArguments) |
| 89 | } else { | 89 | } else { |
| 90 | bail!("cannot get signer from cli signer arguments because none were specified") | 90 | bail!("failed to get signer from cli signer arguments because none were specified") |
| 91 | } | 91 | } |
| 92 | } | 92 | } |
| 93 | Some(SignerInfoSource::GitLocal) => { | 93 | Some(SignerInfoSource::GitLocal) => { |
| @@ -169,7 +169,9 @@ async fn get_signer( | |||
| 169 | password.clone() | 169 | password.clone() |
| 170 | } else { | 170 | } else { |
| 171 | if !prompt_for_ncryptsec_password { | 171 | if !prompt_for_ncryptsec_password { |
| 172 | bail!("cannot login without prompts a nsec is encrypted with a password"); | 172 | bail!( |
| 173 | "failed to login without prompts a nsec is encrypted with a password" | ||
| 174 | ); | ||
| 173 | } | 175 | } |
| 174 | Interactor::default() | 176 | Interactor::default() |
| 175 | .password(PromptPasswordParms::default().with_prompt("password")) | 177 | .password(PromptPasswordParms::default().with_prompt("password")) |
diff --git a/src/lib/login/fresh.rs b/src/lib/login/fresh.rs index 194f638..62622a8 100644 --- a/src/lib/login/fresh.rs +++ b/src/lib/login/fresh.rs | |||
| @@ -627,7 +627,7 @@ fn silently_save_to_git_config( | |||
| 627 | let git_repo = if global { | 627 | let git_repo = if global { |
| 628 | &None | 628 | &None |
| 629 | } else if git_repo.is_none() { | 629 | } else if git_repo.is_none() { |
| 630 | bail!("cannot update local git config wihout git_repo object") | 630 | bail!("failed to update local git config wihout git_repo object") |
| 631 | } else { | 631 | } else { |
| 632 | git_repo | 632 | git_repo |
| 633 | }; | 633 | }; |
diff --git a/src/lib/login/mod.rs b/src/lib/login/mod.rs index d2725e7..00dbb17 100644 --- a/src/lib/login/mod.rs +++ b/src/lib/login/mod.rs | |||
| @@ -61,12 +61,12 @@ fn print_logged_in_as( | |||
| 61 | source: &SignerInfoSource, | 61 | source: &SignerInfoSource, |
| 62 | ) -> Result<()> { | 62 | ) -> Result<()> { |
| 63 | if !offline_mode && user_ref.metadata.created_at.eq(&Timestamp::from(0)) { | 63 | if !offline_mode && user_ref.metadata.created_at.eq(&Timestamp::from(0)) { |
| 64 | eprintln!("cannot find profile..."); | 64 | eprintln!("failed to find profile..."); |
| 65 | } else if !offline_mode && user_ref.metadata.name.eq(&user_ref.public_key.to_bech32()?) { | 65 | } else if !offline_mode && user_ref.metadata.name.eq(&user_ref.public_key.to_bech32()?) { |
| 66 | eprintln!("cannot extract account name from account metadata..."); | 66 | eprintln!("failed to extract account name from account metadata..."); |
| 67 | } else if !offline_mode && user_ref.relays.created_at.eq(&Timestamp::from(0)) { | 67 | } else if !offline_mode && user_ref.relays.created_at.eq(&Timestamp::from(0)) { |
| 68 | eprintln!( | 68 | eprintln!( |
| 69 | "cannot find your relay list. consider using another nostr client to create one to enhance your nostr experience." | 69 | "failed to find your relay list. consider using another nostr client to create one to enhance your nostr experience." |
| 70 | ); | 70 | ); |
| 71 | } | 71 | } |
| 72 | eprintln!( | 72 | eprintln!( |
diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs index 84de185..05234e2 100644 --- a/src/lib/repo_ref.rs +++ b/src/lib/repo_ref.rs | |||
| @@ -95,7 +95,7 @@ impl TryFrom<nostr::Event> for RepoRef { | |||
| 95 | for pk in maintainers { | 95 | for pk in maintainers { |
| 96 | r.maintainers.push( | 96 | r.maintainers.push( |
| 97 | nostr_sdk::prelude::PublicKey::from_str(&pk) | 97 | nostr_sdk::prelude::PublicKey::from_str(&pk) |
| 98 | .context(format!("cannot convert entry from maintainers tag {pk} into a valid nostr public key. it should be in hex format")) | 98 | .context(format!("failed to convert entry from maintainers tag {pk} into a valid nostr public key. it should be in hex format")) |
| 99 | .context("invalid repository event")?, | 99 | .context("invalid repository event")?, |
| 100 | ); | 100 | ); |
| 101 | } | 101 | } |
| @@ -421,8 +421,9 @@ pub fn extract_pks(pk_strings: Vec<String>) -> Result<Vec<PublicKey>> { | |||
| 421 | let mut pks: Vec<PublicKey> = vec![]; | 421 | let mut pks: Vec<PublicKey> = vec![]; |
| 422 | for s in pk_strings { | 422 | for s in pk_strings { |
| 423 | pks.push( | 423 | pks.push( |
| 424 | nostr_sdk::prelude::PublicKey::from_bech32(s.clone()) | 424 | nostr_sdk::prelude::PublicKey::from_bech32(s.clone()).context(format!( |
| 425 | .context(format!("cannot convert {s} into a valid nostr public key"))?, | 425 | "failed to convert {s} into a valid nostr public key" |
| 426 | ))?, | ||
| 426 | ); | 427 | ); |
| 427 | } | 428 | } |
| 428 | Ok(pks) | 429 | Ok(pks) |
| @@ -441,15 +442,15 @@ pub fn save_repo_config_to_yaml( | |||
| 441 | .write(true) | 442 | .write(true) |
| 442 | .truncate(true) | 443 | .truncate(true) |
| 443 | .open(path) | 444 | .open(path) |
| 444 | .context("cannot open maintainers.yaml file with write and truncate options")? | 445 | .context("failed to open maintainers.yaml file with write and truncate options")? |
| 445 | } else { | 446 | } else { |
| 446 | std::fs::File::create(path).context("cannot create maintainers.yaml file")? | 447 | std::fs::File::create(path).context("failed to create maintainers.yaml file")? |
| 447 | }; | 448 | }; |
| 448 | let mut maintainers_npubs = vec![]; | 449 | let mut maintainers_npubs = vec![]; |
| 449 | for m in maintainers { | 450 | for m in maintainers { |
| 450 | maintainers_npubs.push( | 451 | maintainers_npubs.push( |
| 451 | m.to_bech32() | 452 | m.to_bech32() |
| 452 | .context("cannot convert public key into npub")?, | 453 | .context("failed to convert public key into npub")?, |
| 453 | ); | 454 | ); |
| 454 | } | 455 | } |
| 455 | serde_yaml::to_writer( | 456 | serde_yaml::to_writer( |
| @@ -460,7 +461,7 @@ pub fn save_repo_config_to_yaml( | |||
| 460 | relays, | 461 | relays, |
| 461 | }, | 462 | }, |
| 462 | ) | 463 | ) |
| 463 | .context("cannot write maintainers to maintainers.yaml file serde_yaml") | 464 | .context("failed to write maintainers to maintainers.yaml file serde_yaml") |
| 464 | } | 465 | } |
| 465 | 466 | ||
| 466 | #[cfg(test)] | 467 | #[cfg(test)] |