allow pushing to empty repo (#2063)

closes #1919
This commit is contained in:
extrawurst 2024-02-19 15:46:39 +01:00 committed by GitHub
parent be10d9096a
commit ab95b98ef8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 21 deletions

View file

@ -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

View file

@ -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<BranchCompare>,
git_branch_name: cached::BranchName,
git_branches: AsyncSingleJob<AsyncBranchesJob>,
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,12 @@ 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);
is_ahead && self.has_remotes
}
const fn can_pull(&self) -> bool {