Disable uncommit button for parentless commits (#25983)

Closes #25976

There's a couple states that this covers:
- upon `git init`, no footer is shown at all
- after 1 commit (or when on any parentless commit), the uncommit button
is ~disabled~ hidden
- otherwise commit button is shown

Also updated the button with "meta" tooltip showing human readable
description and git command.

Release Notes:

- N/A

---------

Co-authored-by: Nate Butler <iamnbutler@gmail.com>
This commit is contained in:
Julia Ryan 2025-03-05 15:23:05 -08:00 committed by GitHub
parent 4db9ab15a7
commit 0200dda83d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 15 deletions

View file

@ -2237,20 +2237,28 @@ index 1234567..abcdef0 100644
}),
)
.child(div().flex_1())
.child(
panel_icon_button("undo", IconName::Undo)
.icon_size(IconSize::Small)
.icon_color(Color::Muted)
.tooltip(Tooltip::for_action_title(
if self.has_staged_changes() {
"git reset HEAD^ --soft"
} else {
"git reset HEAD^"
},
&git::Uncommit,
))
.on_click(cx.listener(|this, _, window, cx| this.uncommit(window, cx))),
),
.when(commit.has_parent, |this| {
let has_unstaged = self.has_unstaged_changes();
this.child(
panel_icon_button("undo", IconName::Undo)
.icon_size(IconSize::Small)
.icon_color(Color::Muted)
.tooltip(move |window, cx| {
Tooltip::with_meta(
"Uncommit",
Some(&git::Uncommit),
if has_unstaged {
"git reset HEAD^ --soft"
} else {
"git reset HEAD^"
},
window,
cx,
)
})
.on_click(cx.listener(|this, _, window, cx| this.uncommit(window, cx))),
)
}),
)
}
@ -3559,6 +3567,7 @@ impl ComponentPreview for PanelRepoFooter {
sha: "abc123".into(),
subject: "Modify stuff".into(),
commit_timestamp: 1710932954,
has_parent: true,
}),
}
}
@ -3575,6 +3584,7 @@ impl ComponentPreview for PanelRepoFooter {
sha: "abc123".into(),
subject: "Modify stuff".into(),
commit_timestamp: 1710932954,
has_parent: true,
}),
}
}