sourcegit-scm / sourcegit

Windows/macOS/Linux GUI client for GIT users
MIT License
909 stars 96 forks source link

Fix: Enhance support of worktree repository #89

Closed gadfly3173 closed 4 months ago

gadfly3173 commented 4 months ago

Partial repair #86

Known Issues:

love-linger commented 4 months ago

commit 27fd5829f57bcc004c3c4daf8169edb076c0869d will not be merged because it will introduce some issues:

love-linger commented 4 months ago

According to the code in Models/Watcher.cs:

if (_updateBranch > 0 && now > _updateBranch)
{
    _updateBranch = 0;
    _updateWC = 0;

    if (_updateTags > 0)
    {
        _updateTags = 0;
        Task.Run(() =>
        {
            _repo.RefreshTags();
            _repo.RefreshBranches();
            _repo.RefreshCommits();
        });
    }
    else
    {
        Task.Run(() =>
        {
            _repo.RefreshBranches();
            _repo.RefreshCommits();
        });
    }

    Task.Run(_repo.RefreshWorkingCopyChanges);
}

Repository.RefershBranches and Repository.RefreshCommits will always be called if the state of branch changes. If you want to run it immediately, I suggest you use Repository.MarkBranchesDirtyManually in UIThread instead. For example:

-               CallUIThread(() => _repo.SetWatcherEnabled(true));
-               if (!CheckoutAfterCreated)
-               {
-                   _repo.RefreshBranches();
-                   _repo.RefreshCommits();
-               }
+               CallUIThread(() => {
+                   repo.SetWatcherEnabled(true);
+                   repo.MarkBranchesDirtyManually();
+               });
                return true;
love-linger commented 4 months ago

By the way, would adding a toolbar button to refresh the entire repository (shortcut F5) help with these and other similar issue?

gadfly3173 commented 4 months ago

I'll continue to work on this after April 30th.

love-linger commented 4 months ago

There are already three ways to close tabs.

I really do NOT want to introduce a nother way that using the mouse middle button……

gadfly3173 commented 4 months ago

There are already three ways to close tabs.

  • Click the close button on each tab (with left mouse button)
  • Use context menu of each tab (with right mouse button)
  • Use hotkey CTRL + W

I really do NOT want to introduce a nother way that using the mouse middle button……

Using the middle button to close a tab is a very common design in other multi-tab applications, such as Chrome, Jetbrains IDE, Visual Studio Code, GitKraken, etc. I will still revert the submit about closing the tab because it has nothing to do with this PR, and I may not be able to solve the aforementioned error performance

gadfly3173 commented 4 months ago

Known Issues:

  • Operate branch and commit in other worktree repo(includes base repo) still won't show in current worktree repo. To solve this may need to add refresh branches and commits after switched repo tab.
  • Manually press FETCH button won't fix above question.

Fixed these issues

love-linger commented 4 months ago

Commit a63a0d10fbf644221e86ac2031a94c40c26d6a4c force refreshing branches, working copy changes and commit after current active page changed. It's not recommanded. I've add a hotkey 'F5' to manually refresh the whole repository if it is needed.

gadfly3173 commented 4 months ago

Commit a63a0d1 force refreshing branches, working copy changes and commit after current active page changed. It's not recommanded. I've add a hotkey 'F5' to manually refresh the whole repository if it is needed.

Why is it not recommended to refresh branches, commits, and workspaces after switching repositories? According to my observation, GitKraken takes this approach.

love-linger commented 4 months ago

I've pushed a commit 1fe050ed0bf4eb7ea6753e47eb7baca6d5d3f064 to fix issue #86.

Because we use filesystem watcher to determine how to refresh the information of repository, it's not necessary to refresh the repository each time we switch between tabs.

And since Worktree can be traited as : checkout a branch of the main repository to another directory, we just need to make sure that Worktree also listens for gitdir changes in the main repository (since worktree is essentially the same repository as the main Repository) to resolve the issue.