From c8a51b5a05b2342dde1b8fc6887cfc091d46f18c Mon Sep 17 00:00:00 2001 From: extrawurst Date: Mon, 19 Feb 2024 15:00:23 +0100 Subject: [PATCH 1/2] allow pushing to empty repo (closes #1919) --- src/tabs/status.rs | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/tabs/status.rs b/src/tabs/status.rs index 592d4d4ecf..6c4df0e14e 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -15,14 +15,13 @@ use crate::{ }; use anyhow::Result; use asyncgit::{ - asyncjob::AsyncSingleJob, cached, sync::{ self, status::StatusType, RepoPath, RepoPathRef, RepoState, }, sync::{BranchCompare, CommitId}, - AsyncBranchesJob, AsyncDiff, AsyncGitNotification, AsyncStatus, - DiffParams, DiffType, PushType, StatusItem, StatusParams, + AsyncDiff, AsyncGitNotification, AsyncStatus, DiffParams, + DiffType, PushType, StatusItem, StatusParams, }; use crossterm::event::Event; @@ -74,7 +73,6 @@ pub struct Status { git_status_stage: AsyncStatus, git_branch_state: Option, git_branch_name: cached::BranchName, - git_branches: AsyncSingleJob, queue: Queue, git_action_executed: bool, options: SharedOptions, @@ -187,7 +185,6 @@ impl Status { repo_clone, env.sender_git.clone(), ), - git_branches: AsyncSingleJob::new(env.sender_git.clone()), git_action_executed: false, git_branch_state: None, git_branch_name: cached::BranchName::new( @@ -408,22 +405,12 @@ impl Status { self.git_diff.is_pending() || self.git_status_stage.is_pending() || self.git_status_workdir.is_pending() - || self.git_branches.is_pending() } fn check_remotes(&mut self) { - self.has_remotes = false; - - if let Some(result) = self.git_branches.take_last() { - if let Some(Ok(branches)) = result.result() { - self.has_remotes = !branches.is_empty(); - } - } else { - self.git_branches.spawn(AsyncBranchesJob::new( - self.repo.borrow().clone(), - false, - )); - } + self.has_remotes = + sync::get_default_remote(&self.repo.borrow().clone()) + .is_ok(); } /// @@ -609,10 +596,14 @@ impl Status { } fn can_push(&self) -> bool { - self.git_branch_state + let is_ahead = self + .git_branch_state .as_ref() - .map_or(true, |state| state.ahead > 0) - && self.has_remotes + .map_or(true, |state| state.ahead > 0); + + log::info!("can_push: {is_ahead}/{}", self.has_remotes); + + is_ahead && self.has_remotes } const fn can_pull(&self) -> bool { From e55346f3bf89a396f8e6e91f9eabe1bd7ed4d602 Mon Sep 17 00:00:00 2001 From: extrawurst Date: Mon, 19 Feb 2024 15:31:50 +0100 Subject: [PATCH 2/2] cleanup --- CHANGELOG.md | 1 + src/tabs/status.rs | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e0f82ec2c..f7440e1a04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ These defaults require some adoption from existing users but feel more natural t ### Fixes * stash window empty after file history popup closes ([#1986](https://github.com/extrawurst/gitui/issues/1986)) +* allow push to empty remote ([#1919](https://github.com/extrawurst/gitui/issues/1919)) ## [0.24.3] - 2023-09-09 diff --git a/src/tabs/status.rs b/src/tabs/status.rs index 6c4df0e14e..f9d53cf976 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -601,8 +601,6 @@ impl Status { .as_ref() .map_or(true, |state| state.ahead > 0); - log::info!("can_push: {is_ahead}/{}", self.has_remotes); - is_ahead && self.has_remotes }