Skip to content

Commit 7c4bb1c

Browse files
committed
refactor: use BranchInfo instead of local in CheckoutOptionPopup
1 parent 1ee38a2 commit 7c4bb1c

File tree

5 files changed

+22
-23
lines changed

5 files changed

+22
-23
lines changed

asyncgit/src/sync/branch/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ impl BranchInfo {
104104

105105
None
106106
}
107+
108+
/// returns whether branch is local
109+
pub const fn is_local(&self) -> bool {
110+
matches!(self.details, BranchDetails::Local(_))
111+
}
107112
}
108113

109114
///

src/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,8 @@ impl App {
909909
InternalEvent::CommitSearch(options) => {
910910
self.revlog.search(options);
911911
}
912-
InternalEvent::CheckoutOption(branch, is_local) => {
913-
self.checkout_option_popup.open(branch, is_local)?;
912+
InternalEvent::CheckoutOption(branch) => {
913+
self.checkout_option_popup.open(branch)?;
914914
}
915915
}
916916

src/popups/branchlist.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,7 @@ impl BranchListPopup {
609609
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
610610
} else {
611611
self.queue.push(InternalEvent::CheckoutOption(
612-
selected_branch.clone(),
613-
self.local,
612+
selected_branch.clone()
614613
));
615614
}
616615

src/popups/checkout_option.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use ratatui::{
2929
pub struct CheckoutOptionPopup {
3030
queue: Queue,
3131
repo: RepoPath,
32-
local: bool,
3332
branch: Option<BranchInfo>,
3433
option: CheckoutOptions,
3534
visible: bool,
@@ -43,7 +42,6 @@ impl CheckoutOptionPopup {
4342
Self {
4443
queue: env.queue.clone(),
4544
repo: env.repo.borrow().clone(),
46-
local: false,
4745
branch: None,
4846
option: CheckoutOptions::StashAndReapply,
4947
visible: false,
@@ -82,30 +80,27 @@ impl CheckoutOptionPopup {
8280
}
8381

8482
///
85-
pub fn open(
86-
&mut self,
87-
branch: BranchInfo,
88-
is_local: bool,
89-
) -> Result<()> {
83+
pub fn open(&mut self, branch: BranchInfo) -> Result<()> {
9084
self.show()?;
9185

9286
self.branch = Some(branch);
93-
self.local = is_local;
9487

9588
Ok(())
9689
}
9790

9891
fn checkout(&self) -> Result<()> {
99-
if self.local {
100-
checkout_branch(
101-
&self.repo,
102-
&self.branch.as_ref().expect("No branch").name,
103-
)?;
104-
} else {
105-
checkout_remote_branch(
106-
&self.repo,
107-
self.branch.as_ref().expect("No branch"),
108-
)?;
92+
if let Some(branch) = &self.branch {
93+
if branch.is_local() {
94+
checkout_branch(
95+
&self.repo,
96+
&self.branch.as_ref().expect("No branch").name,
97+
)?;
98+
} else {
99+
checkout_remote_branch(
100+
&self.repo,
101+
self.branch.as_ref().expect("No branch"),
102+
)?;
103+
}
109104
}
110105

111106
Ok(())

src/queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub enum InternalEvent {
159159
///
160160
CommitSearch(LogFilterSearchOptions),
161161
///
162-
CheckoutOption(BranchInfo, bool),
162+
CheckoutOption(BranchInfo),
163163
}
164164

165165
/// single threaded simple queue for components to communicate with each other

0 commit comments

Comments
 (0)