Skip to content

PoC list submodules #1090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

**submodules view**

![submodules](assets/submodules.png)

### Added
* submodules support ([#1087](https://github.com/extrawurst/gitui/issues/1087))

## [0.21.0] - 2021-08-17

**popup stacking**
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.PHONY: debug build-release release-linux-musl test clippy clippy-pedantic install install-debug

ARGS=-l
# ARGS=-l -d ~/code/git-bare-test.git
# ARGS=-l -d ~/code/extern/pbrt-v4
# ARGS=-l -d ~/code/git-bare-test.git -w ~/code/git-bare-test

profile:
Expand Down
Binary file added assets/submodules.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions asyncgit/src/sync/commits_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ use unicode_truncate::UnicodeTruncateStr;
)]
pub struct CommitId(Oid);

impl Default for CommitId {
fn default() -> Self {
Self(Oid::zero())
}
}

impl CommitId {
/// create new `CommitId`
pub const fn new(id: Oid) -> Self {
Expand Down
4 changes: 4 additions & 0 deletions asyncgit/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mod staging;
mod stash;
mod state;
pub mod status;
mod submodules;
mod tags;
mod tree;
pub mod utils;
Expand Down Expand Up @@ -80,6 +81,9 @@ pub use stash::{
};
pub use state::{repo_state, RepoState};
pub use status::is_workdir_clean;
pub use submodules::{
get_submodules, update_submodule, SubmoduleInfo, SubmoduleStatus,
};
pub use tags::{
delete_tag, get_tags, get_tags_with_metadata, CommitTags, Tag,
TagWithMetadata, Tags,
Expand Down
84 changes: 84 additions & 0 deletions asyncgit/src/sync/submodules.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use std::path::PathBuf;

use git2::SubmoduleUpdateOptions;
use scopetime::scope_time;

use super::{repo, CommitId, RepoPath};
use crate::{error::Result, Error};

pub use git2::SubmoduleStatus;

///
pub struct SubmoduleInfo {
///
pub path: PathBuf,
///
pub url: Option<String>,
///
pub id: Option<CommitId>,
///
pub head_id: Option<CommitId>,
///
pub status: SubmoduleStatus,
}

impl SubmoduleInfo {
///
pub fn get_repo_path(
&self,
repo_path: &RepoPath,
) -> Result<RepoPath> {
let repo = repo(repo_path)?;
let wd = repo.workdir().ok_or(Error::NoWorkDir)?;

Ok(RepoPath::Path(wd.join(self.path.clone())))
}
}

///
pub fn get_submodules(
repo_path: &RepoPath,
) -> Result<Vec<SubmoduleInfo>> {
scope_time!("get_submodules");

let (r, repo2) = (repo(repo_path)?, repo(repo_path)?);

let res = r
.submodules()?
.iter()
.map(|s| {
let status = repo2
.submodule_status(
s.name().unwrap_or_default(),
git2::SubmoduleIgnore::None,
)
.unwrap_or(SubmoduleStatus::empty());

SubmoduleInfo {
path: s.path().to_path_buf(),
id: s.workdir_id().map(CommitId::from),
head_id: s.head_id().map(CommitId::from),
url: s.url().map(String::from),
status,
}
})
.collect();

Ok(res)
}

///
pub fn update_submodule(
repo_path: &RepoPath,
path: &str,
) -> Result<()> {
let repo = repo(repo_path)?;

let mut submodule = repo.find_submodule(path)?;

let mut options = SubmoduleUpdateOptions::new();

submodule.update(true, Some(&mut options))?;

Ok(())
}
14 changes: 13 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use crate::{
MsgComponent, OptionsPopupComponent, PullComponent,
PushComponent, PushTagsComponent, RenameBranchComponent,
RevisionFilesPopup, SharedOptions, StashMsgComponent,
TagCommitComponent, TagListComponent,
SubmodulesListComponent, TagCommitComponent,
TagListComponent,
},
input::{Input, InputEvent, InputState},
keys::{key_match, KeyConfig, SharedKeyConfig},
Expand Down Expand Up @@ -70,6 +71,7 @@ pub struct App {
rename_branch_popup: RenameBranchComponent,
select_branch_popup: BranchListComponent,
options_popup: OptionsPopupComponent,
submodule_popup: SubmodulesListComponent,
tags_popup: TagListComponent,
cmdbar: RefCell<CommandBar>,
tab: usize,
Expand Down Expand Up @@ -231,6 +233,11 @@ impl App {
key_config.clone(),
options.clone(),
),
submodule_popup: SubmodulesListComponent::new(
repo.clone(),
theme.clone(),
key_config.clone(),
),
find_file_popup: FileFindPopup::new(
&queue,
theme.clone(),
Expand Down Expand Up @@ -543,6 +550,7 @@ impl App {
rename_branch_popup,
select_branch_popup,
revision_files_popup,
submodule_popup,
tags_popup,
options_popup,
help,
Expand All @@ -567,6 +575,7 @@ impl App {
external_editor_popup,
tag_commit_popup,
select_branch_popup,
submodule_popup,
tags_popup,
create_branch_popup,
rename_branch_popup,
Expand Down Expand Up @@ -775,6 +784,9 @@ impl App {
InternalEvent::SelectBranch => {
self.select_branch_popup.open()?;
}
InternalEvent::ViewSubmodules => {
self.submodule_popup.open()?;
}
InternalEvent::Tags => {
self.tags_popup.open()?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/branchlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,9 @@ impl BranchListComponent {
const HEAD_SYMBOL: char = '*';
const EMPTY_SYMBOL: char = ' ';
const THREE_DOTS: &str = "...";
const THREE_DOTS_LENGTH: usize = THREE_DOTS.len(); // "..."
const COMMIT_HASH_LENGTH: usize = 8;
const IS_HEAD_STAR_LENGTH: usize = 3; // "* "
const THREE_DOTS_LENGTH: usize = THREE_DOTS.len(); // "..."

let branch_name_length: usize =
width_available as usize * 40 / 100;
Expand Down
2 changes: 2 additions & 0 deletions src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod revision_files;
mod revision_files_popup;
mod stashmsg;
mod status_tree;
mod submodules;
mod syntax_text;
mod tag_commit;
mod taglist;
Expand Down Expand Up @@ -61,6 +62,7 @@ pub use reset::ConfirmComponent;
pub use revision_files::RevisionFilesComponent;
pub use revision_files_popup::{FileTreeOpen, RevisionFilesPopup};
pub use stashmsg::StashMsgComponent;
pub use submodules::SubmodulesListComponent;
pub use syntax_text::SyntaxTextComponent;
pub use tag_commit::TagCommitComponent;
pub use taglist::TagListComponent;
Expand Down
Loading