Skip to content

Commit

Permalink
Enable jumping back in main view (#1138)
Browse files Browse the repository at this point in the history
Allow going back to the previously selected commit after jumping to its
parent.

Fixes #628

[tk: added test]
  • Loading branch information
kempniu committed Oct 4, 2021
1 parent 874ee11 commit 2e31516
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

DEFINE_ALLOCATOR(realloc_reflogs, char *, 32)

static struct view_history main_view_history = { 0 };

bool
main_status_exists(struct view *view, enum line_type type)
{
Expand Down Expand Up @@ -572,7 +574,19 @@ main_request(struct view *view, enum request request, struct line *line)
break;

case REQ_PARENT:
goto_id(view, "%(commit)^", true, false);
if (push_view_history_state(&main_view_history, &view->pos, NULL)) {
goto_id(view, "%(commit)^", true, false);
} else {
report("Failed to save current view state");
}
break;

case REQ_BACK:
if (pop_view_history_state(&main_view_history, &view->pos, NULL)) {
redraw_view(view);
} else {
report("Already at start of history");
}
break;

case REQ_MOVE_NEXT_MERGE:
Expand Down
28 changes: 28 additions & 0 deletions test/main/goto-test
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ steps '
:save-display commit-1.screen
:parent
:save-display commit-2.screen
:back
:save-display commit-1-back.screen
:parent
:save-display commit-2-again.screen
:parent
:save-display commit-5.screen
:parent
Expand All @@ -39,6 +43,18 @@ assert_equals 'commit-1.screen' <<EOF
2009-02-22 11:53 +0000 Committer o-' [master] Change: b
[main] 9d2a1bbf0046ec6b5e7a6faebb9ba9374bdbdee7 - commit 1 of 5 100%
EOF

assert_equals 'commit-1-back.screen' <<EOF
2009-03-28 13:22 +0000 Committer * [conflict-branch] Change: d'
2009-03-20 01:00 +0000 Committer * Change: d
2014-05-25 19:42 +0000 Unknown | * Unstaged changes
2009-03-11 12:38 +0000 Committer | * [conflict-master] Change: c'
2009-03-03 00:15 +0000 Committer | * Change: c
2009-02-22 11:53 +0000 Committer o-' [master] Change: b
[main] 9d2a1bbf0046ec6b5e7a6faebb9ba9374bdbdee7 - commit 1 of 5 100%
EOF

Expand All @@ -51,6 +67,18 @@ assert_equals 'commit-2.screen' <<EOF
2009-02-22 11:53 +0000 Committer o-' [master] Change: b
[main] fa878e5e6d838243fa59025ef314395fbebc790f - commit 2 of 5 100%
EOF

assert_equals 'commit-2-again.screen' <<EOF
2009-03-28 13:22 +0000 Committer * [conflict-branch] Change: d'
2009-03-20 01:00 +0000 Committer * Change: d
2014-05-25 19:42 +0000 Unknown | * Unstaged changes
2009-03-11 12:38 +0000 Committer | * [conflict-master] Change: c'
2009-03-03 00:15 +0000 Committer | * Change: c
2009-02-22 11:53 +0000 Committer o-' [master] Change: b
[main] fa878e5e6d838243fa59025ef314395fbebc790f - commit 2 of 5 100%
EOF

Expand Down

0 comments on commit 2e31516

Please sign in to comment.