From 7799b0edd16b0c97eb58ba2de62be27134a76122 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 23 Jan 2024 00:00:00 +0000 Subject: feat(prs-list): check for clean repo before checking out PR branch add confirm prompt before checking out branch and applying changes --- src/sub_commands/prs/list.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/sub_commands') 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 @@ -use anyhow::{Context, Result}; +use anyhow::{bail, Context, Result}; #[cfg(not(test))] use crate::client::Client; #[cfg(test)] use crate::client::MockConnect; use crate::{ - cli_interactor::{Interactor, InteractorPrompt, PromptChoiceParms}, + cli_interactor::{Interactor, InteractorPrompt, PromptChoiceParms, PromptConfirmParms}, client::Connect, git::{Repo, RepoActions}, repo_ref, @@ -134,7 +134,7 @@ pub async fn launch( .map(std::borrow::ToOwned::to_owned) .collect(); - // TODO: are there outstanding changes to prevent checking out a new branch? + confirm_checkout(&git_repo)?; let most_recent_pr_patch_chain = get_most_recent_patch_with_ancestors(commits_events) .context("cannot get most recent patch for PR")?; @@ -192,6 +192,23 @@ pub async fn launch( Ok(()) } +fn confirm_checkout(git_repo: &Repo) -> Result<()> { + if !Interactor::default().confirm( + PromptConfirmParms::default() + .with_prompt("check out branch?") + .with_default(true), + )? { + bail!("Exiting..."); + } + + if git_repo.has_outstanding_changes()? { + bail!( + "cannot pull PR branch when repository is not clean. discard or stash (un)staged changes and try again." + ); + } + Ok(()) +} + pub fn tag_value(event: &nostr::Event, tag_name: &str) -> Result { Ok(event .tags -- cgit v1.2.3