mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 17:08:21 +00:00
Disable fetch,pull,push when no remote defined (#1051)
This commit is contained in:
parent
4b03e92cb9
commit
e7f15ae457
3 changed files with 36 additions and 6 deletions
|
|
@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Keep commit message when pre-commit hook fails ([#1035](https://github.com/extrawurst/gitui/issues/1035))
|
||||
- honor `pushurl` when checking credentials for pushing ([#953](https://github.com/extrawurst/gitui/issues/953))
|
||||
- use git-path instead of workdir finding hooks ([#1046](https://github.com/extrawurst/gitui/issues/1046))
|
||||
- only enable remote actions (fetch/pull/push) if there are remote branches ([#1047](https://github.com/extrawurst/gitui/issues/1047))
|
||||
|
||||
### Key binding notes
|
||||
- added `gg`/`G` vim bindings to `vim_style_key_config.ron` ([#1039](https://github.com/extrawurst/gitui/issues/1039))
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ pub struct BranchListComponent {
|
|||
repo: RepoPathRef,
|
||||
branches: Vec<BranchInfo>,
|
||||
local: bool,
|
||||
has_remotes: bool,
|
||||
visible: bool,
|
||||
selection: u16,
|
||||
scroll: VerticalScroll,
|
||||
|
|
@ -200,7 +201,7 @@ impl Component for BranchListComponent {
|
|||
|
||||
out.push(CommandInfo::new(
|
||||
strings::commands::fetch_remotes(&self.key_config),
|
||||
true,
|
||||
self.has_remotes,
|
||||
!self.local,
|
||||
));
|
||||
}
|
||||
|
|
@ -243,6 +244,7 @@ impl Component for BranchListComponent {
|
|||
.map(Into::into);
|
||||
} else if e == self.key_config.keys.tab_toggle {
|
||||
self.local = !self.local;
|
||||
self.check_remotes();
|
||||
self.update_branches()?;
|
||||
} else if e == self.key_config.keys.enter {
|
||||
try_or_popup!(
|
||||
|
|
@ -297,7 +299,9 @@ impl Component for BranchListComponent {
|
|||
self.queue
|
||||
.push(InternalEvent::CompareCommits(b, None));
|
||||
}
|
||||
} else if e == self.key_config.keys.pull && !self.local {
|
||||
} else if e == self.key_config.keys.pull
|
||||
&& !self.local && self.has_remotes
|
||||
{
|
||||
self.queue.push(InternalEvent::FetchRemotes);
|
||||
} else if e == self.key_config.keys.cmd_bar_toggle {
|
||||
//do not consume if its the more key
|
||||
|
|
@ -333,6 +337,7 @@ impl BranchListComponent {
|
|||
Self {
|
||||
branches: Vec::new(),
|
||||
local: true,
|
||||
has_remotes: false,
|
||||
visible: false,
|
||||
selection: 0,
|
||||
scroll: VerticalScroll::new(),
|
||||
|
|
@ -352,9 +357,19 @@ impl BranchListComponent {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn check_remotes(&mut self) {
|
||||
if !self.local {
|
||||
self.has_remotes =
|
||||
get_branches_info(&self.repo.borrow(), false)
|
||||
.map(|branches| !branches.is_empty())
|
||||
.unwrap_or(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// fetch list of branches
|
||||
pub fn update_branches(&mut self) -> Result<()> {
|
||||
if self.is_visible() {
|
||||
self.check_remotes();
|
||||
self.branches =
|
||||
get_branches_info(&self.repo.borrow(), self.local)?;
|
||||
//remove remote branch called `HEAD`
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ use anyhow::Result;
|
|||
use asyncgit::{
|
||||
cached,
|
||||
sync::{
|
||||
self, status::StatusType, RepoPath, RepoPathRef, RepoState,
|
||||
self, get_branches_info, status::StatusType, RepoPath,
|
||||
RepoPathRef, RepoState,
|
||||
},
|
||||
sync::{BranchCompare, CommitId},
|
||||
AsyncDiff, AsyncGitNotification, AsyncStatus, DiffParams,
|
||||
|
|
@ -554,9 +555,17 @@ impl Status {
|
|||
}
|
||||
}
|
||||
|
||||
fn has_remotes(&self) -> bool {
|
||||
get_branches_info(&self.repo.borrow(), false)
|
||||
.map(|l| !l.is_empty())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn pull(&self) {
|
||||
if let Some(branch) = self.git_branch_name.last() {
|
||||
self.queue.push(InternalEvent::Pull(branch));
|
||||
if self.has_remotes() {
|
||||
if let Some(branch) = self.git_branch_name.last() {
|
||||
self.queue.push(InternalEvent::Pull(branch));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -583,6 +592,11 @@ impl Status {
|
|||
self.git_branch_state
|
||||
.as_ref()
|
||||
.map_or(true, |state| state.ahead > 0)
|
||||
&& self.has_remotes()
|
||||
}
|
||||
|
||||
fn can_pull(&self) -> bool {
|
||||
self.has_remotes()
|
||||
}
|
||||
|
||||
fn can_abort_merge(&self) -> bool {
|
||||
|
|
@ -718,7 +732,7 @@ impl Component for Status {
|
|||
));
|
||||
out.push(CommandInfo::new(
|
||||
strings::commands::status_pull(&self.key_config),
|
||||
true,
|
||||
self.can_pull(),
|
||||
!focus_on_diff,
|
||||
));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue