diff --git a/docs/keybindings.md b/docs/keybindings.md index 2d1a094c..1752407e 100644 --- a/docs/keybindings.md +++ b/docs/keybindings.md @@ -31,6 +31,7 @@ toggle-diff-format = "w" refresh = ["shift+r", "f5"] create-new = "n" create-new-describe = "shift+n" +duplicate = "shift+d" squash = "s" squash-ignore-immutable = "shift+s" edit-change = "e" diff --git a/src/commander/jj.rs b/src/commander/jj.rs index 42bfffbb..9634a8d4 100644 --- a/src/commander/jj.rs +++ b/src/commander/jj.rs @@ -18,6 +18,12 @@ impl Commander { .context("Failed executing jj new") } + /// Duplicate a change. Maps to `jj duplicate` + pub fn run_duplicate(&self, revision: &str) -> Result<()> { + self.execute_void_jj_command(vec!["duplicate", revision]) + .context("Failed executing jj duplicate") + } + /// Edit change. Maps to `jj edit ` #[instrument(level = "trace", skip(self))] pub fn run_edit(&self, revision: &str, ignore_immutable: bool) -> Result<()> { diff --git a/src/keybinds/config.rs b/src/keybinds/config.rs index b11e2161..fd70a7dd 100644 --- a/src/keybinds/config.rs +++ b/src/keybinds/config.rs @@ -30,6 +30,7 @@ pub struct LogTabKeybindsConfig { pub toggle_diff_format: Option, pub refresh: Option, + pub duplicate: Option, pub create_new: Option, pub create_new_describe: Option, pub squash: Option, diff --git a/src/keybinds/log_tab.rs b/src/keybinds/log_tab.rs index cc43f517..1bd43f8f 100644 --- a/src/keybinds/log_tab.rs +++ b/src/keybinds/log_tab.rs @@ -31,6 +31,7 @@ pub enum LogTabEvent { CreateNew { describe: bool, }, + Duplicate, Rebase, Squash { ignore_immutable: bool, @@ -76,6 +77,7 @@ impl Default for LogTabKeybinds { LogTabEvent::ToggleDiffFormat => "w", LogTabEvent::Refresh => "shift+r", LogTabEvent::Refresh => "f5", + LogTabEvent::Duplicate => "shift+d", LogTabEvent::CreateNew { describe: false } => "n", LogTabEvent::CreateNew { describe: true } => "shift+n", LogTabEvent::Rebase => "ctrl+r", @@ -122,6 +124,7 @@ impl LogTabKeybinds { LogTabEvent::FocusCurrent => config.focus_current, LogTabEvent::ToggleDiffFormat => config.toggle_diff_format, LogTabEvent::Refresh => config.refresh, + LogTabEvent::Duplicate => config.duplicate, LogTabEvent::CreateNew { describe: false } => config.create_new, LogTabEvent::CreateNew { describe: true } => config.create_new_describe, LogTabEvent::Squash { ignore_immutable: false } => config.squash, diff --git a/src/ui/log_tab.rs b/src/ui/log_tab.rs index 932588d8..8440b003 100644 --- a/src/ui/log_tab.rs +++ b/src/ui/log_tab.rs @@ -192,6 +192,13 @@ impl<'a> LogTab<'a> { self.log_panel.refresh_log_output(commander); self.refresh_head_output(commander); } + + LogTabEvent::Duplicate => { + let _ = commander.run_duplicate(&self.head.change_id.to_string()); + self.log_panel.refresh_log_output(commander); + self.refresh_head_output(commander); + } + LogTabEvent::CreateNew { describe } => { self.popup = ConfirmDialogState::new( NEW_POPUP_ID,