upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/bin/ngit/sub_commands
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-11-26 07:48:30 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-11-26 12:26:47 +0000
commita0593e3aa9b19b9ca3c3881cbe0d9d207fe46d2c (patch)
tree3482e7c558eff09cc91604ad6ddcd02cf2c94699 /src/bin/ngit/sub_commands
parent1332c625b75fce616e06b415c99a068bc45c8210 (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/bin/ngit/sub_commands')
-rw-r--r--src/bin/ngit/sub_commands/fetch.rs2
-rw-r--r--src/bin/ngit/sub_commands/init.rs2
-rw-r--r--src/bin/ngit/sub_commands/list.rs26
-rw-r--r--src/bin/ngit/sub_commands/login.rs2
-rw-r--r--src/bin/ngit/sub_commands/pull.rs22
-rw-r--r--src/bin/ngit/sub_commands/push.rs10
-rw-r--r--src/bin/ngit/sub_commands/send.rs4
7 files changed, 35 insertions, 33 deletions
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
21pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { 21pub 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)]
49pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { 49pub 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)]
26pub async fn launch() -> Result<()> { 26pub 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
715fn check_clean(git_repo: &Repo) -> Result<()> { 717fn 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)]
16pub async fn launch() -> Result<()> { 16pub 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<()> {
196fn check_clean(git_repo: &Repo) -> Result<()> { 196fn 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)]
31pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { 31pub 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)]
47pub async fn launch(cli_args: &Cli, args: &SubCommandArgs, no_fetch: bool) -> Result<()> { 47pub 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