Skip to content

A visual git client, simple to use yet powerful. Light, fast and debloated.

Rust

feat: gitcraft 0.3.2 - edit commit messages in place, pull from the remote pill, update indicator first

Iván8a4b5896cf5f
diff --git a/Cargo.lock b/Cargo.lock
index 916096b..fe8c980 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1447,7 +1447,7 @@ dependencies = [
[[package]]
name = "gitcraft"
-version = "0.3.1"
+version = "0.3.2"
dependencies = [
"eframe",
"egui",
diff --git a/Cargo.toml b/Cargo.toml
index 189cfbb..b787d33 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "gitcraft"
-version = "0.3.1"
+version = "0.3.2"
edition = "2024"
rust-version = "1.95"
license = "MIT OR Apache-2.0"
diff --git a/src/app.rs b/src/app.rs
index d1e2345..e85aae2 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -432,36 +432,6 @@ impl App {
if icons::bar_button(ui, "settings", "Settings").clicked() {
self.settings_open = true;
}
- if let Some(release) = self.update.clone() {
- let pill = ui.add(
- egui::Button::new(
- RichText::new(format!("v{} available", release.version))
- .color(t.accent_text)
- .font(theme::medium(11.5)),
- )
- .fill(t.accent)
- .corner_radius(10.0),
- );
- egui::Popup::menu(&pill)
- .style(crate::theme::menu_style)
- .show(|ui| {
- ui.label(
- RichText::new(format!(
- "gitcraft {} is out (you have {}).",
- release.version,
- update::CURRENT
- ))
- .color(t.text_dim),
- );
- if ui.button("Open the release page").clicked() {
- let _ = open::that_detached(&release.url);
- }
- if ui.button("Skip this version").clicked() {
- self.skipped_version = release.version.clone();
- self.update = None;
- }
- });
- }
if icons::bar_button(ui, "command", "Command palette (Ctrl+P)").clicked() {
self.open_palette();
}
@@ -485,6 +455,49 @@ impl App {
{
self.manual_open = true;
}
+ // A newer release: first in the row, before the icons.
+ if let Some(release) = self.update.clone() {
+ ui.add_space(4.0);
+ let pill = ui.add(
+ egui::Button::new(
+ RichText::new(format!("v{} available", release.version))
+ .color(t.accent_text)
+ .font(theme::medium(11.5)),
+ )
+ .fill(t.accent)
+ .corner_radius(10.0),
+ );
+ egui::Popup::menu(&pill)
+ .style(crate::theme::menu_style)
+ .show(|ui| {
+ // Menus have no side margin (their buttons pad themselves); the
+ // text gets the buttons' own.
+ egui::Frame::new()
+ .inner_margin(egui::Margin {
+ left: 16,
+ right: 16,
+ top: 4,
+ bottom: 8,
+ })
+ .show(ui, |ui| {
+ ui.label(
+ RichText::new(format!(
+ "gitcraft {} is out (you have {}).",
+ release.version,
+ update::CURRENT
+ ))
+ .color(t.text_dim),
+ );
+ });
+ if ui.button("Open the release page").clicked() {
+ let _ = open::that_detached(&release.url);
+ }
+ if ui.button("Skip this version").clicked() {
+ self.skipped_version = release.version.clone();
+ self.update = None;
+ }
+ });
+ }
});
});
if let Some(i) = select {
diff --git a/src/git.rs b/src/git.rs
index a33b710..dcfa80b 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -370,6 +370,10 @@ pub struct CommitDetail {
pub commit_date: String,
pub message: String,
pub files: Vec<ChangedFile>,
+ /// Whether the checked-out branch (HEAD) contains it, so its message can be edited.
+ pub in_head: bool,
+ /// Whether HEAD has merges after it, which rewording it by a rebase would flatten.
+ pub merges_after: bool,
}
pub fn commit_detail(repo: &Path, hash: &str) -> Result<CommitDetail, String> {
@@ -412,6 +416,13 @@ pub fn commit_detail(repo: &Path, hash: &str) -> Result<CommitDetail, String> {
}
}
+ let in_head = run(Some(repo), &["merge-base", "--is-ancestor", h, "HEAD"]).is_ok();
+ let merges_after = in_head
+ && run(
+ Some(repo),
+ &["rev-list", "--merges", "--count", &format!("{h}..HEAD")],
+ )
+ .is_ok_and(|n| n.trim() != "0");
Ok(CommitDetail {
hash: h.to_owned(),
parents: parents.split_whitespace().map(str::to_owned).collect(),
@@ -422,6 +433,8 @@ pub fn commit_detail(repo: &Path, hash: &str) -> Result<CommitDetail, String> {
commit_date: cdate.to_owned(),
message: message.trim_end().to_owned(),
files,
+ in_head,
+ merges_after,
})
}
diff --git a/src/manual.rs b/src/manual.rs
index 61888cd..5352c0c 100644
--- a/src/manual.rs
+++ b/src/manual.rs
@@ -27,7 +27,7 @@ const FEATURES: &[(&str, &[&str])] = &[
"Graph",
&[
"Every branch with its pill on its latest commit: solid for the checked-out one, a laptop when it is local, a cloud when a remote has it.",
- "Double-click a pill to check that branch out (and pull it when its remote is ahead); hover +N to see every branch of the commit, and right-click any of them.",
+ "Double-click a pill to check that branch out (and pull it when its remote is ahead; on the checked-out branch's remote pill, just pull); hover +N to see every branch of the commit, and right-click any of them.",
"Right-click a commit or a pill for branches, tags, merge, rebase, cherry-pick, revert, reset and more.",
"Search messages, authors and hashes, or switch to Code to find the commits that added or removed some text.",
"Interactive rebase: reorder, reword, squash, fix up or drop commits, then start it.",
@@ -46,6 +46,7 @@ const FEATURES: &[(&str, &[&str])] = &[
"Stage, unstage or discard whole files from the right pane.",
"In a file's diff, stage, unstage or discard one hunk, or click the lines you want and act on only those.",
"Write the summary and description and commit; amend the last commit; pick the identity you commit as.",
+ "Double-click a commit's message in the right pane to edit it (any commit of the checked-out branch with no merges after it).",
"Undo and redo commits, merges, rebases, resets, checkouts, branches, tags and stashes.",
],
),
diff --git a/src/repo/detail.rs b/src/repo/detail.rs
index 9584d1e..8331a11 100644
--- a/src/repo/detail.rs
+++ b/src/repo/detail.rs
@@ -4,7 +4,7 @@ use egui::{Align2, Key, RichText, Sense, Ui, pos2, vec2};
use super::diff::unstage_args;
use super::widgets::{self, RowExtra};
-use super::{Action, Dialog, DiffKey, DiffView, Refresh, RepoTab, abort_action, ops};
+use super::{Action, Dialog, DiffKey, DiffView, Refresh, RepoTab, Reword, abort_action, ops};
use crate::git::{Area, ChangedFile, StatusFile};
use crate::icons;
use crate::theme::{self, Tokens};
@@ -85,6 +85,9 @@ impl RepoTab {
return;
};
+ // Taken out while the pane borrows `self`; put back after it.
+ let mut reword = self.reword.take();
+ let head = self.refs.head.clone();
egui::ScrollArea::vertical()
.id_salt("detail_scroll")
.auto_shrink(false)
@@ -97,13 +100,71 @@ impl RepoTab {
.split_once('\n')
.map(|(s, b)| (s, b.trim()))
.unwrap_or((detail.message.as_str(), ""));
- ui.add(
- egui::Label::new(RichText::new(subject).font(theme::semibold(15.0)))
- .wrap(),
- );
- if !body.is_empty() {
- ui.add_space(2.0);
- ui.add(egui::Label::new(RichText::new(body).color(t.text_dim)).wrap());
+ let mut close = false;
+ match reword.as_mut().filter(|r| r.hash == detail.hash) {
+ Some(r) => {
+ if let Some(save) = reword_editor(ui, r) {
+ let message = r.message();
+ if save && message != detail.message.trim() {
+ acts.push(Action::Reword {
+ hash: detail.hash.clone(),
+ message,
+ });
+ }
+ close = true;
+ }
+ }
+ None => {
+ // A commit of the checked-out branch: double-click its message to
+ // edit it (the root commit has no parent to rebase from).
+ let editable = idle
+ && detail.in_head
+ && (detail.hash == head || !detail.merges_after)
+ && (detail.hash == head || !detail.parents.is_empty());
+ let sense = if editable {
+ Sense::click()
+ } else {
+ Sense::hover()
+ };
+ let summary = ui.add(
+ egui::Label::new(
+ RichText::new(subject).font(theme::semibold(15.0)),
+ )
+ .wrap()
+ .sense(sense),
+ );
+ let mut clicked = if editable {
+ summary.on_hover_text("Double-click to edit the message")
+ } else if detail.in_head && detail.merges_after {
+ summary.on_hover_text(
+ "Merges came after this commit: editing its message would flatten them",
+ )
+ } else {
+ summary
+ }
+ .double_clicked();
+ if !body.is_empty() {
+ ui.add_space(2.0);
+ clicked |= ui
+ .add(
+ egui::Label::new(RichText::new(body).color(t.text_dim))
+ .wrap()
+ .sense(sense),
+ )
+ .double_clicked();
+ }
+ if clicked && editable {
+ reword = Some(Reword {
+ hash: detail.hash.clone(),
+ subject: subject.to_owned(),
+ body: body.to_owned(),
+ focus: true,
+ });
+ }
+ }
+ }
+ if close {
+ reword = None;
}
ui.add_space(12.0);
@@ -190,6 +251,7 @@ impl RepoTab {
}
});
});
+ self.reword = reword;
}
/// Changed files, each opening its diff (`key`) when clicked; `rev`: where the files are,
@@ -767,3 +829,66 @@ fn empty_hint(ui: &mut Ui, text: &str) {
t.text_faint,
);
}
+
+impl Reword {
+ /// The summary, then the description after a blank line.
+ fn message(&self) -> String {
+ let (subject, body) = (self.subject.trim(), self.body.trim());
+ if body.is_empty() {
+ subject.to_owned()
+ } else {
+ format!("{subject}\n\n{body}")
+ }
+ }
+}
+
+/// The summary and description being edited, with Save and Cancel: `Some(true)` to save,
+/// `Some(false)` to cancel.
+fn reword_editor(ui: &mut Ui, reword: &mut Reword) -> Option<bool> {
+ let t = Tokens::get(ui.ctx());
+ let summary = ui.add(
+ egui::TextEdit::singleline(&mut reword.subject)
+ .font(theme::semibold(14.0))
+ .hint_text("Summary")
+ .desired_width(f32::INFINITY),
+ );
+ if reword.focus {
+ summary.request_focus();
+ reword.focus = false;
+ }
+ ui.add_space(4.0);
+ ui.add(
+ egui::TextEdit::multiline(&mut reword.body)
+ .hint_text("Description (optional)")
+ .desired_rows(4)
+ .desired_width(f32::INFINITY),
+ );
+ ui.add_space(6.0);
+ let can_save = !reword.subject.trim().is_empty();
+ let (save_keys, cancel_keys) = ui.input(|i| {
+ (
+ i.modifiers.command && i.key_pressed(Key::Enter),
+ i.key_pressed(Key::Escape),
+ )
+ });
+ let mut out = None;
+ ui.horizontal(|ui| {
+ if widgets::primary_button(ui, "Save message", can_save, 110.0).clicked() {
+ out = Some(true);
+ }
+ if ui.button("Cancel").clicked() {
+ out = Some(false);
+ }
+ ui.label(
+ RichText::new("Ctrl+Enter saves · Esc cancels")
+ .small()
+ .color(t.text_faint),
+ );
+ });
+ if save_keys && can_save {
+ out = Some(true);
+ } else if cancel_keys {
+ out = Some(false);
+ }
+ out
+}
diff --git a/src/repo/graph_view.rs b/src/repo/graph_view.rs
index 3a213a6..28d5507 100644
--- a/src/repo/graph_view.rs
+++ b/src/repo/graph_view.rs
@@ -499,12 +499,24 @@ impl RepoTab {
}
/// What double-clicking a pill does: check out that branch (a tracking branch for one only on
- /// a remote, and pulling a local one behind its upstream) or tag. Nothing for the checked-out
- /// one or while an operation runs.
+ /// a remote, and pulling a local one behind its upstream) or tag; pull when it is the
+ /// checked-out branch's remote, further on. Nothing for the checked-out one or while an
+ /// operation runs.
fn pill_checkout(&self, badge: &Badge) -> Option<Action> {
if badge.head || self.busy_op.is_some() {
return None;
}
+ // The checked-out branch's remote pill, further on than the branch: pull.
+ let current = self.refs.current.as_deref() == Some(badge.label.as_str());
+ if badge.kind == BadgeKind::Branch && !badge.local && current {
+ let behind = self
+ .refs
+ .local
+ .iter()
+ .find(|b| b.name == badge.label)
+ .is_some_and(|b| b.ahead_behind().1 > 0);
+ return behind.then_some(Action::Pull);
+ }
match badge.kind {
BadgeKind::Branch if badge.local => {
let behind = self
@@ -583,10 +595,10 @@ impl RepoTab {
let pr = b.kind == BadgeKind::Branch
&& self.prs.iter().any(|p| p.branch == b.label);
ref_pill(ui, ui.painter(), slot.left_center(), b, lane, slot_w, pr);
- let hint = if b.head {
- "checked out"
- } else {
- "double-click to check out"
+ let hint = match self.pill_checkout(b) {
+ _ if b.head => "checked out",
+ Some(Action::Pull) => "double-click to pull",
+ _ => "double-click to check out",
};
let resp = resp.on_hover_text(format!("{} ({hint})", b.describe()));
if resp.double_clicked() {
diff --git a/src/repo/mod.rs b/src/repo/mod.rs
index ccba7c1..53a18de 100644
--- a/src/repo/mod.rs
+++ b/src/repo/mod.rs
@@ -58,6 +58,12 @@ enum Msg {
/// A comparison's files, for the request numbered so.
Compare(u64, Result<CompareData, String>),
Prs(Result<Vec<PullRequest>, String>),
+ /// The commits to replay when rewording `hash`.
+ RewordCommits {
+ hash: String,
+ message: String,
+ result: Result<Vec<git::RebaseCommit>, String>,
+ },
OpDone {
label: String,
result: Result<String, String>,
@@ -162,6 +168,15 @@ impl DiffView {
}
}
+/// A commit's message being edited in the right pane (double-click on it).
+pub(crate) struct Reword {
+ pub hash: String,
+ pub subject: String,
+ pub body: String,
+ /// Put the cursor in the summary on the next frame.
+ pub focus: bool,
+}
+
/// Two points of history side by side in the right pane: a branch against another, a commit
/// against the working tree…
pub(crate) struct Compare {
@@ -288,6 +303,12 @@ pub(crate) enum Action {
},
CloseFileView,
/// Open the interactive rebase editor for the commits after `onto`.
+ /// Gives a commit of the checked-out branch a new message: amending the latest, rebasing
+ /// for an older one.
+ Reword {
+ hash: String,
+ message: String,
+ },
InteractiveRebase {
onto: String,
label: String,
@@ -362,6 +383,8 @@ pub struct RepoTab {
compare_requests: u64,
file_view: Option<file_view::FileView>,
rebase: Option<rebase::RebaseEditor>,
+ /// The selected commit's message, being edited in the right pane.
+ reword: Option<Reword>,
/// HTTPS credentials typed in this session, used for every later git command of the tab.
credentials: Option<git::Credentials>,
/// The last operation started, to run again after signing in.
@@ -455,6 +478,7 @@ impl RepoTab {
compare_requests: 0,
file_view: None,
rebase: None,
+ reword: None,
credentials: None,
last_op: None,
avatars_hinted: false,
@@ -734,6 +758,7 @@ impl RepoTab {
fn load_detail(&mut self, hash: String, ctx: &egui::Context) {
self.detail = None;
+ self.reword = None;
self.detail_error = None;
self.detail_hash = Some(hash.clone());
let path = self.path.clone();
@@ -1056,6 +1081,46 @@ impl RepoTab {
);
}
+ /// The latest commit is amended (its message only, whatever is staged); an older one is
+ /// reworded by an interactive rebase from its parent.
+ fn reword_commit(&mut self, hash: String, message: String, ctx: &egui::Context) {
+ if self.busy_op.is_some() {
+ return;
+ }
+ self.reword = None;
+ if hash == self.refs.head {
+ let (subject, body) = message.split_once("\n\n").unwrap_or((&message, ""));
+ let mut amend = vec![
+ "commit",
+ "--amend",
+ "--only",
+ "--allow-empty",
+ "-m",
+ subject,
+ ];
+ if !body.is_empty() {
+ amend.extend(["-m", body]);
+ }
+ self.run_undoable(
+ &format!("Edit the message of {}", short(&hash)),
+ ops(&[&amend]),
+ Refresh::All,
+ Undo::HeadMove { mode: "--keep" },
+ ctx,
+ );
+ return;
+ }
+ let path = self.path.clone();
+ spawn(&self.tx, ctx, move || {
+ let result = git::rebase_commits(&path, &format!("{hash}^"));
+ Msg::RewordCommits {
+ hash,
+ message,
+ result,
+ }
+ });
+ }
+
fn checkout_remote(&mut self, remote_branch: &str, ctx: &egui::Context) {
// `origin/feature` → local `feature` tracking it (or just switch if it exists).
let local = remote_branch
@@ -1467,6 +1532,38 @@ impl RepoTab {
}
Err(e) => self.status = Some((format!("Interactive rebase: {e}"), true)),
},
+ Msg::RewordCommits {
+ hash,
+ message,
+ result,
+ } => {
+ let result = result.and_then(|commits| {
+ let onto = format!("{hash}^");
+ let mut editor =
+ rebase::RebaseEditor::new(onto, short(&hash).to_owned(), commits);
+ let entry = editor
+ .entries
+ .iter_mut()
+ .find(|e| e.commit.hash == hash)
+ .ok_or("only commits of the checked-out branch can be edited")?;
+ entry.step = rebase::Step::Reword;
+ entry.message = message;
+ if let Some(problem) = editor.problem() {
+ return Err(problem);
+ }
+ editor.command()
+ });
+ match result {
+ Ok(command) => self.run_undoable(
+ &format!("Edit the message of {}", short(&hash)),
+ vec![command],
+ Refresh::All,
+ Undo::HeadMove { mode: "--keep" },
+ ctx,
+ ),
+ Err(e) => self.status = Some((format!("Edit message: {e}"), true)),
+ }
+ }
Msg::FileHistory(path, result) => {
if let Some(view) = &mut self.file_view
&& view.path == path
@@ -1774,6 +1871,7 @@ impl RepoTab {
}
});
}
+ Action::Reword { hash, message } => self.reword_commit(hash, message, ctx),
Action::RunRebase => {
let Some(editor) = &self.rebase else { return };
if editor.problem().is_some() || self.busy_op.is_some() {