1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-06 22:33:07 +02:00

1341 Commits

Author SHA1 Message Date
1a72561b15 Remove the kill package dependency 2025-08-01 10:32:47 +02:00
7d9eaead54 Close the pty instead of killing the process for runAndDetectCredentialRequest
As with the previous commit, this is not strictly necessary for anything, just
cleaner.
2025-08-01 10:32:47 +02:00
83046a05d4 Don't kill processes in RunAndProcessLines
As we just did for tasks, close their stdout pipe instead. This makes the called
process terminate more gracefully.

This isn't a change that we *need* to make, it's just a bit nicer.
2025-08-01 10:32:47 +02:00
e46dc1ead6 Use a better approach for determining pushed and merge statuses
Previously we would call git merge-base with the upstream branch to determine
where unpushed commits end and pushed commits start, and also git merge-base
with the main branch(es) to see where the merged commits start. This worked ok
in normal cases, but it had two problems:
- when filtering by path or by author, those merge-base commits would usually
not be part of the commit list, so we would miss the point where we should
switch from unpushed to pushed, or from pushed to merged. The consequence was
that in filtering mode, all commit hashes were always yellow.
- when main was merged into a feature branch, we would color all commits from
that merge on down in green, even ones that are only part of the feature branch
but not main.

To fix these problems, we switch our approach to one where we call git rev-list
with the branch in question, with negative refspecs for the upstream branch and
the main branches, respectively; this gives us the complete picture of which
commits are pushed/unpushed/merged, so it also works in the cases described
above.

And funnily, even though intuitively it feels more expensive, it actually
performs better than the merge-base calls (for normal usage scenarios at least),
so the commit-loading part of refresh is faster now in general. We are talking
about differences like 300ms before, 140ms after, in some unscientific
measurements I took (depends a lot on repo sizes, branch length, etc.). An
exception are degenerate cases like feature branches with hundreds of thousands
of commits, which are slower now; but I don't think we need to worry about those
too much.
2025-07-31 15:50:53 +02:00
20517330b4 Change GetCommitsOptions.RefForPushedStatus to a models.Ref
This makes it easier to use the full ref in the git merge-base call, which
avoids ambiguities when there's a tag with the same name as the current branch.

This fixes a hash coloring bug in the local commits panel when there's a tag
with the same name as the checked out branch; in this case all commit hashes
that should be yellow were painted as red.
2025-07-31 15:26:19 +02:00
4b9921d0a4 Move the Ref interface from gui/types to models
This is a type that can be useful for model/backend stuff, so move it there. We
are going to use it in the API of the commit loader.
2025-07-31 15:21:34 +02:00
cc0b5a2f7f Cleanup: remove the ignoringWarnings hack from GetMergeBase
GetMergeBase is always called with a full ref, so it shouldn't need the
ignoringWarnings hack (which is about ignoring warnings coming from ambiguous
refs).

Also, separate stdout and stderr, which would also have solved the problem. We
no longer really need it now, but it's still cleaner.
2025-07-31 15:21:34 +02:00
630c1720ac refactor: use slices.Equal to simplify code
Signed-off-by: jishudashu <979260390@qq.com>
2025-07-29 11:19:36 +02:00
9c0e103b90 Stage only tracked files when staging all in filter-by-tracked-files view
Also, fix two other commands that stage all files under the hood:
- when continuing a rebase after resolving conflicts, we auto-stage all files,
  but in this case we never want to include untracked files, regardless of the
  filter
- likewise, pressing ctrl-f to find a base commit for fixup stages all files for
  convenience, but again, this should only stage files that are already tracked
2025-07-28 14:10:38 +02:00
1c533dcd55 Revert "Add IsAnnotated field to models.Tag struct"
It seems that `git for-each-ref` is a lot slower than `git tag --list` when
there are thousands of tags, so revert back to the previous method, now that we
no longer use the IsAnnotated field.

This reverts commit b12b1040c3.
2025-07-28 10:53:51 +02:00
151e80902e Use a different way to check if a tag is annotated
Storing it in the Tag struct makes loading tags a lot slower when there is a
very large number of tags; so determine it on the fly instead. On my machine,
the additional call takes under 5ms, so it seems we can afford it.
2025-07-28 10:53:51 +02:00
neo
1c67093ed9 Fix index out of bounds panic when repository has massive tag lists
Co-authored-by: Stefan Haller <stefan@haller-berlin.de>
2025-07-28 16:44:21 +09:00
neo
c54232e863 Move parentHashes and divergence fields before extraInfo in git log format
Like message, extraField can get very long (when there are thousands of tags on
a single commit), so move it to the end; this allows us to truncate overly long
lines in the output and still get all the essential fields.

Co-authored-by: Stefan Haller <stefan@haller-berlin.de>
2025-07-27 18:52:52 +02:00
15f8ad31e0 Cleanup: use nil for empty slice 2025-07-27 18:51:03 +02:00
c5acad777d Don't use hunk mode for added or deleted files
When entering staging (or patch building) for an added or deleted file, it
doesn't make sense to use hunk mode, because pressing space would stage/unstage
the entire file, and if the user wanted to do that, they would have pressed
space in the Files panel. So always use line mode for added/deleted files by
default, even if the useHunkModeInStagingView user config is on.
2025-07-27 12:10:25 +02:00
fc3b725424 Add a test case for a deleted file to TestParseAndFormatPlain
Not because it's terribly important to test here (doesn't hurt though), but
because it will be useful in the next commit for a new test we're adding there.
2025-07-27 12:10:25 +02:00
0f7f1a56df Fix showing diffs for renamed file when filtering by path
When filtering for a file path we use the --follow option for "git log", so it
will follow renames of the file, which is great. However, if you then selected
one of the commits before a rename, you didn't see a diff, because we would pass
the original filter path to the "git show" call.

To fix this, call git log with the --name-status option when filtering by path,
so that each commit reports which file paths are touched in this commit;
remember these in the commit object, so that we can pass them to the "git show"
call later.

Be careful not to store too many such paths unnecessarily. When filtering by
folder rather than file, all these paths will necessarily be inside the original
filter path, so detect this and don't store them in this case.

There is some unfortunate code duplication between loading commits and loading
reflog commits, which I am too lazy to clean up right now.
2025-07-27 12:05:41 +02:00
88dae1d8b9 Refactor commit loading and reflog commit loading to extract shared code
These are very similar in that they call RunAndProcessLines on a git log command
and then process lines to create commits. Extract this into a common helper
function. At the moment this doesn't gain us much, but in the next commit we
will extend this helper function considerably with filter path logic, which
would otherwise have to be duplicated in both places.
2025-07-27 12:05:41 +02:00
e7c33a7a65 Always append -- to git show command
It is good practice to use a -- argument even if no further arguments follow.
Doesn't really make a difference for this particular command though, I think.
2025-07-27 12:05:41 +02:00
92b5bad29d Cleanup: simplify git arguments for reflog loading
The combination of --abbrev=40 and %h can be shortened to %H.
2025-07-27 12:05:41 +02:00
ec82e7c1e7 Make stash filtering work when filtering on a folder 2025-07-27 12:03:06 +02:00
09cbaf2cba Make stash loading work in filtering mode
This broke with the introduction of the age in the stashes list in bc330b8ff3
(which was included in 0.41, so 12 minor versions ago).

This makes it work again when filtering by file, but it still doesn't work when
filtering by folder (and never has). We'll fix that next.
2025-07-27 12:03:06 +02:00
0dfa078653 Revert "chore: use null char as a stash entries divider during loading"
This was not a good idea, and it seems it has never been tested: the --name-only
and -z options don't work well together. Specifically, -z seems to simply cancel
--name-only.

This is not enough to make it work, we'll need more fixes in the next commit.

This reverts commit 50044dd5e0.
2025-07-27 12:03:06 +02:00
0451a16510 Fix --amend when the commit message is empty 2025-07-14 17:58:31 +02:00
562a2aaa6b Un-deprecate UserConfig.Git.Log.Order and ShowGraph
And remove them from AppState.
2025-07-09 13:15:03 +02:00
703256e92d Move LocalBranchSortOrder and RemoteBranchSortOrder to user config
At the same time, we change the defaults for both of them to "date" (they were
"recency" and "alphabetical", respectively, before). This is the reason we need
to touch so many integration tests. For some of them I decided to adapt the test
assertions to the changed sort order; for others, I added a SetupConfig step to
set the order back to "recency" so that I don't have to change what the test
does (e.g. how many SelectNextItem() calls are needed to get to a certain
branch).
2025-07-09 13:15:03 +02:00
f318e45e9d Move DiffContextSize and RenameSimilarityThreshold to user config 2025-07-09 13:15:03 +02:00
8d7bfd131e Move IgnoreWhitespaceInDiffView to user config
When toggling the value in the UI we simply overwrite the value in UserConfig;
this would be bad if there was ever a chance that we want to write the user
config back to disk, but it is very unlikely that we can do that, because
currently we have no way to tell which parts of the config come from the global
config file and which ones come from a repo-local one.
2025-07-09 13:15:03 +02:00
c739357eb9 Remove git version specific code for versions we no longer support 2025-07-09 12:18:58 +02:00
73bf49f8d8 Remove deprecated edit configs
They were deprecated in April 2023 (see 046b0d9daa), so it's been well over a
year now.
2025-07-08 16:32:21 +02:00
41efd9a027 Use non-deprecated 'OS.Open' config in OpenFile test on Windows
This should have been changed in e4e16fa38e.
2025-07-08 16:32:21 +02:00
28bb6a0e80 Remove some unused code 2025-07-08 15:14:45 +02:00
039831a27a Move to next stageable line after adding a line to a custom patch
While it's true that the behavior is a little different from the staging panel,
where the staged lines are actually removed from the view and in many cases the
selection stays more or less in the same place, it is still very useful to move
to the next stageable thing in the custom patch building view too.
2025-07-04 10:14:35 +02:00
ce9fbe58b2 Toggle only added/deleted lines in patch building view
This improves the experience when selecting a hunk generously with the mouse, by
dragging over it including some context lines above and below. Previously we
would consider the "moving end" of the selection range for whether things need
to be added or removed, but this doesn't make sense if it's a context line. Now
we consider the first actual change line that is included in the range.
2025-07-04 10:14:35 +02:00
ef1a141347 Export PatchLine.isChange 2025-07-04 10:14:35 +02:00
42bbe965fa Render only + and - lines as included in a patch
It is confusing to get header lines, hunk headers, or context lines rendered as
being included in a custom patch, when including these makes no difference to
the patch.

This is only a visual change; internally, we still record these non-patch lines
as being included in the patch. It doesn't matter though; you can press space on
a header line and nothing happens.

It would probably be cleaner to only record + and - lines in the includedLines
array, but that would be a bit more work, and doesn't seem worth it.
2025-07-04 10:14:35 +02:00
9511ed9d2c Use a better name for the auto-stash for moving a custom patch to index 2025-07-03 16:56:30 +02:00
32bd9e6029 Drop stash when successfully unstashing files after moving patch to index 2025-07-02 16:19:06 +02:00
00d043d743 Cleanup: implement AllFilesInPatch using lo.Keys
Curiously, the function was never called so far, but we're going to use it later
in this branch.
2025-07-02 16:19:06 +02:00
ca05a2ccea Enable revive linter, and fix a bunch of warnings
I took the set of enabled checks from revive's recommended configuration [1],
and removed some that I didn't like. There might be other useful checks in
revive that we might want to enable, but this is a nice improvement already.

The bulk of the changes here are removing unnecessary else statements after
returns, but there are a few others too.

[1] https://github.com/mgechev/revive?tab=readme-ov-file#recommended-configuration
2025-06-30 19:13:20 +02:00
7aa426fa71 Enable errorlint linter, and fix warnings 2025-06-30 18:30:11 +02:00
0471dbaa84 Enable intrange linter, and fix warnings 2025-06-30 18:30:11 +02:00
c7d0aaa786 Fix warning QF1004: could use strings.ReplaceAll instead 2025-06-30 18:30:11 +02:00
4604227238 Make stashEntryFromLine a free-standing function
It doesn't use the receiver at all, so doesn't have to be a method.

This fixes ST1016: methods on the same type should have the same receiver name.
2025-06-30 18:30:11 +02:00
b7aecf5f17 Fix warning ST1016: methods on the same type should have the same receiver name 2025-06-30 18:30:11 +02:00
e5b09f34e0 Show tag information for selected tag 2025-06-30 16:12:33 +02:00
b12b1040c3 Add IsAnnotated field to models.Tag struct 2025-06-30 16:12:33 +02:00
03abdfcfe2 Fix the CurrentBranchName function
The function would return "head/branchname" when there was either a tag or a
remote with the same name.

While fixing this we slightly change the semantic of the function (and of
determineCheckedOutBranchName, which calls it): for a detached head it now
returns an empty string rather than the commit hash. I actually think this is
better.
2025-06-30 16:08:03 +02:00
f95ac6780f Cleanup: turn around error condition
It is a common go convention for the "happy path" to be as little indented as
possible.
2025-06-30 16:08:03 +02:00
9e05e4d810 fix: show GPG error before entering commit editor
Closes #4611
2025-06-30 08:35:52 +02:00