Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/actions/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ pub enum UiEffect {
SetChangesSort(ChangesSort),
/// Show the log of git commands and their output.
ShowGitOutput,
/// Look for a newer release now, ignoring the daily cache (also `U`).
CheckForUpdates,
/// Show where HEAD has been (the reflog), to recover lost commits.
ShowReflog,
/// Show the repository's worktrees, to add, remove or prune them.
Expand Down
2 changes: 2 additions & 0 deletions crates/actions/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ fn repository_menu(ctx: &MenuContext) -> Vec<Option<MenuItem>> {
entry("Show Git Output", Action::Ui(UiEffect::ShowGitOutput)),
entry("Show Reflog", Action::Ui(UiEffect::ShowReflog)),
entry("Worktrees...", Action::Ui(UiEffect::ShowWorktrees)),
Some(MenuItem::Separator),
entry("Check for Updates", Action::Ui(UiEffect::CheckForUpdates)),
]
}

Expand Down
8 changes: 8 additions & 0 deletions crates/actions/src/menu/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ fn repository_menu_matches_the_vs_code_order() {
"Show Git Output",
"Show Reflog",
"Worktrees...",
"---",
"Check for Updates",
]
);
assert_eq!(
Expand Down Expand Up @@ -1182,6 +1184,10 @@ fn repository_actions_are_prefilled() {
action(&menu, "Worktrees..."),
&Action::Ui(UiEffect::ShowWorktrees)
);
assert_eq!(
action(&menu, "Check for Updates"),
&Action::Ui(UiEffect::CheckForUpdates)
);
}

#[test]
Expand Down Expand Up @@ -1212,6 +1218,8 @@ fn repository_menu_without_remotes_or_branch() {
"Show Git Output",
"Show Reflog",
"Worktrees...",
"---",
"Check for Updates",
]
);
assert_eq!(
Expand Down
19 changes: 12 additions & 7 deletions crates/app/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,17 @@ pub struct AppState {
}

impl AppState {
/// `U` and the "..." menu's Check for Updates: shows the update that is
/// known, or asks the main loop to look again right now.
pub(super) fn check_for_updates(&mut self) {
if self.update_available.is_some() {
self.update_panel = true;
} else {
self.update_requested = true;
self.notify(Level::Info, "Checking for updates…");
}
}

/// Shows `text` in the status bar, colored by `level`.
pub fn notify(&mut self, level: Level, text: impl Into<String>) {
self.message = Some(text.into());
Expand Down Expand Up @@ -576,7 +587,6 @@ impl AppState {
base.max(self.status_poll.cost * 10)
}

#[expect(clippy::too_many_lines, reason = "routes input across the app modes")]
fn on_key(&mut self, key: KeyEvent) -> Vec<Command> {
if key.kind != KeyEventKind::Press {
return Vec::new();
Expand Down Expand Up @@ -649,12 +659,7 @@ impl AppState {
return Vec::new();
}
(KeyCode::Char('U'), _) => {
if self.update_available.is_some() {
self.update_panel = true;
} else {
self.update_requested = true;
self.notify(Level::Info, "Checking for updates…");
}
self.check_for_updates();
}
(KeyCode::Char('r'), _) => {
// A manual refresh clears old messages; automatic ones keep the
Expand Down
4 changes: 4 additions & 0 deletions crates/app/src/state/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ impl AppState {
Vec::new()
}
Plan::Ui(UiEffect::ShowGitOutput) => self.show_git_output(),
Plan::Ui(UiEffect::CheckForUpdates) => {
self.check_for_updates();
Vec::new()
}
Plan::Ui(UiEffect::ShowReflog) => self.show_reflog(),
Plan::Ui(UiEffect::ShowWorktrees) => self.show_worktrees(),
Plan::Ui(UiEffect::OpenInteractiveRebase { base }) => {
Expand Down
10 changes: 10 additions & 0 deletions crates/app/src/state/toolbar_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,3 +550,13 @@ fn create_tag_from_the_menu_is_annotated_even_without_a_message() {
accept_dialogs(&mut h);
assert_eq!(repo.git(&["cat-file", "-t", "v9"]), "tag");
}

#[test]
fn check_for_updates_in_the_repository_menu_asks_for_a_check() {
let repo = FixtureRepo::sample();
let mut h = open(&repo);
open_repo_menu(&mut h);
click_text(&mut h, "Check for Updates");
assert!(h.state.update_requested, "the main loop looks again now");
assert_eq!(h.state.message.as_deref(), Some("Checking for updates…"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
source: crates/ui/tests/menu.rs
expression: "render(&menu, 60, 25)"
---
.┌─────────────────┐........................................
.│ View as Tree │┌─────────────────────────┐.............
.├─────────────────┤│ Merge... │.............
.│ View & Sort ▸ ││ Rebase Branch... │.............
.├─────────────────┤├─────────────────────────┤.............
.│ Pull ││ Create Branch... │.............
.│ Push ││ Create Branch From... │.............
.│ Clone │├─────────────────────────┤.............
.│ Checkout to... ││ Rename Branch... │.............
.│ Fetch ││ Delete Branch... │.............
.├─────────────────┤│ Delete Remote Branch... │.............
.│ Commit ▸ │├─────────────────────────┤.............
.│ Changes ▸ ││ Publish Branch... │.............
.│ Pull, Push ▸ │└─────────────────────────┘.............
.│ Branch ▸ │........................................
.│ Remote ▸ │........................................
.│ Stash ▸ │........................................
.│ Tags ▸ │........................................
.├─────────────────┤........................................
.│ Show Git Output │........................................
.│ Show Reflog │........................................
.│ Worktrees... │........................................
.└─────────────────┘........................................
............................................................
............................................................
.┌───────────────────┐......................................
.│ View as Tree │┌─────────────────────────┐...........
.├───────────────────┤│ Merge... │...........
.│ View & Sort ▸ ││ Rebase Branch... │...........
.├───────────────────┤├─────────────────────────┤...........
.│ Pull ││ Create Branch... │...........
.│ Push ││ Create Branch From... │...........
.│ Clone │├─────────────────────────┤...........
.│ Checkout to... ││ Rename Branch... │...........
.│ Fetch ││ Delete Branch... │...........
.├───────────────────┤│ Delete Remote Branch... │...........
.│ Commit ▸ │├─────────────────────────┤...........
.│ Changes ▸ ││ Publish Branch... │...........
.│ Pull, Push ▸ │└─────────────────────────┘...........
.│ Branch ▸ │......................................
.│ Remote ▸ │......................................
.│ Stash ▸ │......................................
.│ Tags ▸ │......................................
.├───────────────────┤......................................
.│ Show Git Output │......................................
.│ Show Reflog │......................................
.│ Worktrees... │......................................
.├───────────────────┤......................................
.│ Check for Updates │......................................
.└───────────────────┘......................................
Loading