Commit Graph
5752 Commits
Author SHA1 Message Date
Stefan HallerandClaude Opus 5.5 ce77cfaf92 Lock state.yml while reading or updating it
Two lazygit instances can update state.yml at the same moment. Both
read the same contents, and the second write discards the change of the
first. Also, os.WriteFile empties the file before it writes the new
contents. An instance that reads the file at that moment gets an empty
file, which reads as the default state, or a partial one, which doesn't
parse. This can already happen when several instances start at once,
for example when a tmux session is restored, because each of them
updates state.yml at startup.

Take an exclusive lock on a separate lock file while updating, and a
shared one while reading. Each lock call opens the lock file anew, so
the lock also keeps goroutines of the same instance apart; the test
relies on this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 08:10:59 +01:00
Stefan HallerandClaude Opus 5.5 72ab657cc7 Don't rewrite state.yml if an update doesn't change it
lazygit writes state.yml on every startup to record the current version,
although it's usually the same as the stored one. Switching to the repo
that is already the most recent one rewrites it too. Every write is a
chance for a crash to leave a broken file behind, and the follow-up
work on update checks adds updates that often decide not to change
anything.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 08:10:59 +01:00
Stefan HallerandClaude Opus 5.5 073b76c30c Read state.yml whenever lazygit reads or updates the app state
A common workflow is to keep lazygit open in several terminal tabs, one
per repo. Each instance reads state.yml once at startup and then works
on its own copy. So an instance doesn't see what other instances
changed after it started, and when it saves, it overwrites their
changes. For example, running a shell command with `:` in one tab drops
the commands that another tab added to the history. Switching repos in
one tab drops the repos that another tab added to the recent repos.

Make ReadAppState read the file every time, and make UpdateAppState
apply its change to what it finds in the file. With a full shell
command history the file has about 70 KB, and reading and parsing it
takes less than a millisecond, so we don't need a cache.

Two instances can still update the file at the same moment, and a read
can see a half-written file. The following commits lock the file and
write it atomically.

Since the file is now read at any time and not only at startup, a file
that can't be parsed reads as the defaults, and the next update
replaces it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 08:10:59 +01:00
Stefan HallerandClaude Opus 5.5 c6db95c68d Add tests showing that lazygit instances lose each other's state changes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 08:10:59 +01:00
Stefan HallerandClaude Opus 5.5 76064a302b Replace GetAppState and SaveAppState with ReadAppState and UpdateAppState
Each lazygit instance reads state.yml once at startup. Callers change
that copy and then save all of it. So an instance doesn't see what
other instances changed after it started, and when it saves, it
overwrites their changes.

To fix this, the following commits make ReadAppState read the file and
UpdateAppState apply the change to what it finds in the file. For this
to work, callers must express a change as an operation on the current
state: add a command to the front of the history, remove a history
entry by its value, move the current repo to the front of the recent
repos. The call sites already compute the new value from the current
one; move that code into the update function.

This commit still works on the in-memory copy, so it doesn't change
behavior.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 08:10:58 +01:00
Stefan HallerandClaude Opus 5.5 9ff9479baf Exclude the current repo from the recent repos menu by its path
The menu leaves out the first entry of the recent repos list because
that's the repo we're in. This is true as long as each lazygit instance
keeps its own copy of state.yml. The following commits make instances
read the list from the file. The first entry is then the repo that any
instance opened most recently, and that may be a different one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 08:10:58 +01:00
Stefan HallerandClaude Opus 5.5 ad50d2fb2a Log errors from saving state.yml instead of returning them
If saving state.yml fails while lazygit adds the current repo to the
recent repos list, lazygit stops loading the repo. At startup it exits.
A user on Windows got "The requested operation cannot be performed on
a file with a user-mapped section open" when lazygit opened state.yml
for writing, so lazygit exited on every launch (#4489). Confirming the
intro popup also shows a failed save as an error.

Nothing in state.yml is important enough for this. Log the error
instead, like the other places that save state.yml already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 08:10:58 +01:00
Stefan HallerandClaude Opus 5.5 90039cf7e2 Remove the unused AppState field from Common
Nothing reads it. It's a pointer to the AppConfig's in-memory copy of
state.yml, which the following commits replace with fresh reads of the
file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 08:10:58 +01:00
Stefan HallerandClaude Opus 5.5 5a6d5de3b8 Start with the default app state if state.yml can't be parsed
Several users on Windows reported that lazygit wouldn't start any more
and failed with "yaml: control characters are not allowed" (#3023).
Their state.yml was filled with zero bytes, most likely because the
machine crashed or lost power shortly after lazygit had written the
file. They had to find the file and delete it to make lazygit start
again.

Start with the defaults in this case. The file holds things like the
shell command history and the recent repos list; losing them is better
than not starting. The next save replaces the file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 08:10:58 +01:00
Stefan HallerandClaude Opus 5.5 2d270f0e54 Add a test showing that lazygit doesn't start if state.yml is broken
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 08:10:58 +01:00
Stefan HallerandClaude Opus 5.5 61ef3c770f Move the AppState code into its own file
The following commits add locking and atomic writes for state.yml;
keep that code apart from the user config loading and migration code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 08:10:58 +01:00
Stefan HallerandClaude Opus 5.5 d2321ca27b Show the short hash and subject of a detached HEAD in the new branch prompt
If you press `n` on the row of a detached HEAD in the branches panel,
the title of the prompt contains the full 40-character commit hash.
Since 5dec080719, the Name of a detached HEAD is the full hash.

Describe the commit in the same way as when you press `n` on it in the
commits panel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:34:44 +01:00
Stefan HallerandClaude Opus 5.5 f7c07e4fc2 Add a test showing that the new branch prompt shows the full hash of a detached HEAD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:34:44 +01:00
Stefan HallerandClaude Opus 5.5 6348e8a6af Extract CommitDescription from Commit.Description
A later commit describes a detached HEAD in the same way. Make it work
for hashes shorter than 7 characters. The Name of a detached HEAD is
"HEAD" if `git branch --points-at=HEAD` doesn't report it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:34:44 +01:00
Stefan HallerandClaude Opus 5.5 9dcef62ff2 Show the hash and subject of a detached HEAD in the branches panel
In the branches panel, the row of a detached HEAD has an empty hash
column if gui.showBranchCommitHash is on. In half or full screen mode,
it also has no subject. The branch loader creates this row without the
hash and subject of the commit.

Ask git for the subject too. Show the Name of the row in the hash
column; for a detached HEAD, the Name is the full hash. Leave the
row's CommitHash empty. Otherwise, code that looks for branches at a
commit would take the detached HEAD for a branch. For example, the
checkout menu of the HEAD commit would offer to check it out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:34:44 +01:00
Stefan HallerandClaude Opus 5.5 8fd0684c56 Add a test showing that the branches panel has no hash or subject for a detached HEAD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:34:44 +01:00
Stefan HallerandClaude Opus 5.5 748fe85bef Fix the comment about the Name of a detached HEAD
Since 5dec080719, the Name of a detached HEAD is the full commit hash,
not the part of the DisplayName after "detached at".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:34:44 +01:00
Stefan HallerandClaude Opus 5.5 a28738e04b Show a readable name for a detached HEAD in the status panel
If HEAD is detached, the status panel shows the full 40-character
commit hash after the repo name. This also happens during a rebase,
where it used to show the name of the branch being rebased. Since
5dec080719, the Name of a detached HEAD in the model is the full hash.
That commit made the name work as a ref for git commands, but the
status panel still shows it to the user.

During a rebase, show the name of the branch being rebased again. For
any other detached HEAD, show the same text as the top row of the
branches panel, e.g. "(HEAD detached at v1.2)" or "(no branch, bisect
started on master)".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:31:50 +01:00
Stefan HallerandClaude Opus 5.5 9b3827929c Add tests showing that the status panel shows a commit hash for a detached HEAD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:31:50 +01:00
Stefan HallerandClaude Opus 5.5 73ac8fe6c6 Allow merging into a detached HEAD
Pressing the merge key while HEAD is detached shows an error. This also
happens during a rebase and during a bisect, because HEAD is detached
then. As a result, you can't squash merge another branch at the base of
the current one by starting an interactive rebase with `i`. The
workaround is to squash merge the branch at the tip and move the commit
down. If the merged changes conflict with the branch's own commits, you
have to resolve those conflicts twice this way.

Remove the check. A merge on a detached HEAD is no riskier than a
commit, a cherry-pick or a revert, and lazygit allows all of those
there. It is also useful outside of a rebase, for example to check out
master as a throwaway detached HEAD and merge several branches into it
to see whether they conflict. There is no reason to prevent the user
from doing these things.

If the merge conflicts during a rebase, the merge takes precedence over
the rebase in the working tree state. So continuing goes to the merge
first and then to the rebase.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 14:59:01 +01:00
Stefan HallerandClaude Opus 5.5 bb924c7ccd Use a readable name for a detached HEAD in the rebase and merge menus
If HEAD is detached, the title of the rebase menu contains the full
40-character commit hash. The name comes from the checked-out branch in
the model, and its Name is a commit hash for a detached HEAD.

Use "HEAD" instead, like git does in the messages of merge commits. If
HEAD is detached because of a rebase, use the name of the branch being
rebased.

The merge menu gets the same name for its tooltips and for the squash
merge message. It can't be opened on a detached HEAD yet; the next
commit changes that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 14:59:01 +01:00
Stefan Haller 4b03bf6ac8 Remove the "Become a sponsor" link from the status panel's main view 2026-11-13 08:23:58 +01:00
Stefan Haller b915d25ddb Remove the "Donate" and "Ask Question" links from the status bar
If mouse support is on (the default), the right end of the status bar
shows "Donate" and "Ask Question" links in front of the version number.
They take space away from the keybinding options on the left, so fewer
of those fit before they get cut off.

Remove both links and keep only the version number. Also remove the
paragraph of the intro popup that asks users to click the donate
button.
2026-11-13 08:23:34 +01:00
Stefan Haller 96b9ec6992 Change OpenLinkFailure test to not use the Donate link
We are going to remove the Donate link in the next commit; let the test
click a URL in a commit message in the main view instead.
2026-11-13 08:22:34 +01:00
Stefan HallerandClaude Opus 5.5 b9e0861dfc Show the current search match in full where it overlaps other matches
If the search string can overlap itself, as "aa" can in "aaaa", the
matches overlap too. A cell that is part of two matches shows as part
of the first one. If the second one is the current match, some of its
cells then show in the color of the other matches, and it is hard to
tell where the current match is.

Show a cell as part of the current match whenever it is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 11:28:00 +01:00
Stefan HallerandClaude Opus 5.5 e64b209aed Speed up drawing a view with many search matches
If a search has many matches, scrolling the view becomes laggy. For
example, a search for "e" in a long branch log can find 44000 matches.
With that many, drawing a 100x40 view takes 40ms, where it takes 0.14ms
without a search.

For every cell it draws, draw looks through all the matches to see if
the cell is part of one.

The matches are sorted in the same order as draw visits the cells, so
let draw step through them along with the cells. It finds the first
match on screen with a binary search. Drawing that view now takes
0.14ms with or without a search.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 11:28:00 +01:00
Stefan HallerandClaude Opus 5.5 0bb4566554 Add tests for drawing search matches
No test checks yet which cells draw shows as search matches. The next
commit changes how draw works this out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 11:28:00 +01:00
Stefan HallerandClaude Opus 5.5 0d77b04db3 Don't show search matches and hovered hyperlinks in the inclusion gutter
If a view shows the inclusion gutter and is scrolled sideways, the
gutter shows the highlight of a search match that begins in the columns
scrolled off to the left. The same goes for the underline of a hovered
hyperlink.

Let draw check only the content cells against the search matches and
the hovered hyperlink, and pass the results to setCharacter. The gutter
cells pass neither.

Since draw now works out the content column of a cell once, and not
again for every search match, this also makes drawing with many search
matches faster. With 44000 matches, drawing a 100x40 view took 265ms
and now takes 40ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 11:28:00 +01:00
Stefan HallerandClaude Opus 5.5 5ee580b010 Add tests for search matches and hyperlinks scrolled under the gutter
If a view shows the inclusion gutter and is scrolled sideways, the
gutter shows the search highlight of a match that begins in the
columns scrolled off to the left. It also shows the underline of a
hovered hyperlink that begins there. setCharacter checks every cell it
draws against the search matches and the hovered hyperlink, the cells
of the gutter included. For a gutter cell, the content column it works
out is one of the columns scrolled off to the left.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 11:27:59 +01:00
Stefan HallerandClaude Opus 5.5 cccd088895 Add a benchmark for drawing a view with many search matches
If a search has many matches, scrolling the view becomes laggy because
every draw takes long. Add a benchmark for this, so that later commits
can show how much faster they make drawing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 11:27:59 +01:00
Stefan HallerandClaude Opus 5.5 e2418047df Let benchmarks use WithSimulationScreen
The next commit adds a benchmark that draws a view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 11:27:59 +01:00
Stefan HallerandClaude Opus 5.5 3f73e56fd3 Ignore SIGHUP in the index.lock test hook before forking
sync/lock_error_partway_through_pull_with_rebase failed on CI: every
attempt to continue the rebase ran into index.lock, as if the lock was
never released.

The test hook that holds index.lock starts a background process that
removes the lock once the git command that ran the hook has exited. If
lazygit runs the command in a pty, as it does for a pull, the command's
exit sends SIGHUP to that process. The process ignored SIGHUP, but only
once it got to run. On a busy machine the command can exit before that;
SIGHUP then kills the process and leaves the lock behind. Delaying the
start of the process by 0.3s makes the test fail every time.

Ignore SIGHUP in the hook before starting the background process, so
that the process inherits it. With this, the test passes even with the
delay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:45:44 +01:00
Stefan HallerandClaude Opus 5.5 14a36053e9 Unexport IsPasting
Nothing outside gocui needs to know about pastes any more.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00
Stefan HallerandClaude Opus 5.5 c28e3576d1 Drop pasted keys for views without an OnPaste handler
Every view that takes text has an OnPaste handler now, and views that
don't take text already ignored pasted keys. Make this a single rule.
While a paste is in progress, keys go to the focused view's OnPaste
handler or nowhere. This replaces the check in execKeybindings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00
Stefan HallerandClaude Opus 5.5 9765b96790 Let the search prompt receive pasted text in one piece
Treat pasted text like in the other views that take a single line of
text. Before, a pasted newline confirmed the search, and the rest of
the pasted text was lost.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00
Stefan HallerandClaude Opus 5.5 417dea6381 Let prompts receive pasted text in one piece
Like a menu's filter, a prompt takes a single line of text, so treat
pasted text the same way. Before, the prompt ignored pasted newlines.
This joined the lines without a space. It also ran the keybindings for
other keys in the text, so a pasted Esc closed the prompt, and a pasted
tab switched to the suggestions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00
Stefan HallerandClaude Opus 5.5 e68f195e33 Let a menu's filter receive pasted text in one piece
The filter takes a single line of text. Drop the newlines at the start
and end of the pasted text, and replace the remaining newlines and tabs
with spaces. A pasted newline therefore no longer runs the selected
menu item.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00
Stefan HallerandClaude Opus 5.5 f6ceabdebe Add a test for pasting text into the keybindings menu
The keybindings menu filters as you type. If you paste text that ends
with a newline into it, the text filters the menu, and the newline then
runs the selected item as if you had pressed Enter. The same happens in
the other menus that filter as you type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00
Stefan HallerandClaude Opus 5.5 f3bc6fc85e Extract what the prompt and menu filter editors do after an edit
Handlers for pasted text are going to need the same steps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00
Stefan HallerandClaude Opus 5.5 ebbd2126db Remove hard line breaks from text pasted into the commit description
Do the same as when pasting a commit message with the commit menu, so
that the paragraphs of the body reflow when you edit them. This also
covers a commit message pasted into the summary, since everything after
its first line goes into the description.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00
Stefan HallerandClaude Opus 5.5 ce988017f1 Add a test for pasting a wrapped commit message into the summary
If you paste a commit message into the summary with the terminal's
paste command, the body keeps its hard line breaks. This happens even
where auto-wrapping would break the line at the same place. If you
then edit a paragraph of the body, it doesn't reflow. Pasting with the
commit menu already removes these line breaks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00
Stefan HallerandClaude Opus 5.5 fb21a99035 Return a description driver from Popup.CommitDescriptionPanel
It returned a driver for the summary. This made it impossible to use
the description's driver methods after a test step that moves the
focus to the description, such as pasting a multi-line text into the
summary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00
Stefan HallerandClaude Opus 5.5 107f0c1352 Don't start the description with an empty line when pasting a message
If you paste text into an empty description, drop the newlines at its
start. This happens when you paste a whole commit message into the
summary with the terminal's paste command. The part after the first
line goes into the description, and it starts with the blank line
between subject and body.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00
Stefan HallerandClaude Opus 5.5 f2a63e2de0 Handle text pasted into the commit message panel in one piece
Use the new OnPaste handler for the summary and the description. This
replaces the IsPasting checks in the keybindings for confirming and for
switching between summary and description. These checks only worked for
the default keys of those keybindings. If a user had bound Enter or Tab
to something else, pasting a newline or a tab ran that command.

Otherwise the behavior stays the same, except that the panel now drops
Esc and control characters in pasted text. Before, it executed them;
for example, a pasted Esc closed the panel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00
Stefan HallerandClaude Opus 5.5 0111d9bd61 Let views receive pasted text in one piece
Editable views receive pasted text as one key press per character, so a
newline or a tab in the text triggers the keybinding for Enter or Tab.
The commit message panel works around this by checking IsPasting in
these keybindings. This is fragile, and it gives the panel no way to
look at the pasted text as a whole.

Add an OnPaste handler to View. For a view that has one, collect the
pasted characters, newlines and tabs while the paste lasts, and pass
them to the handler when it ends. Drop all other keys of the paste. They
are unlikely to occur in pasted text, and dispatching keys like Esc in
the middle of a paste would run them as commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00
Stefan HallerandClaude Opus 5.5 9d2058fbc4 Add a test for pasting a multi-line commit message into the summary
If you paste a commit message into the summary with the terminal's
paste command, the description starts with an empty line. The first
newline of the pasted text moves to the description, and the second
one (the blank line between subject and body) is typed into the
description. Git strips the empty line when committing, but it looks
broken in the panel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00
Stefan HallerandClaude Opus 5.5 ad52544df8 Add a test for pasting text into the commit description
It checks that the text goes in at the cursor, and that a tab turns
into spaces instead of switching to the summary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00
Stefan HallerandClaude Opus 5.5 dec9e49162 Add support for pasting text in integration tests
The commit message panel handles pasted text differently from typed
text (see ba6cfc1f85), but integration tests couldn't simulate a
paste, so this had no tests. Let tests replay the events that a
terminal sends for a bracketed paste: the start of the paste, a key
press for each character, and the end of the paste.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00
Stefan HallerandClaude Opus 5.5 b65298c3b1 Remove hard line breaks when pasting a commit message from the clipboard
Do the same as when rewording a commit, so that the paragraphs of the
body reflow when you edit them.

This also matters for the "Copy commit message to clipboard" entry of
the commit menu. It copies the message with the line breaks that
auto-wrapping inserted. Without this change, pasting the copied
message back into the panel would turn these into hard line breaks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00
Stefan HallerandClaude Opus 5.5 1c7ccd5833 Add a test for pasting a commit message that has hard line breaks
If you copy a commit's message with `y` in the commits panel and paste
it into the commit message panel with the commit menu, the body keeps
the hard line breaks that git committed. This happens even where
auto-wrapping would break the line at the same place. If you then edit
a paragraph of the body, it doesn't reflow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:22:50 +01:00