mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
open external editor from commit popup
this puts all commit logic into one 'view' and allows editing amend commit messages in the external editor aswell.
This commit is contained in:
parent
0a24c2c9b0
commit
60759d7bec
4 changed files with 31 additions and 29 deletions
|
|
@ -236,11 +236,6 @@ impl Component for ChangesComponent {
|
||||||
some_selection,
|
some_selection,
|
||||||
self.focused(),
|
self.focused(),
|
||||||
));
|
));
|
||||||
out.push(CommandInfo::new(
|
|
||||||
commands::COMMIT_OPEN_EDITOR,
|
|
||||||
!self.is_empty(),
|
|
||||||
self.focused() || force_all,
|
|
||||||
));
|
|
||||||
out.push(
|
out.push(
|
||||||
CommandInfo::new(
|
CommandInfo::new(
|
||||||
commands::COMMIT_OPEN,
|
commands::COMMIT_OPEN,
|
||||||
|
|
@ -271,15 +266,6 @@ impl Component for ChangesComponent {
|
||||||
.push_back(InternalEvent::OpenCommit);
|
.push_back(InternalEvent::OpenCommit);
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
keys::OPEN_COMMIT_EDITOR
|
|
||||||
if !self.is_working_dir
|
|
||||||
&& !self.is_empty() =>
|
|
||||||
{
|
|
||||||
self.queue
|
|
||||||
.borrow_mut()
|
|
||||||
.push_back(InternalEvent::SuspendPolling);
|
|
||||||
Ok(true)
|
|
||||||
}
|
|
||||||
keys::STATUS_STAGE_FILE => {
|
keys::STATUS_STAGE_FILE => {
|
||||||
try_or_popup!(
|
try_or_popup!(
|
||||||
self,
|
self,
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,7 @@ use super::{
|
||||||
use crate::{
|
use crate::{
|
||||||
get_app_config_path, keys,
|
get_app_config_path, keys,
|
||||||
queue::{InternalEvent, NeedsUpdate, Queue},
|
queue::{InternalEvent, NeedsUpdate, Queue},
|
||||||
strings,
|
strings::{self, commands},
|
||||||
strings::{commands, COMMIT_EDITOR_MSG},
|
|
||||||
ui::style::SharedTheme,
|
ui::style::SharedTheme,
|
||||||
};
|
};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
|
|
@ -67,6 +66,12 @@ impl Component for CommitComponent {
|
||||||
self.can_amend(),
|
self.can_amend(),
|
||||||
true,
|
true,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
out.push(CommandInfo::new(
|
||||||
|
commands::COMMIT_OPEN_EDITOR,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
visibility_blocking(self)
|
visibility_blocking(self)
|
||||||
|
|
@ -88,6 +93,12 @@ impl Component for CommitComponent {
|
||||||
self.amend()?;
|
self.amend()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keys::OPEN_COMMIT_EDITOR => {
|
||||||
|
self.queue
|
||||||
|
.borrow_mut()
|
||||||
|
.push_back(InternalEvent::SuspendPolling);
|
||||||
|
}
|
||||||
|
|
||||||
_ => (),
|
_ => (),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -137,9 +148,15 @@ impl CommitComponent {
|
||||||
let mut config_path: PathBuf = get_app_config_path()?;
|
let mut config_path: PathBuf = get_app_config_path()?;
|
||||||
config_path.push(COMMIT_MSG_FILE_NAME);
|
config_path.push(COMMIT_MSG_FILE_NAME);
|
||||||
|
|
||||||
let mut file = File::create(&config_path)?;
|
{
|
||||||
file.write_all(COMMIT_EDITOR_MSG.as_bytes())?;
|
//TODO: use a tmpfile here
|
||||||
drop(file);
|
let mut file = File::create(&config_path)?;
|
||||||
|
file.write_fmt(format_args!(
|
||||||
|
"{}\n",
|
||||||
|
self.input.get_text()
|
||||||
|
))?;
|
||||||
|
file.write_all(strings::COMMIT_EDITOR_MSG.as_bytes())?;
|
||||||
|
}
|
||||||
|
|
||||||
let mut editor = env::var("GIT_EDTIOR")
|
let mut editor = env::var("GIT_EDTIOR")
|
||||||
.ok()
|
.ok()
|
||||||
|
|
@ -156,9 +173,8 @@ impl CommitComponent {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
io::stdout().execute(LeaveAlternateScreen)?;
|
io::stdout().execute(LeaveAlternateScreen)?;
|
||||||
|
|
||||||
defer! {
|
defer! {
|
||||||
io::stdout().execute(EnterAlternateScreen).expect("failed to reset terminal");
|
io::stdout().execute(EnterAlternateScreen).expect("reset terminal");
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::new(command)
|
Command::new(command)
|
||||||
|
|
@ -168,6 +184,7 @@ impl CommitComponent {
|
||||||
|
|
||||||
let mut message = String::new();
|
let mut message = String::new();
|
||||||
|
|
||||||
|
//TODO: see above
|
||||||
let mut file = File::open(&config_path)?;
|
let mut file = File::open(&config_path)?;
|
||||||
file.read_to_string(&mut message)?;
|
file.read_to_string(&mut message)?;
|
||||||
drop(file);
|
drop(file);
|
||||||
|
|
@ -184,9 +201,9 @@ impl CommitComponent {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if !message.chars().all(char::is_whitespace) {
|
let message = message.trim().to_string();
|
||||||
return self.commit_msg(message);
|
|
||||||
}
|
self.input.set_text(message);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ pub const EXIT_POPUP: KeyEvent = no_mod(KeyCode::Esc);
|
||||||
pub const CLOSE_MSG: KeyEvent = no_mod(KeyCode::Enter);
|
pub const CLOSE_MSG: KeyEvent = no_mod(KeyCode::Enter);
|
||||||
pub const OPEN_COMMIT: KeyEvent = no_mod(KeyCode::Char('c'));
|
pub const OPEN_COMMIT: KeyEvent = no_mod(KeyCode::Char('c'));
|
||||||
pub const OPEN_COMMIT_EDITOR: KeyEvent =
|
pub const OPEN_COMMIT_EDITOR: KeyEvent =
|
||||||
with_mod(KeyCode::Char('C'), KeyModifiers::SHIFT);
|
with_mod(KeyCode::Char('e'), KeyModifiers::CONTROL);
|
||||||
pub const OPEN_HELP: KeyEvent = no_mod(KeyCode::Char('h'));
|
pub const OPEN_HELP: KeyEvent = no_mod(KeyCode::Char('h'));
|
||||||
pub const MOVE_LEFT: KeyEvent = no_mod(KeyCode::Left);
|
pub const MOVE_LEFT: KeyEvent = no_mod(KeyCode::Left);
|
||||||
pub const MOVE_RIGHT: KeyEvent = no_mod(KeyCode::Right);
|
pub const MOVE_RIGHT: KeyEvent = no_mod(KeyCode::Right);
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,8 @@ pub static COMMIT_TITLE: &str = "Commit";
|
||||||
pub static COMMIT_TITLE_AMEND: &str = "Commit (Amend)";
|
pub static COMMIT_TITLE_AMEND: &str = "Commit (Amend)";
|
||||||
pub static COMMIT_MSG: &str = "type commit message..";
|
pub static COMMIT_MSG: &str = "type commit message..";
|
||||||
pub static COMMIT_EDITOR_MSG: &str = r##"
|
pub static COMMIT_EDITOR_MSG: &str = r##"
|
||||||
# Enter your commit message
|
# Edit your commit message
|
||||||
# Lines starting with '#' will be ignored
|
# Lines starting with '#' will be ignored"##;
|
||||||
# Empty commit message will abort the commit"##;
|
|
||||||
pub static STASH_POPUP_TITLE: &str = "Stash";
|
pub static STASH_POPUP_TITLE: &str = "Stash";
|
||||||
pub static STASH_POPUP_MSG: &str = "type name (optional)";
|
pub static STASH_POPUP_MSG: &str = "type name (optional)";
|
||||||
pub static CONFIRM_TITLE_RESET: &str = "Reset";
|
pub static CONFIRM_TITLE_RESET: &str = "Reset";
|
||||||
|
|
@ -155,7 +154,7 @@ pub mod commands {
|
||||||
);
|
);
|
||||||
///
|
///
|
||||||
pub static COMMIT_OPEN_EDITOR: CommandText = CommandText::new(
|
pub static COMMIT_OPEN_EDITOR: CommandText = CommandText::new(
|
||||||
"Commit editor [C]",
|
"Open editor [^e]",
|
||||||
"open commit editor (available in non-empty stage)",
|
"open commit editor (available in non-empty stage)",
|
||||||
CMD_GROUP_COMMIT,
|
CMD_GROUP_COMMIT,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue