Skip to content

Commit dba5206

Browse files
authored
Feat 1757 add signoff option (#1758)
1 parent 77f6725 commit dba5206

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
### Added
1919
* 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))
2020
* simplify theme overrides [[@cruessler](https://github.com/cruessler)] ([#1367](https://github.com/extrawurst/gitui/issues/1367))
21+
* support for sign-off of commits [[@domtac](https://github.com/domtac)]([#1757](https://github.com/extrawurst/gitui/issues/1757))
2122

2223
### Fixes
2324
* fix commit dialog char count for multibyte characters ([#1726](https://github.com/extrawurst/gitui/issues/1726))

src/components/commit.rs

+44
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ impl CommitComponent {
255255
return Ok(CommitResult::Aborted);
256256
}
257257
}
258+
258259
let mut msg = message_prettify(msg, Some(b'#'))?;
260+
259261
if verify {
260262
// run commit message check hook - can reject commit
261263
if let HookResult::NotOk(e) =
@@ -341,6 +343,13 @@ impl CommitComponent {
341343

342344
Ok(())
343345
}
346+
fn signoff_commit(&mut self) {
347+
let msg = self.input.get_text();
348+
let signed_msg = self.add_sign_off(msg);
349+
if let std::result::Result::Ok(signed_msg) = signed_msg {
350+
self.input.set_text(signed_msg);
351+
}
352+
}
344353
fn toggle_verify(&mut self) {
345354
self.verify = !self.verify;
346355
}
@@ -416,6 +425,30 @@ impl CommitComponent {
416425

417426
Ok(())
418427
}
428+
429+
fn add_sign_off(&self, msg: &str) -> Result<String> {
430+
const CONFIG_KEY_USER_NAME: &str = "user.name";
431+
const CONFIG_KEY_USER_MAIL: &str = "user.email";
432+
433+
let user = get_config_string(
434+
&self.repo.borrow(),
435+
CONFIG_KEY_USER_NAME,
436+
)?;
437+
438+
let mail = get_config_string(
439+
&self.repo.borrow(),
440+
CONFIG_KEY_USER_MAIL,
441+
)?;
442+
443+
let mut msg = msg.to_owned();
444+
if let (Some(user), Some(mail)) = (user, mail) {
445+
msg.push_str(&format!(
446+
"\n\nSigned-off-by {user} <{mail}>"
447+
));
448+
}
449+
450+
Ok(msg)
451+
}
419452
}
420453

421454
impl DrawableComponent for CommitComponent {
@@ -464,6 +497,12 @@ impl Component for CommitComponent {
464497
true,
465498
));
466499

500+
out.push(CommandInfo::new(
501+
strings::commands::commit_signoff(&self.key_config),
502+
true,
503+
true,
504+
));
505+
467506
out.push(CommandInfo::new(
468507
strings::commands::commit_open_editor(
469508
&self.key_config,
@@ -531,6 +570,11 @@ impl Component for CommitComponent {
531570
self.input.set_text(msg);
532571
self.commit_msg_history_idx += 1;
533572
}
573+
} else if key_match(
574+
e,
575+
self.key_config.keys.toggle_signoff,
576+
) {
577+
self.signoff_commit();
534578
}
535579
// stop key event propagation
536580
return Ok(EventState::Consumed);

src/keys/key_list.rs

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ pub struct KeysList {
8888
pub log_reset_comit: GituiKeyEvent,
8989
pub log_reword_comit: GituiKeyEvent,
9090
pub commit_amend: GituiKeyEvent,
91+
pub toggle_signoff: GituiKeyEvent,
9192
pub toggle_verify: GituiKeyEvent,
9293
pub copy: GituiKeyEvent,
9394
pub create_branch: GituiKeyEvent,
@@ -174,6 +175,7 @@ impl Default for KeysList {
174175
log_reset_comit: GituiKeyEvent { code: KeyCode::Char('R'), modifiers: KeyModifiers::SHIFT },
175176
log_reword_comit: GituiKeyEvent { code: KeyCode::Char('r'), modifiers: KeyModifiers::empty() },
176177
commit_amend: GituiKeyEvent::new(KeyCode::Char('a'), KeyModifiers::CONTROL),
178+
toggle_signoff: GituiKeyEvent::new(KeyCode::Char('s'), KeyModifiers::CONTROL),
177179
toggle_verify: GituiKeyEvent::new(KeyCode::Char('f'), KeyModifiers::CONTROL),
178180
copy: GituiKeyEvent::new(KeyCode::Char('y'), KeyModifiers::empty()),
179181
create_branch: GituiKeyEvent::new(KeyCode::Char('c'), KeyModifiers::empty()),

src/strings.rs

+12
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,18 @@ pub mod commands {
980980
CMD_GROUP_COMMIT_POPUP,
981981
)
982982
}
983+
pub fn commit_signoff(
984+
key_config: &SharedKeyConfig,
985+
) -> CommandText {
986+
CommandText::new(
987+
format!(
988+
"Sing-off [{}]",
989+
key_config.get_hint(key_config.keys.toggle_signoff),
990+
),
991+
"sign-off commit (-s option)",
992+
CMD_GROUP_COMMIT_POPUP,
993+
)
994+
}
983995
pub fn edit_item(key_config: &SharedKeyConfig) -> CommandText {
984996
CommandText::new(
985997
format!(

0 commit comments

Comments
 (0)