Display commit changes (#1420)

When using an external editor to edit the commit message, the changes are now displayed
This commit is contained in:
bc-universe 2022-11-13 11:18:59 +01:00 committed by extrawurst
parent 8da9cfc21d
commit 9b46bb63f9
4 changed files with 41 additions and 7 deletions

View file

@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased ## Unreleased
### Added
* changes in commit message inside external editor [[@bc-universe]](https://github.com/bc-universe) ([#1420](https://github.com/extrawurst/gitui/issues/1420))
### Fixes ### Fixes
* commit msg history ordered the wrong way ([#1445](https://github.com/extrawurst/gitui/issues/1445)) * commit msg history ordered the wrong way ([#1445](https://github.com/extrawurst/gitui/issues/1445))
* improve help documentation for amend cmd ([#1448](https://github.com/extrawurst/gitui/issues/1448)) * improve help documentation for amend cmd ([#1448](https://github.com/extrawurst/gitui/issues/1448))

View file

@ -446,14 +446,16 @@ impl App {
} else if let InputEvent::State(polling_state) = ev { } else if let InputEvent::State(polling_state) = ev {
self.external_editor_popup.hide(); self.external_editor_popup.hide();
if matches!(polling_state, InputState::Paused) { if matches!(polling_state, InputState::Paused) {
let result = match self.file_to_open.take() { let result =
Some(path) => { if let Some(path) = self.file_to_open.take() {
ExternalEditorComponent::open_file_in_editor( ExternalEditorComponent::open_file_in_editor(
&self.repo.borrow(), &self.repo.borrow(),
Path::new(&path), Path::new(&path),
) )
} } else {
None => self.commit.show_editor(), let changes =
self.status_tab.get_files_changes()?;
self.commit.show_editor(changes)
}; };
if let Err(e) = result { if let Err(e) = result {

View file

@ -17,6 +17,7 @@ use asyncgit::{
self, get_config_string, CommitId, HookResult, RepoPathRef, self, get_config_string, CommitId, HookResult, RepoPathRef,
RepoState, RepoState,
}, },
StatusItem, StatusItemType,
}; };
use crossterm::event::Event; use crossterm::event::Event;
use easy_cast::Cast; use easy_cast::Cast;
@ -139,7 +140,23 @@ impl CommitComponent {
} }
} }
pub fn show_editor(&mut self) -> Result<()> { const fn item_status_char(
item_type: StatusItemType,
) -> &'static str {
match item_type {
StatusItemType::Modified => "modified",
StatusItemType::New => "new file",
StatusItemType::Deleted => "deleted",
StatusItemType::Renamed => "renamed",
StatusItemType::Typechange => " ",
StatusItemType::Conflicted => "conflicted",
}
}
pub fn show_editor(
&mut self,
changes: Vec<StatusItem>,
) -> Result<()> {
let file_path = sync::repo_dir(&self.repo.borrow())? let file_path = sync::repo_dir(&self.repo.borrow())?
.join("COMMIT_EDITMSG"); .join("COMMIT_EDITMSG");
@ -153,6 +170,14 @@ impl CommitComponent {
strings::commit_editor_msg(&self.key_config) strings::commit_editor_msg(&self.key_config)
.as_bytes(), .as_bytes(),
)?; )?;
for change in changes {
let status_char =
Self::item_status_char(change.status);
let message =
format!("\n#\t{status_char}: {}", change.path);
file.write_all(message.as_bytes())?;
}
} }
ExternalEditorComponent::open_file_in_editor( ExternalEditorComponent::open_file_in_editor(

View file

@ -21,7 +21,7 @@ use asyncgit::{
}, },
sync::{BranchCompare, CommitId}, sync::{BranchCompare, CommitId},
AsyncBranchesJob, AsyncDiff, AsyncGitNotification, AsyncStatus, AsyncBranchesJob, AsyncDiff, AsyncGitNotification, AsyncStatus,
DiffParams, DiffType, PushType, StatusParams, DiffParams, DiffType, PushType, StatusItem, StatusParams,
}; };
use crossbeam_channel::Sender; use crossbeam_channel::Sender;
use crossterm::event::Event; use crossterm::event::Event;
@ -465,6 +465,10 @@ impl Status {
Ok(()) Ok(())
} }
pub fn get_files_changes(&mut self) -> Result<Vec<StatusItem>> {
Ok(self.git_status_stage.last()?.items)
}
fn update_status(&mut self) -> Result<()> { fn update_status(&mut self) -> Result<()> {
let stage_status = self.git_status_stage.last()?; let stage_status = self.git_status_stage.last()?;
self.index.set_items(&stage_status.items)?; self.index.set_items(&stage_status.items)?;