mirror of
https://github.com/extrawurst/gitui.git
synced 2024-12-28 19:44:14 +03:00
Add no-verify commit command (#1375)
* add no-verify option on commit action * make verify a bool flag on commit component
This commit is contained in:
parent
c7356ae3de
commit
5ca712ff80
@ -55,6 +55,7 @@ pub struct CommitComponent {
|
|||||||
theme: SharedTheme,
|
theme: SharedTheme,
|
||||||
commit_msg_history_idx: usize,
|
commit_msg_history_idx: usize,
|
||||||
options: SharedOptions,
|
options: SharedOptions,
|
||||||
|
verify: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
const FIRST_LINE_LIMIT: usize = 50;
|
const FIRST_LINE_LIMIT: usize = 50;
|
||||||
@ -85,6 +86,7 @@ impl CommitComponent {
|
|||||||
repo,
|
repo,
|
||||||
commit_msg_history_idx: 0,
|
commit_msg_history_idx: 0,
|
||||||
options,
|
options,
|
||||||
|
verify: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,6 +238,11 @@ impl CommitComponent {
|
|||||||
&mut self,
|
&mut self,
|
||||||
msg: String,
|
msg: String,
|
||||||
) -> Result<CommitResult> {
|
) -> Result<CommitResult> {
|
||||||
|
if !self.verify {
|
||||||
|
self.do_commit(&msg)?;
|
||||||
|
self.verify = true;
|
||||||
|
return Ok(CommitResult::ComitDone);
|
||||||
|
}
|
||||||
if let HookResult::NotOk(e) =
|
if let HookResult::NotOk(e) =
|
||||||
sync::hooks_pre_commit(&self.repo.borrow())?
|
sync::hooks_pre_commit(&self.repo.borrow())?
|
||||||
{
|
{
|
||||||
@ -256,18 +263,7 @@ impl CommitComponent {
|
|||||||
return Ok(CommitResult::Aborted);
|
return Ok(CommitResult::Aborted);
|
||||||
}
|
}
|
||||||
|
|
||||||
match &self.mode {
|
self.do_commit(&msg)?;
|
||||||
Mode::Normal => sync::commit(&self.repo.borrow(), &msg)?,
|
|
||||||
Mode::Amend(amend) => {
|
|
||||||
sync::amend(&self.repo.borrow(), *amend, &msg)?
|
|
||||||
}
|
|
||||||
Mode::Merge(ids) => {
|
|
||||||
sync::merge_commit(&self.repo.borrow(), &msg, ids)?
|
|
||||||
}
|
|
||||||
Mode::Revert => {
|
|
||||||
sync::commit_revert(&self.repo.borrow(), &msg)?
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if let HookResult::NotOk(e) =
|
if let HookResult::NotOk(e) =
|
||||||
sync::hooks_post_commit(&self.repo.borrow())?
|
sync::hooks_post_commit(&self.repo.borrow())?
|
||||||
@ -281,6 +277,22 @@ impl CommitComponent {
|
|||||||
Ok(CommitResult::ComitDone)
|
Ok(CommitResult::ComitDone)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn do_commit(&self, msg: &str) -> Result<()> {
|
||||||
|
match &self.mode {
|
||||||
|
Mode::Normal => sync::commit(&self.repo.borrow(), msg)?,
|
||||||
|
Mode::Amend(amend) => {
|
||||||
|
sync::amend(&self.repo.borrow(), *amend, msg)?
|
||||||
|
}
|
||||||
|
Mode::Merge(ids) => {
|
||||||
|
sync::merge_commit(&self.repo.borrow(), msg, ids)?
|
||||||
|
}
|
||||||
|
Mode::Revert => {
|
||||||
|
sync::commit_revert(&self.repo.borrow(), msg)?
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn can_commit(&self) -> bool {
|
fn can_commit(&self) -> bool {
|
||||||
!self.is_empty() && self.is_changed()
|
!self.is_empty() && self.is_changed()
|
||||||
}
|
}
|
||||||
@ -317,6 +329,9 @@ impl CommitComponent {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
fn toggle_verify(&mut self) {
|
||||||
|
self.verify = !self.verify
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DrawableComponent for CommitComponent {
|
impl DrawableComponent for CommitComponent {
|
||||||
@ -350,6 +365,15 @@ impl Component for CommitComponent {
|
|||||||
true,
|
true,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
out.push(CommandInfo::new(
|
||||||
|
strings::commands::toggle_verify(
|
||||||
|
&self.key_config,
|
||||||
|
self.verify,
|
||||||
|
),
|
||||||
|
self.can_commit(),
|
||||||
|
true,
|
||||||
|
));
|
||||||
|
|
||||||
out.push(CommandInfo::new(
|
out.push(CommandInfo::new(
|
||||||
strings::commands::commit_amend(&self.key_config),
|
strings::commands::commit_amend(&self.key_config),
|
||||||
self.can_amend(),
|
self.can_amend(),
|
||||||
@ -391,6 +415,12 @@ impl Component for CommitComponent {
|
|||||||
"commit error:",
|
"commit error:",
|
||||||
self.commit()
|
self.commit()
|
||||||
);
|
);
|
||||||
|
} else if key_match(
|
||||||
|
e,
|
||||||
|
self.key_config.keys.toggle_verify,
|
||||||
|
) && self.can_commit()
|
||||||
|
{
|
||||||
|
self.toggle_verify();
|
||||||
} else if key_match(
|
} else if key_match(
|
||||||
e,
|
e,
|
||||||
self.key_config.keys.commit_amend,
|
self.key_config.keys.commit_amend,
|
||||||
@ -459,6 +489,7 @@ impl Component for CommitComponent {
|
|||||||
.set_text(sync::merge_msg(&self.repo.borrow())?);
|
.set_text(sync::merge_msg(&self.repo.borrow())?);
|
||||||
Mode::Revert
|
Mode::Revert
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
self.commit_template = get_config_string(
|
self.commit_template = get_config_string(
|
||||||
&self.repo.borrow(),
|
&self.repo.borrow(),
|
||||||
|
@ -88,6 +88,7 @@ pub struct KeysList {
|
|||||||
pub log_tag_commit: GituiKeyEvent,
|
pub log_tag_commit: GituiKeyEvent,
|
||||||
pub log_mark_commit: GituiKeyEvent,
|
pub log_mark_commit: GituiKeyEvent,
|
||||||
pub commit_amend: GituiKeyEvent,
|
pub commit_amend: GituiKeyEvent,
|
||||||
|
pub toggle_verify: GituiKeyEvent,
|
||||||
pub copy: GituiKeyEvent,
|
pub copy: GituiKeyEvent,
|
||||||
pub create_branch: GituiKeyEvent,
|
pub create_branch: GituiKeyEvent,
|
||||||
pub rename_branch: GituiKeyEvent,
|
pub rename_branch: GituiKeyEvent,
|
||||||
@ -170,6 +171,7 @@ impl Default for KeysList {
|
|||||||
log_tag_commit: GituiKeyEvent::new(KeyCode::Char('t'), KeyModifiers::empty()),
|
log_tag_commit: GituiKeyEvent::new(KeyCode::Char('t'), KeyModifiers::empty()),
|
||||||
log_mark_commit: GituiKeyEvent::new(KeyCode::Char(' '), KeyModifiers::empty()),
|
log_mark_commit: GituiKeyEvent::new(KeyCode::Char(' '), KeyModifiers::empty()),
|
||||||
commit_amend: GituiKeyEvent::new(KeyCode::Char('a'), KeyModifiers::CONTROL),
|
commit_amend: GituiKeyEvent::new(KeyCode::Char('a'), KeyModifiers::CONTROL),
|
||||||
|
toggle_verify: GituiKeyEvent::new(KeyCode::Char('f'), KeyModifiers::CONTROL),
|
||||||
copy: GituiKeyEvent::new(KeyCode::Char('y'), KeyModifiers::empty()),
|
copy: GituiKeyEvent::new(KeyCode::Char('y'), KeyModifiers::empty()),
|
||||||
create_branch: GituiKeyEvent::new(KeyCode::Char('c'), KeyModifiers::empty()),
|
create_branch: GituiKeyEvent::new(KeyCode::Char('c'), KeyModifiers::empty()),
|
||||||
rename_branch: GituiKeyEvent::new(KeyCode::Char('r'), KeyModifiers::empty()),
|
rename_branch: GituiKeyEvent::new(KeyCode::Char('r'), KeyModifiers::empty()),
|
||||||
|
@ -59,6 +59,7 @@ pub struct KeysListFile {
|
|||||||
pub log_tag_commit: Option<GituiKeyEvent>,
|
pub log_tag_commit: Option<GituiKeyEvent>,
|
||||||
pub log_mark_commit: Option<GituiKeyEvent>,
|
pub log_mark_commit: Option<GituiKeyEvent>,
|
||||||
pub commit_amend: Option<GituiKeyEvent>,
|
pub commit_amend: Option<GituiKeyEvent>,
|
||||||
|
pub toggle_verify: Option<GituiKeyEvent>,
|
||||||
pub copy: Option<GituiKeyEvent>,
|
pub copy: Option<GituiKeyEvent>,
|
||||||
pub create_branch: Option<GituiKeyEvent>,
|
pub create_branch: Option<GituiKeyEvent>,
|
||||||
pub rename_branch: Option<GituiKeyEvent>,
|
pub rename_branch: Option<GituiKeyEvent>,
|
||||||
@ -150,6 +151,7 @@ impl KeysListFile {
|
|||||||
log_tag_commit: self.log_tag_commit.unwrap_or(default.log_tag_commit),
|
log_tag_commit: self.log_tag_commit.unwrap_or(default.log_tag_commit),
|
||||||
log_mark_commit: self.log_mark_commit.unwrap_or(default.log_mark_commit),
|
log_mark_commit: self.log_mark_commit.unwrap_or(default.log_mark_commit),
|
||||||
commit_amend: self.commit_amend.unwrap_or(default.commit_amend),
|
commit_amend: self.commit_amend.unwrap_or(default.commit_amend),
|
||||||
|
toggle_verify: self.toggle_verify.unwrap_or(default.toggle_verify),
|
||||||
copy: self.copy.unwrap_or(default.copy),
|
copy: self.copy.unwrap_or(default.copy),
|
||||||
create_branch: self.create_branch.unwrap_or(default.create_branch),
|
create_branch: self.create_branch.unwrap_or(default.create_branch),
|
||||||
rename_branch: self.rename_branch.unwrap_or(default.rename_branch),
|
rename_branch: self.rename_branch.unwrap_or(default.rename_branch),
|
||||||
|
@ -883,6 +883,22 @@ pub mod commands {
|
|||||||
)
|
)
|
||||||
.hide_help()
|
.hide_help()
|
||||||
}
|
}
|
||||||
|
pub fn toggle_verify(
|
||||||
|
key_config: &SharedKeyConfig,
|
||||||
|
current_verify: bool,
|
||||||
|
) -> CommandText {
|
||||||
|
let verb = if current_verify { "disable" } else { "enable" };
|
||||||
|
CommandText::new(
|
||||||
|
format!(
|
||||||
|
"{} hooks [{}]",
|
||||||
|
verb,
|
||||||
|
key_config.get_hint(key_config.keys.toggle_verify),
|
||||||
|
),
|
||||||
|
"toggle running on commit hooks (available in commit popup)",
|
||||||
|
CMD_GROUP_COMMIT_POPUP,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn commit_amend(key_config: &SharedKeyConfig) -> CommandText {
|
pub fn commit_amend(key_config: &SharedKeyConfig) -> CommandText {
|
||||||
CommandText::new(
|
CommandText::new(
|
||||||
format!(
|
format!(
|
||||||
|
Loading…
Reference in New Issue
Block a user