Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
* support 'n'/'p' key to move to the next/prev hunk in diff component [[@hamflx](https://github.com/hamflx)] ([#1523](https://github.com/extrawurst/gitui/issues/1523))
* simplify theme overrides [[@cruessler](https://github.com/cruessler)] ([#1367](https://github.com/extrawurst/gitui/issues/1367))
* support for sign-off of commits [[@domtac](https://github.com/domtac)]([#1757](https://github.com/extrawurst/gitui/issues/1757))

### Fixes
* fix commit dialog char count for multibyte characters ([#1726](https://github.com/extrawurst/gitui/issues/1726))
Expand Down
44 changes: 44 additions & 0 deletions src/components/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ impl CommitComponent {
return Ok(CommitResult::Aborted);
}
}

let mut msg = message_prettify(msg, Some(b'#'))?;

if verify {
// run commit message check hook - can reject commit
if let HookResult::NotOk(e) =
Expand Down Expand Up @@ -341,6 +343,13 @@ impl CommitComponent {

Ok(())
}
fn signoff_commit(&mut self) {
let msg = self.input.get_text();
let signed_msg = self.add_sign_off(msg);
if let std::result::Result::Ok(signed_msg) = signed_msg {
self.input.set_text(signed_msg);
}
}
fn toggle_verify(&mut self) {
self.verify = !self.verify;
}
Expand Down Expand Up @@ -416,6 +425,30 @@ impl CommitComponent {

Ok(())
}

fn add_sign_off(&self, msg: &str) -> Result<String> {
const CONFIG_KEY_USER_NAME: &str = "user.name";
const CONFIG_KEY_USER_MAIL: &str = "user.email";

let user = get_config_string(
&self.repo.borrow(),
CONFIG_KEY_USER_NAME,
)?;

let mail = get_config_string(
&self.repo.borrow(),
CONFIG_KEY_USER_MAIL,
)?;

let mut msg = msg.to_owned();
if let (Some(user), Some(mail)) = (user, mail) {
msg.push_str(&format!(
"\n\nSigned-off-by {user} <{mail}>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's the : missing after the key of the trailer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reported in #2196.

));
}

Ok(msg)
}
}

impl DrawableComponent for CommitComponent {
Expand Down Expand Up @@ -464,6 +497,12 @@ impl Component for CommitComponent {
true,
));

out.push(CommandInfo::new(
strings::commands::commit_signoff(&self.key_config),
true,
true,
));

out.push(CommandInfo::new(
strings::commands::commit_open_editor(
&self.key_config,
Expand Down Expand Up @@ -531,6 +570,11 @@ impl Component for CommitComponent {
self.input.set_text(msg);
self.commit_msg_history_idx += 1;
}
} else if key_match(
e,
self.key_config.keys.toggle_signoff,
) {
self.signoff_commit();
}
// stop key event propagation
return Ok(EventState::Consumed);
Expand Down
2 changes: 2 additions & 0 deletions src/keys/key_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub struct KeysList {
pub log_reset_comit: GituiKeyEvent,
pub log_reword_comit: GituiKeyEvent,
pub commit_amend: GituiKeyEvent,
pub toggle_signoff: GituiKeyEvent,
pub toggle_verify: GituiKeyEvent,
pub copy: GituiKeyEvent,
pub create_branch: GituiKeyEvent,
Expand Down Expand Up @@ -174,6 +175,7 @@ impl Default for KeysList {
log_reset_comit: GituiKeyEvent { code: KeyCode::Char('R'), modifiers: KeyModifiers::SHIFT },
log_reword_comit: GituiKeyEvent { code: KeyCode::Char('r'), modifiers: KeyModifiers::empty() },
commit_amend: GituiKeyEvent::new(KeyCode::Char('a'), KeyModifiers::CONTROL),
toggle_signoff: GituiKeyEvent::new(KeyCode::Char('s'), KeyModifiers::CONTROL),
toggle_verify: GituiKeyEvent::new(KeyCode::Char('f'), KeyModifiers::CONTROL),
copy: GituiKeyEvent::new(KeyCode::Char('y'), KeyModifiers::empty()),
create_branch: GituiKeyEvent::new(KeyCode::Char('c'), KeyModifiers::empty()),
Expand Down
12 changes: 12 additions & 0 deletions src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,18 @@ pub mod commands {
CMD_GROUP_COMMIT_POPUP,
)
}
pub fn commit_signoff(
key_config: &SharedKeyConfig,
) -> CommandText {
CommandText::new(
format!(
"Sing-off [{}]",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthiasbeyer this PR is already merged, could you open a PR fixing the typos?

key_config.get_hint(key_config.keys.toggle_signoff),
),
"sign-off commit (-s option)",
CMD_GROUP_COMMIT_POPUP,
)
}
pub fn edit_item(key_config: &SharedKeyConfig) -> CommandText {
CommandText::new(
format!(
Expand Down