mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-23 03:32:30 +03:00
Display commit changes (#1420)
When using an external editor to edit the commit message, the changes are now displayed
This commit is contained in:
parent
8da9cfc21d
commit
9b46bb63f9
@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## 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
|
||||
* 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))
|
||||
|
12
src/app.rs
12
src/app.rs
@ -446,15 +446,17 @@ impl App {
|
||||
} else if let InputEvent::State(polling_state) = ev {
|
||||
self.external_editor_popup.hide();
|
||||
if matches!(polling_state, InputState::Paused) {
|
||||
let result = match self.file_to_open.take() {
|
||||
Some(path) => {
|
||||
let result =
|
||||
if let Some(path) = self.file_to_open.take() {
|
||||
ExternalEditorComponent::open_file_in_editor(
|
||||
&self.repo.borrow(),
|
||||
Path::new(&path),
|
||||
)
|
||||
}
|
||||
None => self.commit.show_editor(),
|
||||
};
|
||||
} else {
|
||||
let changes =
|
||||
self.status_tab.get_files_changes()?;
|
||||
self.commit.show_editor(changes)
|
||||
};
|
||||
|
||||
if let Err(e) = result {
|
||||
let msg =
|
||||
|
@ -17,6 +17,7 @@ use asyncgit::{
|
||||
self, get_config_string, CommitId, HookResult, RepoPathRef,
|
||||
RepoState,
|
||||
},
|
||||
StatusItem, StatusItemType,
|
||||
};
|
||||
use crossterm::event::Event;
|
||||
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())?
|
||||
.join("COMMIT_EDITMSG");
|
||||
|
||||
@ -153,6 +170,14 @@ impl CommitComponent {
|
||||
strings::commit_editor_msg(&self.key_config)
|
||||
.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(
|
||||
|
@ -21,7 +21,7 @@ use asyncgit::{
|
||||
},
|
||||
sync::{BranchCompare, CommitId},
|
||||
AsyncBranchesJob, AsyncDiff, AsyncGitNotification, AsyncStatus,
|
||||
DiffParams, DiffType, PushType, StatusParams,
|
||||
DiffParams, DiffType, PushType, StatusItem, StatusParams,
|
||||
};
|
||||
use crossbeam_channel::Sender;
|
||||
use crossterm::event::Event;
|
||||
@ -465,6 +465,10 @@ impl Status {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_files_changes(&mut self) -> Result<Vec<StatusItem>> {
|
||||
Ok(self.git_status_stage.last()?.items)
|
||||
}
|
||||
|
||||
fn update_status(&mut self) -> Result<()> {
|
||||
let stage_status = self.git_status_stage.last()?;
|
||||
self.index.set_items(&stage_status.items)?;
|
||||
|
Loading…
Reference in New Issue
Block a user