Commit graph

120 commits

Author SHA1 Message Date
Jesse Duffield 201ec5307f Fix flakey worktree tests
In the presentation layer, when showing branches, we'll show worktrees against branches if they're
associated. But there was a race condition: if the worktree model was refreshed after the branches model,
it wouldn't be used in the presentation layer when it came time to render the branches.

A better solution would be to have some way of signalling that a particular context needs to be refreshed
and after all the models are done being refreshed, we then refresh the contexts. This will prevent
double-renders
2023-07-29 17:36:18 +10:00
Jesse Duffield 0e91a2f16e Add more i18n for worktrees 2023-07-29 17:36:18 +10:00
Jesse Duffield 693048eb29 Use fields rather than methods on worktrees
I would prefer to use methods to keep things immutable but I'd rather be consistent with the other
models and update them all at once
2023-07-29 17:36:18 +10:00
Jesse Duffield 873a68949e Centralise logic for obtaining repo paths
There are quite a few paths you might want to get e.g. the repo's path, the worktree's path,
the repo's git dir path, the worktree's git dir path. I want these all obtained once and
then used when needed rather than having to have IO whenever we need them. This is not so
much about reducing time spent on IO as it is about not having to care about errors every time
we want a path.
2023-07-29 17:36:18 +10:00
Jesse Duffield f8c18d074a Remove IO logic from presentation code for worktrees
We're doing all the IO in our workers loader method so that we don't need to do any
in our presentation code
2023-07-29 17:36:18 +10:00
Jesse Duffield 939c573907 Update repo switch logic
We now always re-use the state of the repo if we're returning to it, and we always reset the windows to their default tabs.

We reset to default tabs because it's easy to implement. If people want to:
* have tab states be retained when switching
* have tab states specific to the current repo retained when switching back

Then we'll need to revisit this
2023-07-29 17:36:18 +10:00
Jesse Duffield 71070827f2 Add worktree integration tests 2023-07-29 17:36:18 +10:00
Jesse Duffield e782b77475 Remove worktree version guards
Our min required git version is 2.20 so there's no need to add guards
for worktrees because they were added in 2.5
2023-07-29 17:36:18 +10:00
Jesse Duffield d764f35c5d Fix unit tests 2023-07-29 17:36:18 +10:00
Jesse Duffield b06f938e00 Show loader when switching worktrees 2023-07-29 17:36:18 +10:00
Jesse Duffield ca0b966f44 Support older versions of git when fetching worktrees
Older versions of git don't support the -z flag in `git worktree list`.
So we're using newlines.

Also, we're not raising an error upon error because that triggers another refresh,
which gets us into an infinite loop
2023-07-29 17:36:18 +10:00
Jesse Duffield b79d19e0a7 Support opening worktree in editor 2023-07-29 17:36:18 +10:00
Jesse Duffield 1638354474 Better logic for knowing which repo we're in 2023-07-29 17:36:18 +10:00
Jesse Duffield 96e41fa985 Only show worktree in status panel if not the main worktree and worktrees are supported 2023-07-29 17:36:18 +10:00
Jesse Duffield 4c1d706a85 Hide worktree functionality on old git versions 2023-07-29 17:36:18 +10:00
Jesse Duffield 72d7b91640 Assume that the base of a worktree can be checked out 2023-07-29 17:36:18 +10:00
Jesse Duffield 32ceeaa43f i18n for worktrees 2023-07-29 17:36:18 +10:00
Jesse Duffield 82da8d7586 Don't quit on error 2023-07-29 17:36:17 +10:00
Jesse Duffield 8f51c80d76 Show base ref suggestions when creating worktree 2023-07-29 17:36:17 +10:00
Jesse Duffield c8dcd002e2 Checkout worktree when creating from worktree view 2023-07-29 17:36:17 +10:00
Jesse Duffield 500c0eafb9 Support creating worktrees from refs 2023-07-29 17:36:17 +10:00
Jesse Duffield e0c8a56db5 Fix wording 2023-07-29 17:36:17 +10:00
Jesse Duffield 002e4eedf5 Log when directory is changed 2023-07-29 17:36:17 +10:00
Jesse Duffield a991525391 Handle deleting branch attached to worktree 2023-07-29 17:36:17 +10:00
Jesse Duffield fd854fb7f7 Don't touch repo stack when switching worktrees
We shouldn't touch this cos we're doing a lateral move
2023-07-29 17:36:17 +10:00
Jesse Duffield 64711dfc2f Move status panel presentation logic into presentation package 2023-07-29 17:36:17 +10:00
Jesse Duffield 0776ae41d3 Land in the same panel when switching to a worktree 2023-07-29 17:36:17 +10:00
Jesse Duffield 9eb9ce88b3 Prompt to switch to worktree when branch is checked out by other worktree 2023-07-29 17:36:17 +10:00
Jesse Duffield 7af9715a1b Use git lingo 2023-07-29 17:36:17 +10:00
Jesse Duffield dbd32f63dd Improve name handling 2023-07-29 17:36:17 +10:00
Joel Baranick b22f936522 Address PR comments 2023-07-29 17:36:17 +10:00
Joel Baranick 53e408f156 Basic support for adding a worktree 2023-07-29 17:36:17 +10:00
Joel Baranick f13f85de8e Style missing worktree as red and display better error when trying to switch to them
Use a broken link icon for missing worktrees
2023-07-29 17:36:17 +10:00
Joel Baranick 4a2c54e5d8 Update status to differentiate the main vs linked worktrees 2023-07-29 17:36:17 +10:00
Joel Baranick eded08bacf Initial addition of support for worktrees 2023-07-29 17:36:17 +10:00
Jesse Duffield 39b77c0fca Have staging refresh wait for files to refresh first 2023-07-29 10:20:15 +10:00
Jesse Duffield 63e5790410 Speed up refresh using concurrency and wait groups
Previously our synchronous refreshes took far longer because nothing
was happening concurrently. We now run refresh functions concurrently
and use a wait group to ensure they're all done before returning
2023-07-29 10:04:11 +10:00
Jesse Duffield 09ce430240 Log duration of refresh 2023-07-29 09:39:10 +10:00
Jesse Duffield 7807b40322 Better tag creation UX
Previously we used a single-line prompt for a tag annotation. Now we're using the commit message
prompt.

I've had to update other uses of that prompt to allow the summary and description labels to
be passed in
2023-07-22 14:36:35 +10:00
Jesse Duffield 3cee37388c Keep track of authors across local commits and branch commits for suggestions
Previously, we would only show the authors based on local commits, but sometimes you want to set a commit author
to that of a commit on another branch. Now, so long as you've viewed the branch's commits, the author will appear
as a suggestion.
2023-07-22 10:47:04 +10:00
Jesse Duffield 373f24c80f Fix crash on empty menu
When a menu is empty (e.g. due to filtering) we shouldn't crash on focus or selection
2023-07-20 21:05:52 +10:00
Jesse Duffield b61ca21a84 Allow checking for merge conflicts after running a custom command
We have a use-case to rebind 'm' to the merge action in the branches panel. There's three ways to handle this:
1) For all global keybindings, define a per-panel key that invokes it
2) Give a name to all controller actions and allow them to be invoked in custom commands
3) Allow checking for merge conflicts after running a custom command so that users can add their own 'git merge' custom command
that matches the in-built action

Option 1 is hairy, Option 2 though good for users introduces new backwards compatibility issues that I don't want to do
right now, and option 3 is trivially easy to implement so that's what I'm doing.

I've put this under an 'after' key so that we can add more things later. I'm imagining other things like being able to
move the cursor to a newly added item etc.

I considered always running this hook by default but I'd rather not: it's matching on the output text and I'd rather something
like that be explicitly opted-into to avoid cases where we erroneously believe that there are conflicts.
2023-07-13 18:40:34 +10:00
Stefan Haller 30ce7c8085 Replace uses of "git stash save" with "git stash push"
Save has been deprecated for a while, push is the recommended way to save a
stash. Push has been available since 2.13, so we can use it without problems.
2023-07-10 15:09:17 +02:00
Jesse Duffield 6b9390409e Use an interface for tasks instead of a concrete struct
By using an interface for tasks we can use a fake implementation in tests with extra methods
2023-07-10 17:12:21 +10:00
Jesse Duffield 14ecc15e71 Use first class task objects instead of global counter
The global counter approach is easy to understand but it's brittle and depends on implicit behaviour that is not very discoverable.

With a global counter, if any goroutine accidentally decrements the counter twice, we'll think lazygit is idle when it's actually busy.
Likewise if a goroutine accidentally increments the counter twice we'll think lazygit is busy when it's actually idle.
With the new approach we have a map of tasks where each task can either be busy or not. We create a new task and add it to the map
when we spawn a worker goroutine (among other things) and we remove it once the task is done.

The task can also be paused and continued for situations where we switch back and forth between running a program and asking for user
input.

In order for this to work with `git push` (and other commands that require credentials) we need to obtain the task from gocui when
we create the worker goroutine, and then pass it along to the commands package to pause/continue the task as required. This is
MUCH more discoverable than the old approach which just decremented and incremented the global counter from within the commands package,
but it's at the cost of expanding some function signatures (arguably a good thing).

Likewise, whenever you want to call WithWaitingStatus or WithLoaderPanel the callback will now have access to the task for pausing/
continuing. We only need to actually make use of this functionality in a couple of places so it's a high price to pay, but I don't
know if I want to introduce a WithWaitingStatusTask and WithLoaderPanelTask function (open to suggestions).
2023-07-09 21:30:19 +10:00
Jesse Duffield e588355f57 Add mutex for refreshing branches
We had a race condition due to refreshing branches in two different places, one which refreshed reflog commits
beforehand. The race condition meant that upon load we wouldn't see recency values (provided by the reflog commits)
against the branches
2023-07-09 20:57:18 +10:00
Jesse Duffield 015a04fac6 Remove redundant waitgroup
Turns out we're just running our refresh functions one after the other which isn't ideal but we can fix that separately.
As it stands this wait group isn't doing anything.
2023-07-08 22:54:52 +10:00
Jesse Duffield 26ca41a40e Handle pending actions properly in git commands that require credentials
I don't know if this is a hack or not: we run a git command and increment the pending action
count to 1 but at some point the command requests a username or password, so we need to prompt
the user to enter that. At that point we don't want to say that there is a pending action,
so we decrement the action count before prompting the user and then re-increment it again afterward.

Given that we panic when the counter goes below zero, it's important that it's not zero
when we run the git command (should be impossible anyway).

I toyed with a different approach using channels and a long-running goroutine that
handles all commands that request credentials but it feels over-engineered compared to this
commit's approach.
2023-07-08 22:54:52 +10:00
Jesse Duffield 6c4e7ee972 Add busy count for integration tests
Integration tests need to be notified when Lazygit is idle so they can progress to the next assertion / user action.
2023-07-08 22:54:52 +10:00
Jesse Duffield 261f30f49c Add integration tests for searching/filtering 2023-07-03 12:54:14 +10:00