Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for refresh-mode = periodic (issue #430). #591

Merged
merged 4 commits into from
Apr 29, 2017
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: 7 additions & 1 deletion src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,16 @@ get_input(int prompt_position, struct key *key)

if (opt_refresh_mode == REFRESH_MODE_PERIODIC) {
delay = watch_periodic(opt_refresh_interval);
bool refs_refreshed = false;
foreach_displayed_view (view, i) {
if (view_can_refresh(view) &&
watch_dirty(&view->watch))
watch_dirty(&view->watch)) {
if (!refs_refreshed) {
load_refs(true);
refs_refreshed = true;
}
refresh_view(view);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/watch.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ watch_head_handler(struct watch_handler *handler, enum watch_event event, enum w

// FIXME: check branch
if ((head = get_ref_head()) &&
check_file_mtime(&handler->last_modified, "%s/refs/head/%s", repo.git_dir, head->name))
check_file_mtime(&handler->last_modified, "%s/refs/heads/%s", repo.git_dir, head->name))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch.

return WATCH_HEAD;

return WATCH_NONE;
Expand Down
74 changes: 74 additions & 0 deletions test/main/refresh-periodic-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/sh

. libtest.sh
. libgit.sh
. "$source_dir/util.sh"

export LINES=5

steps '
:save-display main-with-unstaged.screen

:exec @git add a
:save-display main-after-add-a.screen

:exec @git commit -m "Commit changes"
:save-display main-after-commit.screen

:exec @git add b.c
:exec @git commit -m "Another change: hello"
:exec @sleep 2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need an advice about test/main/refresh-periodic-test: as it is, I am not sure that it correctly checks that the automatic refresh works. Sleeping for several seconds through exec, seems to block the whole program, which is not the same as tig being idle for this time. Is there a better way to ensure that tig will just simply sit idle for a while?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will require some rework. I'll take a look.

:save-display main-after-commiting-change-and-sleeping-hello.screen

:exec @git add i.o
:exec @git commit -am "Another change: world"
:exec @sleep 2
:save-display main-after-commiting-change-and-sleeping-world.screen
'

tigrc <<EOF
set refresh-mode = periodic
set refresh-interval = 1
EOF

in_work_dir create_dirty_workdir

export GIT_AUTHOR_DATE="$(expr $author_date + $author_date_delta)"
export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"

test_tig

assert_equals 'main-with-unstaged.screen' <<EOF
$YYY_MM_DD_HH_MM Unknown o Unstaged changes
2009-02-13 23:31 A. U. Thor I [master] Initial commit

[main] Unstaged changes 100%
EOF

assert_equals 'main-after-add-a.screen' <<EOF
$YYY_MM_DD_HH_MM Unknown o Unstaged changes
$YYY_MM_DD_HH_MM Unknown o Staged changes
2009-02-13 23:31 A. U. Thor I [master] Initial commit
[main] Unstaged changes 100%
EOF

assert_equals 'main-after-commit.screen' <<EOF
2014-05-25 19:42 Unknown o Unstaged changes
2009-02-22 11:53 Committer o [master] Commit changes
2009-02-13 23:31 A. U. Thor I Initial commit
[main] Unstaged changes 100%
EOF

assert_equals 'main-after-commiting-change-and-sleeping-hello.screen' <<EOF
2014-05-25 19:42 Unknown o Unstaged changes
2009-02-22 11:53 Committer o [master] Another change: hello
2009-02-22 11:53 Committer o Commit changes
[main] Unstaged changes 75%
EOF

assert_equals 'main-after-commiting-change-and-sleeping-world.screen' <<EOF
2009-02-22 11:53 Committer o [master] Another change: world
2009-02-22 11:53 Committer o Another change: hello
2009-02-22 11:53 Committer o Commit changes
[main] 70bab5b220d2fd9bf61c125d52d59e10e93ec341 - commit 1 of 4 75%
EOF