upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/sub_commands
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-01-23 00:00:00 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-01-23 00:00:00 +0000
commit7799b0edd16b0c97eb58ba2de62be27134a76122 (patch)
tree1cacb8026e251f51279b6a6be4f57a3cc9b978d2 /src/sub_commands
parentc543b2f25b6893e5dce6111bc12d9812099251ba (diff)
feat(prs-list): check for clean repo
before checking out PR branch add confirm prompt before checking out branch and applying changes
Diffstat (limited to 'src/sub_commands')
-rw-r--r--src/sub_commands/prs/list.rs23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/sub_commands/prs/list.rs b/src/sub_commands/prs/list.rs
index a6aa8b7..f896f5a 100644
--- a/src/sub_commands/prs/list.rs
+++ b/src/sub_commands/prs/list.rs
@@ -1,11 +1,11 @@
1use anyhow::{Context, Result}; 1use anyhow::{bail, Context, Result};
2 2
3#[cfg(not(test))] 3#[cfg(not(test))]
4use crate::client::Client; 4use crate::client::Client;
5#[cfg(test)] 5#[cfg(test)]
6use crate::client::MockConnect; 6use crate::client::MockConnect;
7use crate::{ 7use crate::{
8 cli_interactor::{Interactor, InteractorPrompt, PromptChoiceParms}, 8 cli_interactor::{Interactor, InteractorPrompt, PromptChoiceParms, PromptConfirmParms},
9 client::Connect, 9 client::Connect,
10 git::{Repo, RepoActions}, 10 git::{Repo, RepoActions},
11 repo_ref, 11 repo_ref,
@@ -134,7 +134,7 @@ pub async fn launch(
134 .map(std::borrow::ToOwned::to_owned) 134 .map(std::borrow::ToOwned::to_owned)
135 .collect(); 135 .collect();
136 136
137 // TODO: are there outstanding changes to prevent checking out a new branch? 137 confirm_checkout(&git_repo)?;
138 138
139 let most_recent_pr_patch_chain = get_most_recent_patch_with_ancestors(commits_events) 139 let most_recent_pr_patch_chain = get_most_recent_patch_with_ancestors(commits_events)
140 .context("cannot get most recent patch for PR")?; 140 .context("cannot get most recent patch for PR")?;
@@ -192,6 +192,23 @@ pub async fn launch(
192 Ok(()) 192 Ok(())
193} 193}
194 194
195fn confirm_checkout(git_repo: &Repo) -> Result<()> {
196 if !Interactor::default().confirm(
197 PromptConfirmParms::default()
198 .with_prompt("check out branch?")
199 .with_default(true),
200 )? {
201 bail!("Exiting...");
202 }
203
204 if git_repo.has_outstanding_changes()? {
205 bail!(
206 "cannot pull PR branch when repository is not clean. discard or stash (un)staged changes and try again."
207 );
208 }
209 Ok(())
210}
211
195pub fn tag_value(event: &nostr::Event, tag_name: &str) -> Result<String> { 212pub fn tag_value(event: &nostr::Event, tag_name: &str) -> Result<String> {
196 Ok(event 213 Ok(event
197 .tags 214 .tags