Commit graph

1036 commits

Author SHA1 Message Date
Jesse Duffield ab4f310ce9 rename files 2023-07-29 17:36:18 +10:00
Jesse Duffield 40753e916d Write unit tests with the help of afero
Afero is a package that lets you mock out a filesystem with an in-memory filesystem.
It allows us to easily create the files required for a given test without worrying about
a cleanup step or different tests tripping on eachother when run in parallel.

Later on I'll standardise on using afero over the vanilla os package
2023-07-29 17:36:18 +10:00
Jesse Duffield c9a19f0fbc Use forward-slashes on windows
We want to be using forward slashes everywhere internally, so if we get a path from windows
we should immediately convert it to use forward slashes.

I'm leaving out the recent repos list because that would require a migration
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 9fb0fe1e35 Add test for opening lazygit in the worktree of a bare repo 2023-07-29 17:36:18 +10:00
Jesse Duffield 180908d244 Fix test by making branches appear deterministically
This fixes pkg/integration/tests/worktree/rebase.go which was failing on old git versions due to a difference in
order of branches that don't have recency values
2023-07-29 17:36:18 +10:00
Jesse Duffield 4a2c21bc10 Support fastforwarding worktree 2023-07-29 17:36:18 +10:00
Jesse Duffield df78ffd081 Add more worktree tests 2023-07-29 17:36:18 +10:00
Jesse Duffield 0eac6483ec Add worktree tests for removing/detaching 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 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 514c2f0897 Fix tests
Going and fixing up some submodule tests which were broken by bad assumptions with worktree code
2023-07-29 17:36:18 +10:00
Jesse Duffield af5ec473f3 Safer fetching of linked worktree paths 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 0cef35324f Properly render worktrees in files panel 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 4c1d706a85 Hide worktree functionality on old git versions 2023-07-29 17:36:18 +10:00
Jesse Duffield b6d5542b35 Associate branches with worktrees even when mid-rebase 2023-07-29 17:36:18 +10:00
Jesse Duffield 500c0eafb9 Support creating worktrees from refs 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 ad017f3bb8 Move current worktree to top of list 2023-07-29 17:36:17 +10:00
Jesse Duffield dbd32f63dd Improve name handling 2023-07-29 17:36:17 +10:00
Jesse Duffield 038de926b3 Update worktree model 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 b10670ba44 Improve worktree panel 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 141011aaae Hide worktrees in the worktree panel if they point at a non-existing filesystem location.
Remove unneeded check when filtering out branches from non-current worktrees from the branch panel.
Add link icon for linked worktrees
2023-07-29 17:36:17 +10:00
Joel Baranick 2f156b3438 Support for deleting a worktree 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 429225da80 Support random order of command execution in unit tests
Now that we run code concurrently in our loaders, we need to handle that in our tests.
We could enforce a deterministic ordering by mocking waitgroup or something like that,
but I think it's fine to let our tests handle some randomness given that prod itself
will have that randomness.

I've removed the patch test file because it was clunky, not providing much value, and
it would have been hard to refactor to the new pattern
2023-07-29 12:36:17 +10:00
Jesse Duffield 272e021c08 Refactor reflog commit loader
No functional changes
2023-07-29 10:04:11 +10:00
Jesse Duffield 862ebd25cb Speed up remote loader
We're:
* using concurrency with wait groups
* avoiding regex
* processing lines of input as they come rather than storing everything in one string
* avoiding an inner loop by creating a mapping of remote names to branches
2023-07-29 10:04:11 +10:00
Jesse Duffield 5d8a85f7e7 Use wait groups to speed up commit loading
The speedup is most noticeable on first load, when we haven't yet fetched out main branches.
I saw a speedup from 105ms to 60ms. On subsequent loads the gain is more modest;
54ms to 40ms
2023-07-29 10:04:11 +10:00
Jesse Duffield 71cab4fadc Log duration of commands
This will help us diagnose performance issues
2023-07-29 09:39:22 +10:00
Jesse Duffield c4e27bf96c Revert "Fix flakey pull_merge_conflict test"
This reverts commit 90613056ce, or the part that removed
a goroutine at least.

Reverting because this has caused an infinite wait for push/pull on windows.
We'll need to find out why that happens separately
2023-07-24 21:12:03 +10:00
Stefan Haller c21633b1be Prompt for commit message when moving a custom patch to a new commit 2023-07-23 13:55:48 +02: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
Stefan Haller 39f3f150ed Fix crash when a background fetch prompts for credentials
This happens consistently for my when I close my MacBook's lid. It seems that
MacOS locks the user's keychain in this case, and since I have my keychain
provide the pass phrases for my ssh keys, fetching fails because it tries to
prompt me for a pass phrase.

This all worked correctly already, we have the FailOnCredentialRequest()
mechanism specifically for this situation, so all is great. The only problem was
that it was trying to pause the ongoing task while prompting the user for input;
but the task is nil for a background fetch (and should be).
2023-07-18 18:53:35 +02:00
Stefan Haller 6b769fb138 Fix populating the Commit.Tags field
We now store all tags in this field if there are several.
2023-07-15 13:07:02 +02:00
Stefan Haller cc835a813e Extend commit_loader test to show how the Tags field is populated
It shows that right now, we take only the first tag if there are multiple.
Judging from how the code is written, I'm not sure this was intentional.
2023-07-15 13:07:02 +02:00
Jesse Duffield 78bbdca757 Add test for cmd obj cloning 2023-07-15 11:05:43 +10:00
Scott Callaway 9617737352 config: rely on .gitconfig for verbose commit messages
As discussed in https://github.com/jesseduffield/lazygit/pull/2599, it
makes more sense to have the user specify whether they want verbose
commits from their own git config, rather than lazygit config.

This means that we can remove all the code (including test coverage)
associated with the custom verbose flag, and lazygit will just inherit
the .gitconfig settings automatically.
2023-07-14 07:56:09 +02: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