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
8 changes: 8 additions & 0 deletions src/screen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ impl Screen {
}

fn update_cursor(&mut self, nav_mode: NavMode) {
// Nothing is selectable (e.g. the log of a branch with no commits).
// Reset the cursor to a valid sentinel rather than positioning it,
// which would index into an empty `line_index` and panic (#262).
if self.line_index.is_empty() {
self.cursor = 0;
return;
}

self.clamp_cursor();
if self.is_cursor_off_screen() {
self.move_cursor_to_screen_center();
Expand Down
15 changes: 15 additions & 0 deletions src/tests/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,18 @@ fn log_other_input() {
fn log_other_invalid() {
snapshot!(setup(setup_clone!()), "lo <enter>");
}

#[test]
fn log_empty_branch() {
// Regression for #262: showing the log of a branch with no commits used to
// panic ("index out of bounds") because the log screen had no items but the
// cursor still indexed into it.
let mut ctx = setup_clone!();
run(&ctx.dir, &["rm", "-rf", ".git"]);
run(&ctx.dir, &["rm", "initial-file"]);
run(&ctx.dir, &["git", "init", "--initial-branch=main"]);

let mut app = ctx.init_app();
ctx.update(&mut app, keys("ll"));
insta::assert_snapshot!(ctx.redact_buffer());
}
25 changes: 25 additions & 0 deletions src/tests/snapshots/gitu__tests__log__log_empty_branch.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
source: src/tests/log.rs
expression: ctx.redact_buffer()
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
styles_hash: 355101d0bd329837
Loading