Skip to content

Commit

Permalink
Remotes popup (#2350)
Browse files Browse the repository at this point in the history
Co-authored-by: extrawurst <[email protected]>
Co-authored-by: extrawurst <[email protected]>
  • Loading branch information
3 people authored Sep 18, 2024
1 parent 2cbeeed commit d4f9400
Show file tree
Hide file tree
Showing 15 changed files with 1,433 additions and 117 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixes
* respect env vars like `GIT_CONFIG_GLOBAL` ([#2298](https://github.com/extrawurst/gitui/issues/2298))

### Added
* add popups for viewing, adding, updating and removing remotes [[@robin-thoene](https://github.com/robin-thoene)] ([#2172](https://github.com/extrawurst/gitui/issues/2172))

## [0.26.3] - 2024-06-02

### Breaking Changes
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ log = "0.4"
notify = "6.1"
notify-debouncer-mini = "0.4"
once_cell = "1"
# pin until upgrading this does not introduce a duplicte dependency
# pin until upgrading this does not introduce a duplicate dependency
parking_lot_core = "=0.9.9"
ratatui = { version = "0.28", default-features = false, features = [
'crossterm',
Expand Down
7 changes: 4 additions & 3 deletions asyncgit/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ pub use merge::{
};
pub use rebase::rebase_branch;
pub use remotes::{
get_default_remote, get_default_remote_for_fetch,
get_default_remote_for_push, get_remotes, push::AsyncProgress,
tags::PushTagsProgress,
add_remote, delete_remote, get_default_remote,
get_default_remote_for_fetch, get_default_remote_for_push,
get_remote_url, get_remotes, push::AsyncProgress, rename_remote,
tags::PushTagsProgress, update_remote_url, validate_remote_name,
};
pub(crate) use repository::repo;
pub use repository::{RepoPath, RepoPathRef};
Expand Down
66 changes: 65 additions & 1 deletion asyncgit/src/sync/remotes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use crate::{
ProgressPercent,
};
use crossbeam_channel::Sender;
use git2::{BranchType, FetchOptions, ProxyOptions, Repository};
use git2::{
BranchType, FetchOptions, ProxyOptions, Remote, Repository,
};
use scopetime::scope_time;
use utils::bytes2string;

Expand All @@ -32,6 +34,54 @@ pub fn proxy_auto<'a>() -> ProxyOptions<'a> {
proxy
}

///
pub fn add_remote(
repo_path: &RepoPath,
name: &str,
url: &str,
) -> Result<()> {
let repo = repo(repo_path)?;
repo.remote(name, url)?;
Ok(())
}

///
pub fn rename_remote(
repo_path: &RepoPath,
name: &str,
new_name: &str,
) -> Result<()> {
let repo = repo(repo_path)?;
repo.remote_rename(name, new_name)?;
Ok(())
}

///
pub fn update_remote_url(
repo_path: &RepoPath,
name: &str,
new_url: &str,
) -> Result<()> {
let repo = repo(repo_path)?;
repo.remote_set_url(name, new_url)?;
Ok(())
}

///
pub fn delete_remote(
repo_path: &RepoPath,
remote_name: &str,
) -> Result<()> {
let repo = repo(repo_path)?;
repo.remote_delete(remote_name)?;
Ok(())
}

///
pub fn validate_remote_name(name: &str) -> bool {
Remote::is_valid_name(name)
}

///
pub fn get_remotes(repo_path: &RepoPath) -> Result<Vec<String>> {
scope_time!("get_remotes");
Expand All @@ -44,6 +94,20 @@ pub fn get_remotes(repo_path: &RepoPath) -> Result<Vec<String>> {
Ok(remotes)
}

///
pub fn get_remote_url(
repo_path: &RepoPath,
remote_name: &str,
) -> Result<Option<String>> {
let repo = repo(repo_path)?;
let remote = repo.find_remote(remote_name)?.clone();
let url = remote.url();
if let Some(u) = url {
return Ok(Some(u.to_string()));
}
Ok(None)
}

/// tries to find origin or the only remote that is defined if any
/// in case of multiple remotes and none named *origin* we fail
pub fn get_default_remote(repo_path: &RepoPath) -> Result<String> {
Expand Down
68 changes: 61 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ use crate::{
popups::{
AppOption, BlameFilePopup, BranchListPopup, CommitPopup,
CompareCommitsPopup, ConfirmPopup, CreateBranchPopup,
ExternalEditorPopup, FetchPopup, FileRevlogPopup,
FuzzyFindPopup, HelpPopup, InspectCommitPopup,
LogSearchPopupPopup, MsgPopup, OptionsPopup, PullPopup,
PushPopup, PushTagsPopup, RenameBranchPopup, ResetPopup,
RevisionFilesPopup, StashMsgPopup, SubmodulesListPopup,
TagCommitPopup, TagListPopup,
CreateRemotePopup, ExternalEditorPopup, FetchPopup,
FileRevlogPopup, FuzzyFindPopup, HelpPopup,
InspectCommitPopup, LogSearchPopupPopup, MsgPopup,
OptionsPopup, PullPopup, PushPopup, PushTagsPopup,
RemoteListPopup, RenameBranchPopup, RenameRemotePopup,
ResetPopup, RevisionFilesPopup, StashMsgPopup,
SubmodulesListPopup, TagCommitPopup, TagListPopup,
UpdateRemoteUrlPopup,
},
queue::{
Action, AppTabs, InternalEvent, NeedsUpdate, Queue,
Expand Down Expand Up @@ -86,6 +88,10 @@ pub struct App {
fetch_popup: FetchPopup,
tag_commit_popup: TagCommitPopup,
create_branch_popup: CreateBranchPopup,
create_remote_popup: CreateRemotePopup,
rename_remote_popup: RenameRemotePopup,
update_remote_url_popup: UpdateRemoteUrlPopup,
remotes_popup: RemoteListPopup,
rename_branch_popup: RenameBranchPopup,
select_branch_popup: BranchListPopup,
options_popup: OptionsPopup,
Expand Down Expand Up @@ -189,6 +195,10 @@ impl App {
fetch_popup: FetchPopup::new(&env),
tag_commit_popup: TagCommitPopup::new(&env),
create_branch_popup: CreateBranchPopup::new(&env),
create_remote_popup: CreateRemotePopup::new(&env),
rename_remote_popup: RenameRemotePopup::new(&env),
update_remote_url_popup: UpdateRemoteUrlPopup::new(&env),
remotes_popup: RemoteListPopup::new(&env),
rename_branch_popup: RenameBranchPopup::new(&env),
select_branch_popup: BranchListPopup::new(&env),
tags_popup: TagListPopup::new(&env),
Expand Down Expand Up @@ -484,6 +494,10 @@ impl App {
tag_commit_popup,
reset_popup,
create_branch_popup,
create_remote_popup,
rename_remote_popup,
update_remote_url_popup,
remotes_popup,
rename_branch_popup,
select_branch_popup,
revision_files_popup,
Expand Down Expand Up @@ -512,6 +526,10 @@ impl App {
external_editor_popup,
tag_commit_popup,
select_branch_popup,
remotes_popup,
create_remote_popup,
rename_remote_popup,
update_remote_url_popup,
submodule_popup,
tags_popup,
reset_popup,
Expand Down Expand Up @@ -646,6 +664,9 @@ impl App {
if flags.contains(NeedsUpdate::BRANCHES) {
self.select_branch_popup.update_branches()?;
}
if flags.contains(NeedsUpdate::REMOTES) {
self.remotes_popup.update_remotes()?;
}

Ok(())
}
Expand Down Expand Up @@ -727,7 +748,19 @@ impl App {
InternalEvent::TagCommit(id) => {
self.tag_commit_popup.open(id)?;
}

InternalEvent::CreateRemote => {
self.create_remote_popup.open()?;
}
InternalEvent::RenameRemote(cur_name) => {
self.rename_remote_popup.open(cur_name)?;
}
InternalEvent::UpdateRemoteUrl(remote_name, cur_url) => {
self.update_remote_url_popup
.open(remote_name, cur_url)?;
}
InternalEvent::ViewRemotes => {
self.remotes_popup.open()?;
}
InternalEvent::CreateBranch => {
self.create_branch_popup.open()?;
}
Expand Down Expand Up @@ -926,6 +959,9 @@ impl App {
Action::DeleteRemoteBranch(branch_ref) => {
self.delete_remote_branch(&branch_ref)?;
}
Action::DeleteRemote(remote_name) => {
self.delete_remote(&remote_name);
}
Action::DeleteTag(tag_name) => {
self.delete_tag(tag_name)?;
}
Expand Down Expand Up @@ -1015,6 +1051,24 @@ impl App {
Ok(())
}

fn delete_remote(&self, remote_name: &str) {
let res =
sync::delete_remote(&self.repo.borrow(), remote_name);
match res {
Ok(()) => {
self.queue.push(InternalEvent::Update(
NeedsUpdate::ALL | NeedsUpdate::REMOTES,
));
}
Err(e) => {
log::error!("delete remote: {}", e,);
self.queue.push(InternalEvent::ShowErrorMsg(
format!("delete remote error:\n{e}",),
));
}
}
}

fn commands(&self, force_all: bool) -> Vec<CommandInfo> {
let mut res = Vec::new();

Expand Down
10 changes: 10 additions & 0 deletions src/keys/key_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ pub struct KeysList {
pub stage_unstage_item: GituiKeyEvent,
pub tag_annotate: GituiKeyEvent,
pub view_submodules: GituiKeyEvent,
pub view_remotes: GituiKeyEvent,
pub update_remote_name: GituiKeyEvent,
pub update_remote_url: GituiKeyEvent,
pub add_remote: GituiKeyEvent,
pub delete_remote: GituiKeyEvent,
pub view_submodule_parent: GituiKeyEvent,
pub update_submodule: GituiKeyEvent,
pub commit_history_next: GituiKeyEvent,
Expand Down Expand Up @@ -210,6 +215,11 @@ impl Default for KeysList {
stage_unstage_item: GituiKeyEvent::new(KeyCode::Enter, KeyModifiers::empty()),
tag_annotate: GituiKeyEvent::new(KeyCode::Char('a'), KeyModifiers::CONTROL),
view_submodules: GituiKeyEvent::new(KeyCode::Char('S'), KeyModifiers::SHIFT),
view_remotes: GituiKeyEvent::new(KeyCode::Char('r'), KeyModifiers::CONTROL),
update_remote_name: GituiKeyEvent::new(KeyCode::Char('n'),KeyModifiers::NONE),
update_remote_url: GituiKeyEvent::new(KeyCode::Char('u'),KeyModifiers::NONE),
add_remote: GituiKeyEvent::new(KeyCode::Char('a'), KeyModifiers::NONE),
delete_remote: GituiKeyEvent::new(KeyCode::Char('r'), KeyModifiers::NONE),
view_submodule_parent: GituiKeyEvent::new(KeyCode::Char('p'), KeyModifiers::empty()),
update_submodule: GituiKeyEvent::new(KeyCode::Char('u'), KeyModifiers::empty()),
commit_history_next: GituiKeyEvent::new(KeyCode::Char('n'), KeyModifiers::CONTROL),
Expand Down
Loading

0 comments on commit d4f9400

Please sign in to comment.