Improve bisecting (#6168)

This PR makes bisecting easier in several ways:

- **Start a bisect from more views.** The bisect menu (`b`) is now also
available in the local branches, remote branches, tags, sub-commits and
reflog views. This makes it possible to mark a branch or tag as good or
bad without checking it out first. Once git knows both a good and a bad
commit, lazygit focuses the commits panel, where the bisect continues.
- **Select the commit to test.** Whenever git picks a new commit to
test, lazygit selects it. Before, this happened only when you marked the
commit to test in lazygit while it was selected. Now it also happens
when lazygit starts during a bisect, when you run `git bisect` commands
in a terminal, and when the commit is further down than the commits that
lazygit loads at first.
- **Select the result.** When the bisect is done, lazygit selects the
first bad commit, so that you can look at it right away. Pressing `b`
afterwards shows the result again and offers to reset the bisect.
Before, the menu offered to mark the commit that you had just marked.
- **Show the log of HEAD until both a good and a bad commit are known.**
If you check out another branch to find a commit to mark, the commits
panel shows that branch.
- **Focus the commits panel at startup** if a bisect is in progress.
- **Mark the remaining commits correctly.** The "?" marks for the
commits that git still has to consider now come from git. They were
missing while git tests the merge base of a good and a bad commit on
different branches, and early in a long bisect.
- **Fix labels.** Before git has picked a commit to test, the bisect
menu names the selected commit instead of calling it the "current
commit". Once the bisect is done, the last tested commit shows its mark
instead of "current".

Closes #2346.
Closes #2941.
Closes #5530.
Closes #6103.
This commit is contained in:
Stefan Haller authored and GitHub committed 2026-10-31 15:12:18 +01:00
commit c9c0db40bd
41 files changed
+1212 -246

No files matched your search

@@ -175,6 +175,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy branch name to clipboard | |
| `` b `` | View bisect options | |
| `` i `` | Show git-flow options | |
| `` <space> `` | Checkout | Checkout selected item. |
| `` n `` | New branch | |
@@ -257,6 +258,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy abbreviated commit hash to clipboard | |
| `` b `` | View bisect options | |
| `` <space> `` | Checkout | Checkout the selected commit as a detached HEAD. |
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | Open commit in browser | |
@@ -287,6 +289,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| `` s `` | Sort order | |
| `` g `` | Reset | View reset options (soft/mixed/hard) for resetting onto selected item. |
| `` <ctrl+t> `` | Open external diff tool (git difftool) | |
| `` b `` | View bisect options | |
| `` 0 `` | Focus main view | |
| `` <enter> `` | View commits | |
| `` / `` | Filter the current view by text | |
@@ -358,6 +361,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy abbreviated commit hash to clipboard | |
| `` b `` | View bisect options | |
| `` <space> `` | Checkout | Checkout the selected commit as a detached HEAD. |
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | Open commit in browser | |
@@ -392,6 +396,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy tag to clipboard | |
| `` b `` | View bisect options | |
| `` <space> `` | Checkout | Checkout the selected tag as a detached HEAD. |
| `` n `` | New tag | Create new tag from current commit. You'll be prompted to enter a tag name and optional description. |
| `` w `` | New worktree | |
@@ -134,6 +134,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy abbreviated commit hash to clipboard | |
| `` b `` | bisectオプションを表示 | |
| `` <space> `` | チェックアウト(ブランチの切り替え) | 選択したコミットをデタッチドヘッド(特定のブランチに属さない状態)としてチェックアウトします。 |
| `` y `` | コミット属性をクリップボードにコピー | コミット属性をクリップボードにコピーします(例:ハッシュ、URL、差分、メッセージ、作者)。 |
| `` o `` | ブラウザでコミットを開く | |
@@ -218,6 +219,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | タグをクリップボードにコピー | |
| `` b `` | bisectオプションを表示 | |
| `` <space> `` | チェックアウト(ブランチの切り替え) | 選択したタグをデタッチドHEADとしてチェックアウトします。 |
| `` n `` | 新しいタグを作成 | 現在のコミットから新しいタグを作成します。タグ名とオプションの説明を入力するよう促されます。 |
| `` w `` | 新しいワークツリー | |
@@ -318,6 +320,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy abbreviated commit hash to clipboard | |
| `` b `` | bisectオプションを表示 | |
| `` <space> `` | チェックアウト(ブランチの切り替え) | 選択したコミットをデタッチドヘッド(特定のブランチに属さない状態)としてチェックアウトします。 |
| `` y `` | コミット属性をクリップボードにコピー | コミット属性をクリップボードにコピーします(例:ハッシュ、URL、差分、メッセージ、作者)。 |
| `` o `` | ブラウザでコミットを開く | |
@@ -360,6 +363,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| `` s `` | 並び順 | |
| `` g `` | リセット | 選択した項目へのリセットオプション(ソフト/ミックス/ハード)を表示します。各リセットタイプの詳細は次の通りです:<br>- ソフトリセット:変更を保持し、ステージされた状態にします<br>- ミックスリセット:変更を保持し、ステージされていない状態にします<br>- ハードリセット:すべての変更を破棄します |
| `` <ctrl+t> `` | 外部差分ツールを開く(git difftool) | |
| `` b `` | bisectオプションを表示 | |
| `` 0 `` | メインビューにフォーカス | |
| `` <enter> `` | コミットを表示 | |
| `` / `` | 現在のビューをテキストでフィルタリング | |
@@ -369,6 +373,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | ブランチ名をクリップボードにコピー | |
| `` b `` | bisectオプションを表示 | |
| `` i `` | git-flowオプションを表示 | |
| `` <space> `` | チェックアウト(ブランチの切り替え) | 選択した項目をチェックアウトします。 |
| `` n `` | 新しいブランチ | |
@@ -65,6 +65,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy abbreviated commit hash to clipboard | |
| `` b `` | Bisect 옵션 보기 | |
| `` <space> `` | 체크아웃 | Checkout the selected commit as a detached HEAD. |
| `` y `` | 커밋 attribute 복사 | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | 브라우저에서 커밋 열기 | |
@@ -124,6 +125,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy abbreviated commit hash to clipboard | |
| `` b `` | Bisect 옵션 보기 | |
| `` <space> `` | 체크아웃 | Checkout the selected commit as a detached HEAD. |
| `` y `` | 커밋 attribute 복사 | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | 브라우저에서 커밋 열기 | |
@@ -205,6 +207,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | 브랜치명을 클립보드에 복사 | |
| `` b `` | Bisect 옵션 보기 | |
| `` i `` | Git-flow 옵션 보기 | |
| `` <space> `` | 체크아웃 | Checkout selected item. |
| `` n `` | 새 브랜치 생성 | |
@@ -283,6 +286,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| `` s `` | Sort order | |
| `` g `` | View reset options | View reset options (soft/mixed/hard) for resetting onto selected item. |
| `` <ctrl+t> `` | Open external diff tool (git difftool) | |
| `` b `` | Bisect 옵션 보기 | |
| `` 0 `` | Focus main view | |
| `` <enter> `` | 커밋 보기 | |
| `` / `` | Filter the current view by text | |
@@ -361,6 +365,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy tag to clipboard | |
| `` b `` | Bisect 옵션 보기 | |
| `` <space> `` | 체크아웃 | Checkout the selected tag as a detached HEAD. |
| `` n `` | 태그를 생성 | Create new tag from current commit. You'll be prompted to enter a tag name and optional description. |
| `` w `` | New worktree | |
@@ -99,6 +99,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Kopieer branch name naar klembord | |
| `` b `` | View bisect options | |
| `` i `` | Laat git-flow opties zien | |
| `` <space> `` | Uitchecken | Geselecteerd item uitchecken. |
| `` n `` | Nieuwe branch | |
@@ -257,6 +258,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy abbreviated commit hash to clipboard | |
| `` b `` | View bisect options | |
| `` <space> `` | Uitchecken | Check de geselecteerde branch uit als een detached HEAD. |
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | Open commit in browser | |
@@ -287,6 +289,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| `` s `` | Sort order | |
| `` g `` | Bekijk reset opties | View reset options (soft/mixed/hard) for resetting onto selected item. |
| `` <ctrl+t> `` | Open externe diff applicatie (git difftool) | |
| `` b `` | View bisect options | |
| `` 0 `` | Focus main view | |
| `` <enter> `` | Bekijk commits | |
| `` / `` | Filter the current view by text | |
@@ -358,6 +361,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy abbreviated commit hash to clipboard | |
| `` b `` | View bisect options | |
| `` <space> `` | Uitchecken | Check de geselecteerde branch uit als een detached HEAD. |
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | Open commit in browser | |
@@ -392,6 +396,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy tag to clipboard | |
| `` b `` | View bisect options | |
| `` <space> `` | Uitchecken | Geselecteerde tag uitchecken als detached HEAD. |
| `` n `` | Creëer tag | Maak een nieuwe tag die naar de huidige commit wijst. Je wordt gevraagd om een tag naam en optionele beschrijving. |
| `` w `` | New worktree | |
@@ -135,6 +135,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy abbreviated commit hash to clipboard | |
| `` b `` | Zobacz opcje bisect | |
| `` <space> `` | Przełącz | Przełącz wybrany commit jako odłączoną HEAD. |
| `` y `` | Kopiuj atrybut commita do schowka | Kopiuj atrybut commita do schowka (np. hash, URL, różnice, wiadomość, autor). |
| `` o `` | Otwórz commit w przeglądarce | |
@@ -162,6 +163,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Kopiuj nazwę gałęzi do schowka | |
| `` b `` | Zobacz opcje bisect | |
| `` i `` | Pokaż opcje git-flow | |
| `` <space> `` | Przełącz | Przełącz wybrany element. |
| `` n `` | Nowa gałąź | |
@@ -337,6 +339,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy abbreviated commit hash to clipboard | |
| `` b `` | Zobacz opcje bisect | |
| `` <space> `` | Przełącz | Przełącz wybrany commit jako odłączoną HEAD. |
| `` y `` | Kopiuj atrybut commita do schowka | Kopiuj atrybut commita do schowka (np. hash, URL, różnice, wiadomość, autor). |
| `` o `` | Otwórz commit w przeglądarce | |
@@ -371,6 +374,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Skopiuj tag do schowka | |
| `` b `` | Zobacz opcje bisect | |
| `` <space> `` | Przełącz | Przełącz wybrany tag jako odłączoną głowę (detached HEAD). |
| `` n `` | Nowy tag | Utwórz nowy tag z bieżącego commita. Zostaniesz poproszony o wprowadzenie nazwy tagu i opcjonalnego opisu. |
| `` w `` | Nowe drzewo pracy | |
@@ -409,6 +413,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| `` s `` | Kolejność sortowania | |
| `` g `` | Reset | Wyświetl opcje resetu (miękki/mieszany/twardy) do wybranego elementu. |
| `` <ctrl+t> `` | Otwórz zewnętrzne narzędzie różnic (git difftool) | |
| `` b `` | Zobacz opcje bisect | |
| `` 0 `` | Focus main view | |
| `` <enter> `` | Pokaż commity | |
| `` / `` | Filtruj bieżący widok po tekście | |
@@ -91,6 +91,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copiar nome da branch para área de transferência | |
| `` b `` | Ver opções de bissecção | |
| `` i `` | Exibir opções do git-flow | |
| `` <space> `` | Verificar | Checar item selecionado |
| `` n `` | Nova branch | |
@@ -132,6 +133,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| `` s `` | Sort order | |
| `` g `` | Restaurar | Ver opções de redefinição (soft/mixed/hard) para redefinir para o item selecionado. |
| `` <ctrl+t> `` | Abrir ferramenta de diff externa (git difftool) | |
| `` b `` | Ver opções de bissecção | |
| `` 0 `` | Focar visualização principal | |
| `` <enter> `` | Ver commits | |
| `` / `` | Filtrar a visualização atual por texto | |
@@ -203,6 +205,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copiar etiqueta para área de transferência | |
| `` b `` | Ver opções de bissecção | |
| `` <space> `` | Verificar | Checar a tag selecionada como um HEAD, desanexado |
| `` n `` | Nova etiqueta | Crie uma nova etiqueta a partir do commit atual. Você será solicitado a digitar um nome e uma descrição opcional. |
| `` w `` | Nova árvore de trabalho | |
@@ -285,6 +288,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy abbreviated commit hash to clipboard | |
| `` b `` | Ver opções de bissecção | |
| `` <space> `` | Verificar | Checkout the selected commit as a detached HEAD. |
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | Abrir commit no navegador | |
@@ -367,6 +371,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy abbreviated commit hash to clipboard | |
| `` b `` | Ver opções de bissecção | |
| `` <space> `` | Verificar | Checkout the selected commit as a detached HEAD. |
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | Abrir commit no navegador | |
@@ -143,6 +143,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy abbreviated commit hash to clipboard | |
| `` b `` | Просмотреть параметры бинарного поиска | |
| `` <space> `` | Переключить | Checkout the selected commit as a detached HEAD. |
| `` y `` | Скопировать атрибут коммита | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | Открыть коммит в браузере | |
@@ -205,6 +206,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Скопировать название ветки в буфер обмена | |
| `` b `` | Просмотреть параметры бинарного поиска | |
| `` i `` | Показать параметры git-flow | |
| `` <space> `` | Переключить | Checkout selected item. |
| `` n `` | Новая ветка | |
@@ -252,6 +254,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy abbreviated commit hash to clipboard | |
| `` b `` | Просмотреть параметры бинарного поиска | |
| `` <space> `` | Переключить | Checkout the selected commit as a detached HEAD. |
| `` y `` | Скопировать атрибут коммита | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
| `` o `` | Открыть коммит в браузере | |
@@ -324,6 +327,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | Copy tag to clipboard | |
| `` b `` | Просмотреть параметры бинарного поиска | |
| `` <space> `` | Переключить | Checkout the selected tag as a detached HEAD. |
| `` n `` | Создать тег | Create new tag from current commit. You'll be prompted to enter a tag name and optional description. |
| `` w `` | New worktree | |
@@ -350,6 +354,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| `` s `` | Порядок сортировки | |
| `` g `` | Просмотреть параметры сброса | View reset options (soft/mixed/hard) for resetting onto selected item. |
| `` <ctrl+t> `` | Open external diff tool (git difftool) | |
| `` b `` | Просмотреть параметры бинарного поиска | |
| `` 0 `` | Focus main view | |
| `` <enter> `` | Просмотреть коммиты | |
| `` / `` | Filter the current view by text | |
@@ -58,6 +58,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | 复制缩略提交哈希值到剪贴板 | |
| `` b `` | 查看二分查找选项 | |
| `` <space> `` | 检出 | 检出所选择的提交作为分离HEAD。 |
| `` y `` | 复制提交属性到剪贴板 | 复制提交属性到剪贴板(如hash、URL、diff、消息、作者)。 |
| `` o `` | 在浏览器中打开提交 | |
@@ -102,6 +103,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | 复制缩略提交哈希值到剪贴板 | |
| `` b `` | 查看二分查找选项 | |
| `` <space> `` | 检出 | 检出所选择的提交作为分离HEAD。 |
| `` y `` | 复制提交属性到剪贴板 | 复制提交属性到剪贴板(如hash、URL、diff、消息、作者)。 |
| `` o `` | 在浏览器中打开提交 | |
@@ -224,6 +226,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | 复制分支名称到剪贴板 | |
| `` b `` | 查看二分查找选项 | |
| `` i `` | 显示 git-flow 选项 | |
| `` <space> `` | 检出 | 检出选中的项目 |
| `` n `` | 新分支 | |
@@ -255,6 +258,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | 复制标签到剪贴板 | |
| `` b `` | 查看二分查找选项 | |
| `` <space> `` | 检出 | 检出选择的标签作为分离的HEAD |
| `` n `` | 创建标签 | 基于当前提交创建一个新标签。您将在弹窗中输入标签名称和描述(可选)。 |
| `` w `` | 新建工作树 | |
@@ -409,6 +413,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| `` s `` | 排序 | |
| `` g `` | 查看重置选项 | 查看重置选项 (soft/mixed/hard) 用于重置到选择项 |
| `` <ctrl+t> `` | 使用外部差异比较工具(git difftool) | |
| `` b `` | 查看二分查找选项 | |
| `` 0 `` | 聚焦主视图 | |
| `` <enter> `` | 查看提交 | |
| `` / `` | 通过文本过滤当前视图 | |
@@ -109,6 +109,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | 複製縮略提交雜湊值到剪貼簿 | |
| `` b `` | 查看二分選項 | |
| `` <space> `` | 檢出 | 檢出所選擇的提交作為分離HEAD。 |
| `` y `` | 複製提交屬性 | 複製提交屬性到剪貼簿(如hash、URL、diff、訊息、作者)。 |
| `` o `` | 在瀏覽器中開啟提交 | |
@@ -236,6 +237,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | 複製縮略提交雜湊值到剪貼簿 | |
| `` b `` | 查看二分選項 | |
| `` <space> `` | 檢出 | 檢出所選擇的提交作為分離HEAD。 |
| `` y `` | 複製提交屬性 | 複製提交屬性到剪貼簿(如hash、URL、diff、訊息、作者)。 |
| `` o `` | 在瀏覽器中開啟提交 | |
@@ -256,6 +258,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | 複製分支名稱到剪貼簿 | |
| `` b `` | 查看二分選項 | |
| `` i `` | 顯示 git-flow 選項 | |
| `` <space> `` | 檢出 | 檢出選定的項目。 |
| `` n `` | 新分支 | |
@@ -287,6 +290,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| Key | Action | Info |
|-----|--------|-------------|
| `` <ctrl+o> `` | 複製標籤到剪貼簿 | |
| `` b `` | 查看二分選項 | |
| `` <space> `` | 檢出 | 檢出選擇的標籤作為分離的HEAD。 |
| `` n `` | 建立標籤 | 基於目前提交建立一個新標籤。您將在彈窗中輸入標籤名稱和描述(可選)。 |
| `` w `` | 新建工作樹 | |
@@ -409,6 +413,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
| `` s `` | 排序規則 | |
| `` g `` | 檢視重設選項 | 檢視重置選項 (soft/mixed/hard) 用於重置到選擇項。 |
| `` <ctrl+t> `` | 開啟外部差異工具 (git difftool) | |
| `` b `` | 查看二分選項 | |
| `` 0 `` | 聚焦主檢視 | |
| `` <enter> `` | 檢視提交 | |
| `` / `` | 搜尋 | |
+56
View File
@@ -3,7 +3,12 @@ package git_commands
import (
"os"
"path/filepath"
"strconv"
"strings"
"github.com/jesseduffield/generics/set"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/samber/lo"
)
type BisectCommands struct {
@@ -180,6 +185,40 @@ func (self *BisectCommands) IsDone() (bool, []string, error) {
return done, candidates, nil
}
// Asks git which of the given commits the bisect hasn't ruled out yet, and
// stores them in the bisect info. Git may list many more commits than these,
// so we don't keep the others.
func (self *BisectCommands) LoadCandidates(info *BisectInfo, commits []*models.Commit) error {
if !info.Bisecting() {
return nil
}
oldHashes := lo.Keys(lo.PickBy(info.statusMap, func(_ string, status BisectStatus) bool {
return status == BisectStatusOld
}))
cmdArgs := NewGitCmd("rev-list").
Arg(info.GetNewHash(), "--not").
Arg(oldHashes...).
ToArgv()
loadedHashes := set.NewFromSlice(lo.Map(commits, func(commit *models.Commit, _ int) string {
return commit.Hash()
}))
candidates := set.New[string]()
err := self.cmd.New(cmdArgs).DontLog().RunAndProcessLines(func(line string) (bool, error) {
if hash := strings.TrimSpace(line); loadedHashes.Includes(hash) {
candidates.Add(hash)
}
return false, nil
})
if err != nil {
return err
}
info.candidates = candidates
return nil
}
// tells us whether the 'start' ref that we'll be sent back to after we're done
// bisecting is actually a descendant of our current bisect commit. If it's not, we need to
// render the commits from the bad commit.
@@ -192,3 +231,20 @@ func (self *BisectCommands) ReachableFromStart(bisectInfo *BisectInfo) bool {
return err == nil
}
// Returns the number of commits that are reachable from logRef but not from
// the given commit. In a log of logRef, parents come after their children
// (unless the log uses git's default order and commit dates are skewed), so
// the commit is at most this many commits down from the top.
func (self *BisectCommands) CountCommitsAbove(hash string, logRef string) (int, error) {
cmdArgs := NewGitCmd("rev-list").
Arg("--count", hash+".."+logRef).
ToArgv()
output, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
if err != nil {
return 0, err
}
return strconv.Atoi(strings.TrimSpace(output))
}
+29
View File
@@ -2,6 +2,7 @@ package git_commands
import (
"github.com/jesseduffield/generics/maps"
"github.com/jesseduffield/generics/set"
"github.com/samber/lo"
"github.com/sirupsen/logrus"
)
@@ -34,6 +35,11 @@ type BisectInfo struct {
// the hash of the commit that's under test
current string
// the commits that the bisect hasn't ruled out yet, among those that the
// commits view has loaded. Nil until BisectCommands.LoadCandidates is
// called.
candidates *set.Set[string]
}
type BisectStatus int
@@ -63,6 +69,29 @@ func (self *BisectInfo) GetCurrentHash() string {
return self.current
}
// Whether git has checked out a commit for the user to test, and the user
// hasn't marked it yet. After the user marks it, git checks out the next one,
// unless there's nothing left to test. This is the case if git has found the
// first new commit, or if only skipped commits are left. Git checks out the
// first commit to test once it knows both a new and an old commit, unless the
// old commit is a parent of the new one.
func (self *BisectInfo) HasCommitToTest() bool {
if self.current == "" {
return false
}
_, marked := self.statusMap[self.current]
return !marked
}
// Whether the bisect hasn't ruled out the commit yet. This is the case if the
// new commit can reach it, but no old one can, so it includes the new commit
// and the skipped ones. Only known for the commits that the commits view has
// loaded.
func (self *BisectInfo) IsCandidate(commitHash string) bool {
return self.candidates != nil && self.candidates.Includes(commitHash)
}
func (self *BisectInfo) GetStartHash() string {
return self.start
}
+2 -2
View File
@@ -56,7 +56,7 @@ func NewCommitLoader(
}
type GetCommitsOptions struct {
Limit bool
Limit int // the maximum number of commits to load, or 0 to load all of them
FilterPath string
FilterAuthor string
IncludeRebaseCommits bool
@@ -611,7 +611,7 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) *oscommands.CmdObj {
Arg(prettyFormat).
Arg("--abbrev=40").
ArgIf(opts.FilterAuthor != "", "--author="+opts.FilterAuthor).
ArgIf(opts.Limit, "-300").
ArgIf(opts.Limit > 0, fmt.Sprintf("-%d", opts.Limit)).
ArgIf(opts.FilterPath != "", "--follow", "--name-status").
Arg("--no-show-signature").
ArgIf(opts.RefToShowDivergenceFrom != "", "--left-right").
+12
View File
@@ -343,6 +343,10 @@ type LocalCommitsViewModel struct {
// commits refresh reads it on the UI thread to decide how many commits to load.
limitCommits atomic.Bool
// The limit that the commits in the model were loaded with, or 0 if they
// were loaded without one.
loadedCommitLimit int
// If this is true we'll use git log --all when fetching the commits.
showWholeGitGraph bool
}
@@ -431,6 +435,14 @@ func (self *LocalCommitsViewModel) GetLimitCommits() bool {
return self.limitCommits.Load()
}
func (self *LocalCommitsViewModel) SetLoadedCommitLimit(value int) {
self.loadedCommitLimit = value
}
func (self *LocalCommitsViewModel) GetLoadedCommitLimit() int {
return self.loadedCommitLimit
}
func (self *LocalCommitsViewModel) SetShowWholeGitGraph(value bool) {
self.showWholeGitGraph = value
}
+13 -2
View File
@@ -174,8 +174,11 @@ type SubCommitsViewModel struct {
refToShowDivergenceFrom string
*ListViewModel[*models.Commit]
limitCommits bool
showBranchHeads bool
limitCommits bool
// The limit that the commits in the model were loaded with, or 0 if they
// were loaded without one.
loadedCommitLimit int
showBranchHeads bool
}
func (self *SubCommitsViewModel) SetRef(ref models.Ref) {
@@ -239,6 +242,14 @@ func (self *SubCommitsContext) GetLimitCommits() bool {
return self.limitCommits
}
func (self *SubCommitsContext) SetLoadedCommitLimit(value int) {
self.loadedCommitLimit = value
}
func (self *SubCommitsContext) GetLoadedCommitLimit() int {
return self.loadedCommitLimit
}
func (self *SubCommitsContext) GetDiffTerminals() []string {
itemId := self.GetSelectedItemId()
+11 -3
View File
@@ -146,8 +146,6 @@ func (gui *Gui) resetHelpersAndControllers() {
submodulesController := controllers.NewSubmodulesController(common)
bisectController := controllers.NewBisectController(common)
commitMessageController := controllers.NewCommitMessageController(
common,
)
@@ -311,9 +309,19 @@ func (gui *Gui) resetHelpersAndControllers() {
controllers.AttachControllers(gui.State.Contexts.LocalCommits,
localCommitsController,
bisectController,
)
for _, context := range []controllers.CanBisect{
gui.State.Contexts.LocalCommits,
gui.State.Contexts.SubCommits,
gui.State.Contexts.ReflogCommits,
gui.State.Contexts.Branches,
gui.State.Contexts.RemoteBranches,
gui.State.Contexts.Tags,
} {
controllers.AttachControllers(context, controllers.NewBisectController(common, context))
}
controllers.AttachControllers(gui.State.Contexts.CommitFiles,
commitFilesController,
)
+194 -148
View File
@@ -9,28 +9,41 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/samber/lo"
)
type CanBisect interface {
types.IListContext
GetSelectedRef() models.Ref
}
// Offers the bisect menu for the selected item. The commits panel is where the
// user bisects: it shows the good, bad and skipped commits, and the one to test
// next. The other views only offer marking their selected item as good or bad,
// until git knows both a good and a bad commit.
type BisectController struct {
baseController
*ListControllerTrait[*models.Commit]
c *ControllerCommon
*ListControllerTrait[models.Ref]
c *ControllerCommon
context CanBisect
}
var _ types.IController = &BisectController{}
func NewBisectController(
c *ControllerCommon,
context CanBisect,
) *BisectController {
return &BisectController{
baseController: baseController{},
c: c,
context: context,
ListControllerTrait: NewListControllerTrait(
c,
c.Contexts().LocalCommits,
c.Contexts().LocalCommits.GetSelected,
c.Contexts().LocalCommits.GetSelectedItems,
context,
context.GetSelectedRef,
func() ([]models.Ref, int, int) {
panic("Not implemented")
},
),
}
}
@@ -38,120 +51,83 @@ func NewBisectController(
func (self *BisectController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
bindings := []*types.Binding{
{
Keys: opts.GetKeys(opts.Config.Commits.ViewBisectOptions),
Handler: opts.Guards.OutsideFilterMode(self.withItem(self.openMenu)),
Description: self.c.Tr.ViewBisectOptions,
OpensMenu: true,
Keys: opts.GetKeys(opts.Config.Commits.ViewBisectOptions),
Handler: opts.Guards.OutsideFilterMode(self.withItem(self.openMenu)),
GetDisabledReason: self.notBisectingOutsideCommitsPanel,
Description: self.c.Tr.ViewBisectOptions,
OpensMenu: true,
},
}
return bindings
}
func (self *BisectController) openMenu(commit *models.Commit) error {
func (self *BisectController) isCommitsPanel() bool {
return self.context.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY
}
func (self *BisectController) notBisectingOutsideCommitsPanel() *types.DisabledReason {
if !self.isCommitsPanel() && self.c.Model().BisectInfo.Bisecting() {
return &types.DisabledReason{Text: self.c.Tr.Bisect.UseCommitsPanel}
}
return nil
}
func (self *BisectController) openMenu(ref models.Ref) error {
// no shame in getting this directly rather than using the cached value
// given how cheap it is to obtain
info := self.c.Git().Bisect.GetInfo()
if info.Started() {
return self.openMidBisectMenu(info, commit)
if !info.Started() {
return self.openStartBisectMenu(info, ref)
}
return self.openStartBisectMenu(info, commit)
if !info.Bisecting() {
return self.openMenuBeforeBisecting(info, ref)
}
if !info.HasCommitToTest() {
return self.showBisectResult()
}
return self.openMidBisectMenu(info, ref)
}
func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, commit *models.Commit) error {
// if there is not yet a 'current' bisect commit, or if we have
// selected the current commit, we need to jump to the next 'current' commit
// after we perform a bisect action. The reason we don't unconditionally jump
// is that sometimes the user will want to go and mark a few commits as skipped
// in a row and they wouldn't want to be jumped back to the current bisect
// commit each time.
// Originally we were allowing the user to, from the bisect menu, select whether
// they were talking about the selected commit or the current bisect commit,
// and that was a bit confusing (and required extra keypresses).
selectCurrentAfter := info.GetCurrentHash() == "" || info.GetCurrentHash() == commit.Hash()
// we need to wait to reselect if our bisect commits aren't ancestors of our 'start'
// ref, because we'll be reloading our commits in that case.
waitToReselect := selectCurrentAfter && !self.c.Git().Bisect.ReachableFromStart(info)
// Git has nothing left for the user to test, so show the result, and offer to
// reset the bisect.
func (self *BisectController) showBisectResult() error {
done, candidateHashes, err := self.c.Git().Bisect.IsDone()
if err != nil {
return err
}
// If we have a current hash already, then we always want to use that one. If
// not, we're still picking the initial commits before we really start, so
// use the selected commit in that case.
if !done {
// Git stopped without finding the first bad commit, for example
// because the merge base of the good and the bad commit is bad. Git
// said why when it stopped, so all that's left to do is to reset.
return self.c.Helpers().Bisect.Reset()
}
bisecting := info.GetCurrentHash() != ""
hashToMark := lo.Ternary(bisecting, info.GetCurrentHash(), commit.Hash())
shortHashToMark := utils.ShortHash(hashToMark)
return self.showBisectCompleteMessage(candidateHashes)
}
// For marking a commit as bad, when we're not already bisecting, we require
// a single item selected, but once we are bisecting, it doesn't matter because
// the action applies to the HEAD commit rather than the selected commit.
var singleItemIfNotBisecting *types.DisabledReason
if !bisecting {
singleItemIfNotBisecting = self.require(self.singleItemSelected())()
// The menu for when a bisect has started, but git doesn't know both a good and
// a bad commit yet. Its entries act on the selected item.
func (self *BisectController) openMenuBeforeBisecting(info *git_commands.BisectInfo, ref models.Ref) error {
disabledReason := self.require(self.singleItemSelected())()
refDescription := self.describeRef(ref)
markLabel := func(term string) string {
return utils.ResolvePlaceholderString(self.c.Tr.Bisect.MarkRef,
map[string]string{"ref": refDescription, "term": term})
}
menuItems := []*types.MenuItem{
{
Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, shortHashToMark, info.NewTerm()),
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectMark)
if err := self.c.Git().Bisect.Mark(hashToMark, info.NewTerm()); err != nil {
return err
}
return self.afterMark(selectCurrentAfter, waitToReselect)
},
DisabledReason: singleItemIfNotBisecting,
Keys: menuKey('b'),
},
{
Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, shortHashToMark, info.OldTerm()),
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectMark)
if err := self.c.Git().Bisect.Mark(hashToMark, info.OldTerm()); err != nil {
return err
}
return self.afterMark(selectCurrentAfter, waitToReselect)
},
DisabledReason: singleItemIfNotBisecting,
Keys: menuKey('g'),
},
{
Label: fmt.Sprintf(self.c.Tr.Bisect.SkipCurrent, shortHashToMark),
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectSkip)
if err := self.c.Git().Bisect.Skip(hashToMark); err != nil {
return err
}
return self.afterMark(selectCurrentAfter, waitToReselect)
},
DisabledReason: singleItemIfNotBisecting,
Keys: menuKey('s'),
},
self.markMenuItem(markLabel(info.NewTerm()), ref.FullRefName(), info.NewTerm(), disabledReason, 'b'),
self.markMenuItem(markLabel(info.OldTerm()), ref.FullRefName(), info.OldTerm(), disabledReason, 'g'),
}
if info.GetCurrentHash() != "" && info.GetCurrentHash() != commit.Hash() {
menuItems = append(menuItems, lo.ToPtr(types.MenuItem{
Label: fmt.Sprintf(self.c.Tr.Bisect.SkipSelected, commit.ShortHash()),
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectSkip)
if err := self.c.Git().Bisect.Skip(commit.Hash()); err != nil {
return err
}
return self.afterMark(selectCurrentAfter, waitToReselect)
},
DisabledReason: self.require(self.singleItemSelected())(),
Keys: menuKey('S'),
}))
if self.isCommitsPanel() {
menuItems = append(menuItems, self.skipMenuItem(
utils.ResolvePlaceholderString(self.c.Tr.Bisect.SkipRef, map[string]string{"ref": refDescription}),
ref.FullRefName(), types.KeepCommitSelectionByHash, disabledReason, 's'))
}
menuItems = append(menuItems, lo.ToPtr(types.MenuItem{
Label: self.c.Tr.Bisect.ResetOption,
OnPress: func() error {
return self.c.Helpers().Bisect.Reset()
},
Keys: menuKey('r'),
}))
menuItems = append(menuItems, self.resetMenuItem())
return self.c.Menu(types.CreateMenuOptions{
Title: self.c.Tr.Bisect.BisectMenuTitle,
@@ -159,19 +135,130 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
})
}
func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo, commit *models.Commit) error {
// The menu for while bisecting. Its entries act on the commit that git wants the
// user to test, except for the one that skips the selected commit.
func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, ref models.Ref) error {
currentHash := info.GetCurrentHash()
shortCurrentHash := utils.ShortHash(currentHash)
menuItems := []*types.MenuItem{
self.markMenuItem(
fmt.Sprintf(self.c.Tr.Bisect.Mark, shortCurrentHash, info.NewTerm()),
currentHash, info.NewTerm(), nil, 'b'),
self.markMenuItem(
fmt.Sprintf(self.c.Tr.Bisect.Mark, shortCurrentHash, info.OldTerm()),
currentHash, info.OldTerm(), nil, 'g'),
self.skipMenuItem(
fmt.Sprintf(self.c.Tr.Bisect.SkipCurrent, shortCurrentHash),
currentHash, types.KeepCommitSelectionByHash, nil, 's'),
}
if currentHash != ref.FullRefName() {
menuItems = append(menuItems, self.skipMenuItem(
fmt.Sprintf(self.c.Tr.Bisect.SkipSelected, utils.ShortHash(ref.FullRefName())),
ref.FullRefName(),
// Git may pick a different commit to test now. Keep the skipped
// commit selected anyway, so that the user can go on skipping
// commits near it.
types.KeepCommitSelectionIndex,
self.require(self.singleItemSelected())(),
'S'))
}
menuItems = append(menuItems, self.resetMenuItem())
return self.c.Menu(types.CreateMenuOptions{
Title: self.c.Tr.Bisect.BisectMenuTitle,
Items: menuItems,
})
}
// Returns how the bisect menu refers to the given item.
func (self *BisectController) describeRef(ref models.Ref) string {
switch ref := ref.(type) {
case *models.Branch:
// The branches view shows a detached head as a branch, too
if !ref.DetachedHead {
return utils.ResolvePlaceholderString(self.c.Tr.Bisect.BranchRef,
map[string]string{"name": ref.RefName()})
}
case *models.RemoteBranch:
return utils.ResolvePlaceholderString(self.c.Tr.Bisect.BranchRef,
map[string]string{"name": ref.RefName()})
case *models.Tag:
return utils.ResolvePlaceholderString(self.c.Tr.Bisect.TagRef,
map[string]string{"name": ref.RefName()})
}
return utils.ResolvePlaceholderString(self.c.Tr.Bisect.CommitRef,
map[string]string{"hash": utils.ShortHash(ref.FullRefName())})
}
func (self *BisectController) markMenuItem(label string, ref string, term string, disabledReason *types.DisabledReason, key rune) *types.MenuItem {
return &types.MenuItem{
Label: label,
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectMark)
if err := self.c.Git().Bisect.Mark(ref, term); err != nil {
return err
}
if !self.isCommitsPanel() && self.c.Git().Bisect.GetInfo().Bisecting() {
// Git knows both a good and a bad commit now, so the user goes
// on in the commits panel
self.c.Context().Push(self.c.Contexts().LocalCommits, types.OnFocusOpts{})
}
return self.afterMark(types.KeepCommitSelectionByHash)
},
DisabledReason: disabledReason,
Keys: menuKey(key),
}
}
func (self *BisectController) skipMenuItem(label string, ref string, commitSelection types.CommitSelectionBehavior, disabledReason *types.DisabledReason, key rune) *types.MenuItem {
return &types.MenuItem{
Label: label,
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectSkip)
if err := self.c.Git().Bisect.Skip(ref); err != nil {
return err
}
return self.afterMark(commitSelection)
},
DisabledReason: disabledReason,
Keys: menuKey(key),
}
}
func (self *BisectController) resetMenuItem() *types.MenuItem {
return &types.MenuItem{
Label: self.c.Tr.Bisect.ResetOption,
OnPress: func() error {
return self.c.Helpers().Bisect.Reset()
},
Keys: menuKey('r'),
}
}
func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo, ref models.Ref) error {
refDescription := self.describeRef(ref)
markLabel := func(term string) string {
return utils.ResolvePlaceholderString(self.c.Tr.Bisect.MarkRefStart,
map[string]string{"ref": refDescription, "term": term})
}
return self.c.Menu(types.CreateMenuOptions{
Title: self.c.Tr.Bisect.BisectMenuTitle,
Items: []*types.MenuItem{
{
Label: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortHash(), info.NewTerm()),
Label: markLabel(info.NewTerm()),
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.StartBisect)
if err := self.c.Git().Bisect.Start(); err != nil {
return err
}
if err := self.c.Git().Bisect.Mark(commit.Hash(), info.NewTerm()); err != nil {
if err := self.c.Git().Bisect.Mark(ref.FullRefName(), info.NewTerm()); err != nil {
return err
}
@@ -182,14 +269,14 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
Keys: menuKey('b'),
},
{
Label: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortHash(), info.OldTerm()),
Label: markLabel(info.OldTerm()),
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.StartBisect)
if err := self.c.Git().Bisect.Start(); err != nil {
return err
}
if err := self.c.Git().Bisect.Mark(commit.Hash(), info.OldTerm()); err != nil {
if err := self.c.Git().Bisect.Mark(ref.FullRefName(), info.OldTerm()); err != nil {
return err
}
@@ -256,15 +343,13 @@ func (self *BisectController) showBisectCompleteMessage(candidateHashes []string
return nil
}
func (self *BisectController) afterMark(selectCurrent bool, waitToReselect bool) error {
func (self *BisectController) afterMark(commitSelection types.CommitSelectionBehavior) error {
done, candidateHashes, err := self.c.Git().Bisect.IsDone()
if err != nil {
return err
}
if err := self.afterBisectMarkRefresh(selectCurrent, waitToReselect); err != nil {
return err
}
self.c.Refresh(types.RefreshOptions{CommitSelection: commitSelection})
if done {
return self.showBisectCompleteMessage(candidateHashes)
@@ -272,42 +357,3 @@ func (self *BisectController) afterMark(selectCurrent bool, waitToReselect bool)
return nil
}
func (self *BisectController) afterBisectMarkRefresh(selectCurrent bool, waitToReselect bool) error {
selectFn := func() error {
if selectCurrent {
self.selectCurrentBisectCommit()
}
return nil
}
if waitToReselect {
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{}, Then: selectFn})
return nil
}
if err := selectFn(); err != nil {
return err
}
self.c.Helpers().Bisect.PostBisectCommandRefresh()
return nil
}
func (self *BisectController) selectCurrentBisectCommit() {
info := self.c.Git().Bisect.GetInfo()
if info.GetCurrentHash() != "" {
// find index of commit with that hash, move cursor to that.
for i, commit := range self.c.Model().Commits {
if commit.Hash() == info.GetCurrentHash() {
self.context().SetSelection(i)
self.context().HandleFocus(types.OnFocusOpts{})
break
}
}
}
}
func (self *BisectController) context() *context.LocalCommitsContext {
return self.c.Contexts().LocalCommits
}
+122 -28
View File
@@ -134,6 +134,14 @@ type refreshEnv struct {
batch *refreshBounceBatch
}
// focusOpts returns the options for re-rendering the views this refresh updates.
func (env refreshEnv) focusOpts() types.OnFocusOpts {
return types.OnFocusOpts{
KeepScrollPosition: env.keepScrollPosition,
SkipMainViewUpdate: env.skipMainViewUpdate,
}
}
// refreshBounceBatch collects the UI-thread bounces of a batched refresh so they
// can be applied together in one frame rather than one scope at a time. The
// scopes run on separate worker goroutines and add concurrently, hence the
@@ -750,6 +758,10 @@ func (self *RefreshHelper) refreshReflogAndBranches(capturedReflog capturedReflo
return nil
}
// The number of commits that the commits and sub-commits views load at first,
// to keep things fast. They load the rest when the user scrolls near the end.
const commitLimit = 300
// capturedCommitState holds everything the commits refresh reads from the
// model, contexts, and modes. It is gathered on the UI thread (see
// captureCommitsState) before the git work is dispatched to a worker, so the
@@ -842,9 +854,10 @@ func (self *RefreshHelper) determineCheckedOutRef(env refreshEnv) models.Ref {
func (self *RefreshHelper) refreshCommitsWithLimit(captured capturedCommitState, commitSelection types.CommitSelectionBehavior, env refreshEnv) error {
checkedOutRef := self.determineCheckedOutRef(env)
refName, bisectInfo := self.refForLog(env)
limit := self.commitLimitForLog(captured.limitCommits, refName, bisectInfo, env)
commits, err := env.git.Loaders.CommitLoader.GetCommits(
git_commands.GetCommitsOptions{
Limit: captured.limitCommits,
Limit: limit,
FilterPath: captured.filterPath,
FilterAuthor: captured.filterAuthor,
IncludeRebaseCommits: true,
@@ -858,19 +871,26 @@ func (self *RefreshHelper) refreshCommitsWithLimit(captured capturedCommitState,
if err != nil {
return err
}
if err := env.git.Bisect.LoadCandidates(bisectInfo, commits); err != nil {
self.c.Log.Warnf("Failed to find the commits that the bisect hasn't ruled out yet: %v", err)
}
workingTreeState := env.git.Status.WorkingTreeState()
self.onUIThreadUnlessRepoChanged(env, func() {
var selectionRange *localCommitSelectionRange
var newConflictedCommitIdx *int
var jumpToCommitIdx *int
if commitSelection == types.KeepCommitSelectionByHash {
selectedIdx, rangeStartIdx, rangeSelectMode := self.c.Contexts().LocalCommits.GetSelectionRangeAndMode()
selectionRange = captureLocalCommitSelectionRange(self.c.Model().Commits, selectedIdx, rangeStartIdx, rangeSelectMode)
newConflictedCommitIdx = findNewConflictedCommit(self.c.Model().Commits, commits)
jumpToCommitIdx = findNewConflictedCommit(self.c.Model().Commits, commits)
if jumpToCommitIdx == nil {
jumpToCommitIdx = findNewBisectCommitToSelect(self.c.Model().BisectInfo, bisectInfo, commits)
}
}
self.c.Model().BisectInfo = bisectInfo
self.c.Model().Commits = commits
self.c.Contexts().LocalCommits.SetLoadedCommitLimit(limit)
self.c.Model().CommitsWereFilteredAtLastRefresh = captured.filterPath != "" || captured.filterAuthor != ""
self.RefreshAuthors(commits)
self.c.Model().WorkingTreeStateAtLastCommitRefresh = workingTreeState
@@ -886,8 +906,8 @@ func (self *RefreshHelper) refreshCommitsWithLimit(captured capturedCommitState,
self.c.Contexts().LocalCommits.SetSelection(headCommitIdx)
}
case types.KeepCommitSelectionByHash:
if newConflictedCommitIdx != nil {
self.c.Contexts().LocalCommits.SetSelection(*newConflictedCommitIdx)
if jumpToCommitIdx != nil {
self.c.Contexts().LocalCommits.SetSelection(*jumpToCommitIdx)
} else if selectionRange != nil {
selectedIdx, rangeStartIdx, found := findLocalCommitSelectionRange(commits, selectionRange)
if found {
@@ -897,9 +917,17 @@ func (self *RefreshHelper) refreshCommitsWithLimit(captured capturedCommitState,
case types.KeepCommitSelectionIndex:
// The caller set the selection index deliberately; leave it untouched.
}
focusOpts := env.focusOpts()
if jumpToCommitIdx != nil {
// We selected a commit that the user needs to look at next, so
// scroll it into view even if the refresh keeps the scroll position
// otherwise.
focusOpts.KeepScrollPosition = false
}
self.rerenderView(self.c.Contexts().LocalCommits, focusOpts)
})
self.refreshView(self.c.Contexts().LocalCommits, env)
return nil
}
@@ -991,6 +1019,42 @@ func findNewConflictedCommit(previousCommits []*models.Commit, commits []*models
return nil
}
// Returns the index of the commit that the user needs to look at during a
// bisect, if it is in the new commits slice and it is a different commit than
// at the previous refresh (or there wasn't one then). Otherwise returns nil.
func findNewBisectCommitToSelect(previousBisectInfo *git_commands.BisectInfo, bisectInfo *git_commands.BisectInfo, commits []*models.Commit) *int {
hash := bisectCommitToSelect(bisectInfo)
if hash == "" || hash == bisectCommitToSelect(previousBisectInfo) {
return nil
}
_, idx, found := lo.FindIndexOf(commits, func(commit *models.Commit) bool {
return commit.Hash() == hash
})
if found {
return &idx
}
return nil
}
// Returns the commit that the user needs to look at during a bisect: the one
// that git wants them to test, or the first bad commit once git has found it.
// Returns "" if git doesn't know both a good and a bad commit yet.
func bisectCommitToSelect(bisectInfo *git_commands.BisectInfo) string {
if !bisectInfo.Bisecting() {
return ""
}
if bisectInfo.HasCommitToTest() {
return bisectInfo.GetCurrentHash()
}
// There's nothing left to test, so the commit marked bad is the first bad
// commit. (If only skipped commits are left, it is one of the candidates.)
return bisectInfo.GetNewHash()
}
// capturedSubCommitState holds the sub-commits refresh's model/context/mode
// inputs, gathered on the UI thread (see captureSubCommitState) before the git
// work is dispatched to a worker.
@@ -1023,9 +1087,10 @@ func (self *RefreshHelper) refreshSubCommitsWithLimit(captured capturedSubCommit
return nil
}
limit := lo.Ternary(captured.limitCommits, commitLimit, 0)
commits, err := env.git.Loaders.CommitLoader.GetCommits(
git_commands.GetCommitsOptions{
Limit: captured.limitCommits,
Limit: limit,
FilterPath: captured.filterPath,
FilterAuthor: captured.filterAuthor,
IncludeRebaseCommits: false,
@@ -1041,6 +1106,7 @@ func (self *RefreshHelper) refreshSubCommitsWithLimit(captured capturedSubCommit
}
self.onUIThreadUnlessRepoChanged(env, func() {
self.c.Model().SubCommits = commits
self.c.Contexts().SubCommits.SetLoadedCommitLimit(limit)
self.RefreshAuthors(commits)
})
@@ -1705,18 +1771,43 @@ func (self *RefreshHelper) refreshStatus(env refreshEnv) {
func (self *RefreshHelper) refForLog(env refreshEnv) (string, *git_commands.BisectInfo) {
bisectInfo := env.git.Bisect.GetInfo()
if !bisectInfo.Started() {
// Until we know both a good and a bad commit, git hasn't checked out
// anything for the user to test, and the user may be checking out
// branches to find the commits to mark. Show the log of what's checked
// out, as usual.
if !bisectInfo.Bisecting() {
return "HEAD", bisectInfo
}
// need to see if our bisect's current commit is reachable from our 'new' ref.
if bisectInfo.Bisecting() && !env.git.Bisect.ReachableFromStart(bisectInfo) {
if !env.git.Bisect.ReachableFromStart(bisectInfo) {
return bisectInfo.GetNewHash(), bisectInfo
}
return bisectInfo.GetStartHash(), bisectInfo
}
// commitLimitForLog returns the number of commits to load for the commits view,
// or 0 to load all of them.
func (self *RefreshHelper) commitLimitForLog(limitCommits bool, refName string, bisectInfo *git_commands.BisectInfo, env refreshEnv) int {
if !limitCommits {
return 0
}
if hash := bisectCommitToSelect(bisectInfo); hash != "" {
// Load the commit that the user needs to look at, and as many commits
// after it as we load from the top otherwise. This way we can select it
// without having to load all commits.
count, err := env.git.Bisect.CountCommitsAbove(hash, refName)
if err == nil {
return count + commitLimit
}
self.c.Log.Warnf("Failed to count the commits above the bisect commit to select: %v", err)
}
return commitLimit
}
func (self *RefreshHelper) refreshView(context types.Context, env refreshEnv) {
// refreshView is called from the worker goroutine that drives async
// refreshes, so bounce to the UI thread before mutating view content. Guard
@@ -1725,27 +1816,30 @@ func (self *RefreshHelper) refreshView(context types.Context, env refreshEnv) {
// dropped, so there's nothing fresh to render — and the captured context
// belongs to the old repo's now-replaced context tree anyway.
self.onUIThreadUnlessRepoChanged(env, func() {
// Re-applying the filter must be done before re-rendering the view, so that
// the filtered list model is up to date for rendering.
self.searchHelper.ReApplyFilter(context)
self.rerenderView(context, env.focusOpts())
})
}
self.c.PostRefreshUpdateWithOptions(context, types.OnFocusOpts{
KeepScrollPosition: env.keepScrollPosition,
SkipMainViewUpdate: env.skipMainViewUpdate,
})
// rerenderView re-renders a context's view after a refresh has updated the
// model it shows. It must run on the UI thread.
func (self *RefreshHelper) rerenderView(context types.Context, opts types.OnFocusOpts) {
// Re-applying the filter must be done before re-rendering the view, so that
// the filtered list model is up to date for rendering.
self.searchHelper.ReApplyFilter(context)
self.c.AfterLayout(func() error {
// Re-applying the search must be done after re-rendering the view though,
// so that the "x of y" status is shown correctly.
//
// Also, it must be done after layout, because otherwise FocusPoint
// hasn't been called yet (see ListContextTrait.FocusLine), which means
// that the scroll position might be such that the entire visible
// content is outside the viewport. And this would cause problems in
// searchModelCommits.
self.searchHelper.ReApplySearch(context)
return nil
})
self.c.PostRefreshUpdateWithOptions(context, opts)
self.c.AfterLayout(func() error {
// Re-applying the search must be done after re-rendering the view though,
// so that the "x of y" status is shown correctly.
//
// Also, it must be done after layout, because otherwise FocusPoint
// hasn't been called yet (see ListContextTrait.FocusLine), which means
// that the scroll position might be such that the entire visible
// content is outside the viewport. And this would cause problems in
// searchModelCommits.
self.searchHelper.ReApplySearch(context)
return nil
})
}
@@ -34,7 +34,7 @@ type ViewSubCommitsOpts struct {
func (self *SubCommitsHelper) ViewSubCommits(opts ViewSubCommitsOpts) error {
commits, err := self.c.Git().Loaders.CommitLoader.GetCommits(
git_commands.GetCommitsOptions{
Limit: true,
Limit: commitLimit,
FilterPath: self.c.Modes().Filtering.GetPath(),
FilterAuthor: self.c.Modes().Filtering.GetAuthor(),
IncludeRebaseCommits: false,
@@ -60,6 +60,7 @@ func (self *SubCommitsHelper) ViewSubCommits(opts ViewSubCommitsOpts) error {
subCommitsContext.SetRef(opts.Ref)
subCommitsContext.SetRefToShowDivergenceFrom(opts.RefToShowDivergenceFrom)
subCommitsContext.SetLimitCommits(true)
subCommitsContext.SetLoadedCommitLimit(commitLimit)
subCommitsContext.SetShowBranchHeads(opts.ShowBranchHeads)
subCommitsContext.ClearSearchString()
subCommitsContext.GetView().ClearSearch()
@@ -18,8 +18,26 @@ import (
"github.com/stefanhaller/git-todo-parser/todo"
)
// after selecting the 200th commit, we'll load in all the rest
const COMMIT_THRESHOLD = 200
// If the selection gets this close to the end of the commits that we loaded,
// we load all the rest
const loadAllCommitsMargin = 100
type canLoadAllCommits interface {
GetSelectedLineIdx() int
GetLimitCommits() bool
SetLimitCommits(value bool)
GetLoadedCommitLimit() int
}
// If we loaded only the first commits of a list, and the selection gets close to
// the end of them, load all of them.
func loadAllCommitsIfSelectionIsNearEnd(c *ControllerCommon, context canLoadAllCommits, scope types.RefreshableView) {
limit := context.GetLoadedCommitLimit()
if context.GetLimitCommits() && limit > 0 && context.GetSelectedLineIdx() > limit-loadAllCommitsMargin {
context.SetLimitCommits(false)
c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{scope}})
}
}
// How long a commit move may take before the drop indicator switches to a
// "moving commits here" spinner; quick moves stay free of flicker.
@@ -1807,11 +1825,7 @@ func (self *LocalCommitsController) handleOpenLogMenu() error {
func (self *LocalCommitsController) GetOnFocus() func(types.OnFocusOpts) {
return func(types.OnFocusOpts) {
context := self.context()
if context.GetSelectedLineIdx() > COMMIT_THRESHOLD && context.GetLimitCommits() {
context.SetLimitCommits(false)
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}})
}
loadAllCommitsIfSelectionIsNearEnd(self.c, self.context(), types.COMMITS)
}
}
@@ -64,10 +64,6 @@ func (self *SubCommitsController) GetOnRenderToMain() func() {
func (self *SubCommitsController) GetOnFocus() func(types.OnFocusOpts) {
return func(types.OnFocusOpts) {
context := self.context()
if context.GetSelectedLineIdx() > COMMIT_THRESHOLD && context.GetLimitCommits() {
context.SetLimitCommits(false)
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUB_COMMITS}})
}
loadAllCommitsIfSelectionIsNearEnd(self.c, self.context(), types.SUB_COMMITS)
}
}
+6 -2
View File
@@ -666,7 +666,7 @@ func (gui *Gui) resetState(startArgs appTypes.StartArgs) types.Context {
gui.applySidePanelConfig()
return initialContext(contextTree, startArgs)
return initialContext(contextTree, startArgs, gui.git.Bisect.GetInfo().Started())
}
func (gui *Gui) loadCachedPullRequests() []*models.GithubPullRequest {
@@ -754,7 +754,7 @@ func parseScreenModeArg(screenModeArg string) types.ScreenMode {
}
}
func initialContext(contextTree *context.ContextTree, startArgs appTypes.StartArgs) types.IListContext {
func initialContext(contextTree *context.ContextTree, startArgs appTypes.StartArgs, bisectStarted bool) types.IListContext {
var initialContext types.IListContext = contextTree.Files
if startArgs.FilterPath != "" {
@@ -772,6 +772,10 @@ func initialContext(contextTree *context.ContextTree, startArgs appTypes.StartAr
default:
panic("unhandled git arg")
}
} else if bisectStarted {
// The commits panel shows how far the bisect has got, and the user
// marks the commits to test there
initialContext = contextTree.LocalCommits
}
return initialContext
+8 -40
View File
@@ -36,11 +36,6 @@ var (
pipeSetCacheAuthorColors = authors.ColorsVersion()
)
type bisectBounds struct {
newIndex int
oldIndex int
}
func GetCommitListDisplayStrings(
common *common.Common,
commits []*models.Commit,
@@ -78,8 +73,6 @@ func GetCommitListDisplayStrings(
filteredCommits := commits[startIdx:endIdx]
bisectBounds := getbisectBounds(commits, bisectInfo)
// function expects to be passed the index of the commit in terms of the `commits` slice
var getGraphLine func(int) string
if showGraph {
@@ -187,14 +180,14 @@ func GetCommitListDisplayStrings(
reservedWidths := getReservedColumnWidths(
commits, common.UserConfig().Gui.CommitHashLength, fullDescription,
timeFormat, shortTimeFormat, now, bisectInfo, bisectBounds)
timeFormat, shortTimeFormat, now, bisectInfo)
lines := make([][]string, 0, len(filteredCommits))
var bisectStatus BisectStatus
willBeRebased := markedBaseCommit == ""
for i, commit := range filteredCommits {
unfilteredIdx := i + startIdx
bisectStatus = getBisectStatus(unfilteredIdx, commit.Hash(), bisectInfo, bisectBounds)
bisectStatus = getBisectStatus(commit.Hash(), bisectInfo)
isMarkedBaseCommit := commit.Hash() != "" && commit.Hash() == markedBaseCommit
if isMarkedBaseCommit {
willBeRebased = true
@@ -243,16 +236,15 @@ func getReservedColumnWidths(
shortTimeFormat string,
now time.Time,
bisectInfo *git_commands.BisectInfo,
bisectBounds *bisectBounds,
) reservedColumnWidths {
result := reservedColumnWidths{}
for i, commit := range commits {
for _, commit := range commits {
result.hash = max(result.hash, utils.StringWidth(getHashText(commit, hashLength)))
if commit.IsTODO() {
result.action = max(result.action, utils.StringWidth(getActionText(commit)))
}
bisectStatus := getBisectStatus(i, commit.Hash(), bisectInfo, bisectBounds)
bisectStatus := getBisectStatus(commit.Hash(), bisectInfo)
result.bisect = max(result.bisect,
utils.StringWidth(getBisectStatusText(bisectStatus, bisectInfo)))
}
@@ -274,29 +266,6 @@ func getReservedColumnWidths(
return result
}
func getbisectBounds(commits []*models.Commit, bisectInfo *git_commands.BisectInfo) *bisectBounds {
if !bisectInfo.Bisecting() {
return nil
}
bisectBounds := &bisectBounds{}
for i, commit := range commits {
if commit.Hash() == bisectInfo.GetNewHash() {
bisectBounds.newIndex = i
}
status, ok := bisectInfo.Status(commit.Hash())
if ok && status == git_commands.BisectStatusOld {
bisectBounds.oldIndex = i
return bisectBounds
}
}
// shouldn't land here
return nil
}
// precondition: slice is not empty
func indexOfFirstNonTODOCommit(commits []*models.Commit) int {
for i, commit := range commits {
@@ -345,19 +314,18 @@ const (
BisectStatusOld
BisectStatusNew
BisectStatusSkipped
// adding candidate here which isn't present in the commands package because
// we need to actually go through the commits to get this info
// a commit that has no mark, and that the bisect hasn't ruled out yet
BisectStatusCandidate
// also adding this
BisectStatusCurrent
)
func getBisectStatus(index int, commitHash string, bisectInfo *git_commands.BisectInfo, bisectBounds *bisectBounds) BisectStatus {
func getBisectStatus(commitHash string, bisectInfo *git_commands.BisectInfo) BisectStatus {
if !bisectInfo.Started() {
return BisectStatusNone
}
if bisectInfo.GetCurrentHash() == commitHash {
if bisectInfo.HasCommitToTest() && bisectInfo.GetCurrentHash() == commitHash {
return BisectStatusCurrent
}
@@ -372,7 +340,7 @@ func getBisectStatus(index int, commitHash string, bisectInfo *git_commands.Bise
return BisectStatusSkipped
}
} else {
if bisectBounds != nil && index >= bisectBounds.newIndex && index <= bisectBounds.oldIndex {
if bisectInfo.IsCandidate(commitHash) {
return BisectStatusCandidate
}
return BisectStatusNone
+14 -2
View File
@@ -1039,7 +1039,7 @@ type TranslationSet struct {
}
type Bisect struct {
MarkStart string
MarkRefStart string
ResetTitle string
ResetPrompt string
ResetOption string
@@ -1048,8 +1048,14 @@ type Bisect struct {
NewTermPrompt string
BisectMenuTitle string
Mark string
MarkRef string
SkipCurrent string
SkipSelected string
SkipRef string
CommitRef string
BranchRef string
TagRef string
UseCommitsPanel string
CompleteTitle string
CompletePrompt string
CompletePromptIndeterminate string
@@ -2371,9 +2377,15 @@ func EnglishTranslationSet() *TranslationSet {
},
Bisect: Bisect{
Mark: "Mark current commit (%s) as %s",
MarkStart: "Mark %s as %s (start bisect)",
MarkRefStart: "Mark {{.ref}} as {{.term}} (start bisect)",
SkipCurrent: "Skip current commit (%s)",
SkipSelected: "Skip selected commit (%s)",
MarkRef: "Mark {{.ref}} as {{.term}}",
SkipRef: "Skip {{.ref}}",
CommitRef: "commit {{.hash}}",
BranchRef: "branch '{{.name}}'",
TagRef: "tag '{{.name}}'",
UseCommitsPanel: "Bisecting is in progress; use the commits panel",
ResetTitle: "Reset 'git bisect'",
ResetPrompt: "Are you sure you want to reset 'git bisect'?",
ResetOption: "Reset bisect",
+2 -2
View File
@@ -414,8 +414,8 @@ func (self *Shell) Stash(message string) *Shell {
return self
}
func (self *Shell) StartBisect(good string, bad string) *Shell {
self.RunCommand([]string{"git", "bisect", "start", good, bad})
func (self *Shell) StartBisect(bad string, good string) *Shell {
self.RunCommand([]string{"git", "bisect", "start", bad, good})
return self
}
@@ -0,0 +1,55 @@
package bisect
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var CheckOutBranchBeforeBisecting = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Check out a different branch after marking a commit as good, but before marking one as bad",
ExtraCmdArgs: []string{},
Skip: false,
SetupRepo: func(shell *Shell) {
shell.
CreateNCommits(3).
NewBranch("feature").
CreateNCommitsStartingAt(3, 4).
Checkout("master")
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.GetUserConfig().Git.Log.ShowGraph = "never"
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
SelectedLine(Contains("CI commit-03")).
Press(keys.Commits.ViewBisectOptions).
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("Bisect")).Select(MatchesRegexp(`Mark .* as good`)).Confirm()
}).
Lines(
Contains("CI commit-03").Contains("<-- good"),
Contains("CI commit-02"),
Contains("CI commit-01"),
)
t.Views().Branches().
Focus().
NavigateToLine(Contains("feature")).
PressPrimaryAction().
Lines(
Contains("* feature"),
Contains("master"),
)
t.Views().Commits().
Lines(
Contains("CI commit-06"),
Contains("CI commit-05"),
Contains("CI commit-04"),
Contains("CI commit-03").Contains("<-- good"),
Contains("CI commit-02"),
Contains("CI commit-01"),
)
},
})
@@ -6,7 +6,7 @@ import (
)
var FromOtherBranch = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Opening lazygit when bisect has been started from another branch. There's an issue where we don't reselect the current branch if we mark the current branch as bad so this test side-steps that problem",
Description: "Opening lazygit when bisect has been started from another branch",
ExtraCmdArgs: []string{},
Skip: false,
SetupRepo: func(shell *Shell) {
@@ -25,11 +25,10 @@ var FromOtherBranch = NewIntegrationTest(NewIntegrationTestArgs{
Focus().
TopLines(
MatchesRegexp(`<-- bad.*commit-08`),
MatchesRegexp(`<-- current.*commit-07`),
MatchesRegexp(`<-- current.*commit-07`).IsSelected(),
MatchesRegexp(`\?.*commit-06`),
MatchesRegexp(`<-- good.*commit-05`),
).
SelectNextItem().
Press(keys.Commits.ViewBisectOptions).
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("Bisect")).Select(MatchesRegexp(`Mark .* as good`)).Confirm()
@@ -0,0 +1,38 @@
package bisect
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var MarkCandidatesWhileTestingMergeBase = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Mark the commits that the bisect hasn't ruled out yet while git tests the merge base of the good and the bad commit",
ExtraCmdArgs: []string{},
Skip: false,
SetupRepo: func(shell *Shell) {
shell.
CreateNCommits(2).
NewBranch("fixed").
CreateNCommitsStartingAt(1, 3).
Checkout("master").
CreateNCommitsStartingAt(2, 4).
// The good commit-03 is on another branch, so git checks out the
// merge base commit-02 to test first
StartBisect("master", "fixed")
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.GetUserConfig().Git.Log.ShowGraph = "never"
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
IsFocused().
Lines(
Contains("CI commit-05").Contains("<-- bad"),
MatchesRegexp(`\?.*commit-04`),
Contains("CI commit-02").Contains("<-- current").IsSelected(),
// This is an ancestor of the good commit-03, so the bisect has
// ruled it out
Contains("CI commit-01").DoesNotContain("?"),
)
},
})
@@ -0,0 +1,41 @@
package bisect
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var OfferResetWhenMergeBaseIsBad = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Offer to reset instead of showing the bisect menu when git stopped because the merge base is bad",
ExtraCmdArgs: []string{},
Skip: false,
SetupRepo: func(shell *Shell) {
shell.
CreateNCommits(2).
NewBranch("fixed").
CreateNCommitsStartingAt(1, 3).
Checkout("master").
CreateNCommitsStartingAt(2, 4).
// Git checks out the merge base commit-02 to test first. If it is
// bad, git can't find the first bad commit, and stops.
StartBisect("master", "fixed").
RunCommandExpectError([]string{"git", "bisect", "bad"})
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.GetUserConfig().Git.Log.ShowGraph = "never"
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
IsFocused().
Lines(
Contains("CI commit-05"),
Contains("CI commit-04"),
Contains("CI commit-02").Contains("<-- bad").IsSelected(),
Contains("CI commit-01"),
).
Press(keys.Commits.ViewBisectOptions).
Tap(func() {
t.ExpectPopup().Confirmation().Title(Equals("Reset 'git bisect'")).Content(Equals("Are you sure you want to reset 'git bisect'?")).Cancel()
})
},
})
@@ -0,0 +1,35 @@
package bisect
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var SelectCurrentCommit = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Select the current bisect commit whenever it changes, but not on every refresh",
ExtraCmdArgs: []string{},
Skip: false,
SetupRepo: func(shell *Shell) {
shell.
CreateNCommits(10).
StartBisect("HEAD", "HEAD~9")
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.GetUserConfig().Git.Log.ShowGraph = "never"
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
SelectedLine(Contains("CI commit-05").Contains("<-- current")).
NavigateToLine(Contains("CI commit-08")).
Tap(func() {
t.RefreshInBackground()
}).
SelectedLine(Contains("CI commit-08")).
Tap(func() {
t.Shell().RunCommand([]string{"git", "bisect", "good"})
t.RefreshInBackground()
}).
SelectedLine(Contains("CI commit-07").Contains("<-- current"))
},
})
@@ -0,0 +1,33 @@
package bisect
import (
"fmt"
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var SelectCurrentCommitInLongRange = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Select the current bisect commit when it is further down than the commits that we load at first, and mark the commits around it that the bisect hasn't ruled out yet",
ExtraCmdArgs: []string{},
Skip: false,
SetupRepo: func(shell *Shell) {
for i := range 700 {
shell.EmptyCommit(fmt.Sprintf("commit %03d", i+1))
}
shell.StartBisect("HEAD", "HEAD~699")
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.GetUserConfig().Git.Log.ShowGraph = "never"
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
SelectedLine(Contains("<-- current")).
// The commits between the current one and the good one are still
// to be tested. The good one is further down than the commits that
// we load.
SelectNextItem().
SelectedLine(Contains("?"))
},
})
@@ -0,0 +1,46 @@
package bisect
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var SelectFirstBadCommit = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Select the first bad commit when marking the last commit to test finishes the bisect",
ExtraCmdArgs: []string{},
Skip: false,
SetupRepo: func(shell *Shell) {
shell.
CreateNCommits(10).
StartBisect("HEAD~2", "HEAD~5")
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.GetUserConfig().Git.Log.ShowGraph = "never"
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
IsFocused().
TopLines(
Contains("CI commit-10"),
Contains("CI commit-09"),
Contains("CI commit-08").Contains("<-- bad"),
Contains("CI commit-07").Contains("<-- current").IsSelected(),
Contains("CI commit-06"),
Contains("CI commit-05").Contains("<-- good"),
).
Press(keys.Commits.ViewBisectOptions).
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("Bisect")).Select(MatchesRegexp(`Mark .* as good`)).Confirm()
t.ExpectPopup().Alert().Title(Equals("Bisect complete")).Content(MatchesRegexp("(?s)commit-08.*Do you want to reset")).Cancel()
}).
TopLines(
Contains("CI commit-10"),
Contains("CI commit-09"),
Contains("CI commit-08").Contains("<-- bad").IsSelected(),
Contains("CI commit-07").Contains("<-- good"),
Contains("CI commit-06"),
Contains("CI commit-05").Contains("<-- good"),
)
},
})
@@ -0,0 +1,28 @@
package bisect
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var SelectFirstBadCommitOnStartup = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Select the first bad commit when starting with a finished bisect",
ExtraCmdArgs: []string{},
Skip: false,
SetupRepo: func(shell *Shell) {
shell.
CreateNCommits(10).
StartBisect("HEAD~2", "HEAD~5").
// Mark commit-07, the commit that git checked out to test. This
// finishes the bisect, because commit-08 is bad.
RunCommand([]string{"git", "bisect", "good"})
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.GetUserConfig().Git.Log.ShowGraph = "never"
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
IsFocused().
SelectedLine(Contains("CI commit-08").Contains("<-- bad"))
},
})
@@ -0,0 +1,38 @@
package bisect
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var ShowResultAgain = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Show the result of a finished bisect again instead of the bisect menu",
ExtraCmdArgs: []string{},
Skip: false,
SetupRepo: func(shell *Shell) {
shell.
CreateNCommits(10).
StartBisect("HEAD~2", "HEAD~5").
// Mark commit-07, the commit that git checked out to test. This
// finishes the bisect, because commit-08 is bad.
RunCommand([]string{"git", "bisect", "good"})
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.GetUserConfig().Git.Log.ShowGraph = "never"
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
IsFocused().
SelectedLine(Contains("CI commit-08").Contains("<-- bad")).
Press(keys.Commits.ViewBisectOptions).
Tap(func() {
t.ExpectPopup().Alert().Title(Equals("Bisect complete")).Content(MatchesRegexp("(?s)commit-08.*Do you want to reset")).Cancel()
})
t.Views().Branches().
Focus().
Press(keys.Commits.ViewBisectOptions)
t.ExpectToast(Equals("Disabled: Bisecting is in progress; use the commits panel"))
},
})
@@ -0,0 +1,41 @@
package bisect
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var ShowResultWhenFoundRightAway = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Show the result instead of the bisect menu when git found the first bad commit without testing any",
ExtraCmdArgs: []string{},
Skip: false,
SetupRepo: func(shell *Shell) {
shell.
CreateNCommits(3).
// The good commit is the parent of the bad one, so git doesn't
// check out anything to test
StartBisect("HEAD", "HEAD~1")
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.GetUserConfig().Git.Log.ShowGraph = "never"
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
IsFocused().
Lines(
Contains("CI commit-03").Contains("<-- bad").IsSelected(),
Contains("CI commit-02").Contains("<-- good"),
Contains("CI commit-01"),
).
Press(keys.Commits.ViewBisectOptions).
Tap(func() {
t.ExpectPopup().Alert().Title(Equals("Bisect complete")).Content(MatchesRegexp("(?s)commit-03.*Do you want to reset")).Cancel()
})
t.Views().Branches().
Focus().
Press(keys.Commits.ViewBisectOptions)
t.ExpectToast(Equals("Disabled: Bisecting is in progress; use the commits panel"))
},
})
+11 -1
View File
@@ -27,7 +27,17 @@ var Skip = NewIntegrationTest(NewIntegrationTestArgs{
NavigateToLine(Contains("commit-01")).
Press(keys.Commits.ViewBisectOptions).
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("Bisect")).Select(MatchesRegexp(`Mark .* as good`)).Confirm()
t.ExpectPopup().Menu().Title(Equals("Bisect")).
// There's no current commit yet, so the entries act on the
// selected commit:
Lines(
Contains("b Mark commit").Contains("as bad"),
Contains("g Mark commit").Contains("as good"),
Contains("s Skip commit"),
Contains("r Reset bisect"),
Contains("Cancel"),
).
Select(MatchesRegexp(`Mark .* as good`)).Confirm()
t.Views().Information().Content(Contains("Bisecting"))
}).
Lines(
@@ -0,0 +1,77 @@
package bisect
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var StartFromBranches = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Start a bisect by marking the heads of two branches as good and bad in the branches panel",
ExtraCmdArgs: []string{},
Skip: false,
SetupRepo: func(shell *Shell) {
shell.
CreateNCommits(3).
NewBranch("feature").
CreateNCommitsStartingAt(6, 4).
Checkout("master")
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.GetUserConfig().Git.Log.ShowGraph = "never"
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Branches().
Focus().
Lines(
Contains("master").IsSelected(),
Contains("feature"),
).
Press(keys.Commits.ViewBisectOptions).
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("Bisect")).
Lines(
Contains("b Mark branch 'master' as bad (start bisect)"),
Contains("g Mark branch 'master' as good (start bisect)"),
Contains("t Choose bisect terms"),
Contains("Cancel"),
).
Select(Contains("as good")).Confirm()
t.Views().Information().Content(Contains("Bisecting"))
}).
NavigateToLine(Contains("feature")).
Press(keys.Commits.ViewBisectOptions).
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("Bisect")).
Lines(
Contains("b Mark branch 'feature' as bad"),
Contains("g Mark branch 'feature' as good"),
Contains("r Reset bisect"),
Contains("Cancel"),
).
Select(Contains("as bad")).Confirm()
})
t.Views().Commits().
IsFocused().
Lines(
Contains("CI commit-09").Contains("<-- bad"),
Contains("CI commit-08"),
Contains("CI commit-07"),
Contains("CI commit-06").Contains("<-- current").IsSelected(),
Contains("CI commit-05"),
Contains("CI commit-04"),
Contains("CI commit-03").Contains("<-- good"),
Contains("CI commit-02"),
Contains("CI commit-01"),
)
// Once git knows both a good and a bad commit, the bisect continues in
// the commits panel
t.Views().Branches().
Focus().
Press(keys.Commits.ViewBisectOptions)
t.ExpectToast(Equals("Disabled: Bisecting is in progress; use the commits panel"))
},
})
@@ -0,0 +1,70 @@
package bisect
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var StartFromSubCommitsAndReflog = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Start a bisect by marking a commit of a branch as bad and a reflog entry as good",
ExtraCmdArgs: []string{},
Skip: false,
SetupRepo: func(shell *Shell) {
shell.
CreateNCommits(3).
NewBranch("feature").
CreateNCommitsStartingAt(3, 4).
Checkout("master")
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.GetUserConfig().Git.Log.ShowGraph = "never"
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Branches().
Focus().
NavigateToLine(Contains("feature")).
PressEnter()
t.Views().SubCommits().
IsFocused().
SelectedLine(Contains("CI commit-06")).
Press(keys.Commits.ViewBisectOptions).
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("Bisect")).
Lines(
MatchesRegexp(`b Mark commit [0-9a-f]+ as bad \(start bisect\)`),
MatchesRegexp(`g Mark commit [0-9a-f]+ as good \(start bisect\)`),
Contains("t Choose bisect terms"),
Contains("Cancel"),
).
Select(Contains("as bad")).Confirm()
}).
PressEscape()
t.Views().ReflogCommits().
Focus().
NavigateToLine(Contains("commit-01")).
Press(keys.Commits.ViewBisectOptions).
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("Bisect")).
Lines(
MatchesRegexp(`b Mark commit [0-9a-f]+ as bad`),
MatchesRegexp(`g Mark commit [0-9a-f]+ as good`),
Contains("r Reset bisect"),
Contains("Cancel"),
).
Select(Contains("as good")).Confirm()
})
t.Views().Commits().
IsFocused().
Lines(
Contains("CI commit-06").Contains("<-- bad"),
Contains("CI commit-05"),
Contains("CI commit-04"),
Contains("CI commit-03").Contains("<-- current").IsSelected(),
Contains("CI commit-02"),
Contains("CI commit-01").Contains("<-- good"),
)
},
})
@@ -0,0 +1,76 @@
package bisect
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var StartFromTagsAndRemoteBranches = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Start a bisect by marking a tag as good and a remote branch as bad",
ExtraCmdArgs: []string{},
Skip: false,
SetupRepo: func(shell *Shell) {
shell.
CreateNCommits(2).
CreateLightweightTag("v1.0", "HEAD").
CreateNCommitsStartingAt(4, 3).
CloneIntoRemote("origin").
HardReset("HEAD~2")
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.GetUserConfig().Git.Log.ShowGraph = "never"
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Tags().
Focus().
Lines(
Contains("v1.0").IsSelected(),
).
Press(keys.Commits.ViewBisectOptions).
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("Bisect")).
Lines(
Contains("b Mark tag 'v1.0' as bad (start bisect)"),
Contains("g Mark tag 'v1.0' as good (start bisect)"),
Contains("t Choose bisect terms"),
Contains("Cancel"),
).
Select(Contains("as good")).Confirm()
})
t.Views().Remotes().
Focus().
Lines(
Contains("origin").IsSelected(),
).
PressEnter()
t.Views().RemoteBranches().
IsFocused().
Lines(
Contains("master").IsSelected(),
).
Press(keys.Commits.ViewBisectOptions).
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("Bisect")).
Lines(
Contains("b Mark branch 'origin/master' as bad"),
Contains("g Mark branch 'origin/master' as good"),
Contains("r Reset bisect"),
Contains("Cancel"),
).
Select(Contains("as bad")).Confirm()
})
t.Views().Commits().
IsFocused().
Lines(
Contains("CI commit-06").Contains("<-- bad"),
Contains("CI commit-05"),
Contains("CI commit-04").Contains("<-- current").IsSelected(),
Contains("CI commit-03"),
Contains("CI v1.0 commit-02").Contains("<-- good"),
Contains("CI commit-01"),
)
},
})
@@ -0,0 +1,32 @@
package bisect
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var StartInCommitsPanel = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Focus the commits panel at startup when a bisect is in progress",
ExtraCmdArgs: []string{},
Skip: false,
SetupRepo: func(shell *Shell) {
shell.
CreateNCommits(3).
// The bisect is in progress, although git knows only a bad commit
// so far
RunCommand([]string{"git", "bisect", "start"}).
RunCommand([]string{"git", "bisect", "bad"})
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.GetUserConfig().Git.Log.ShowGraph = "never"
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
IsFocused().
Lines(
Contains("CI commit-03").Contains("<-- bad").IsSelected(),
Contains("CI commit-02"),
Contains("CI commit-01"),
)
},
})
+14
View File
@@ -36,9 +36,22 @@ import (
var tests = []*components.IntegrationTest{
bisect.Basic,
bisect.CheckOutBranchBeforeBisecting,
bisect.ChooseTerms,
bisect.FromOtherBranch,
bisect.MarkCandidatesWhileTestingMergeBase,
bisect.OfferResetWhenMergeBaseIsBad,
bisect.SelectCurrentCommit,
bisect.SelectCurrentCommitInLongRange,
bisect.SelectFirstBadCommit,
bisect.SelectFirstBadCommitOnStartup,
bisect.ShowResultAgain,
bisect.ShowResultWhenFoundRightAway,
bisect.Skip,
bisect.StartFromBranches,
bisect.StartFromSubCommitsAndReflog,
bisect.StartFromTagsAndRemoteBranches,
bisect.StartInCommitsPanel,
branch.CheckoutAutostash,
branch.CheckoutByName,
branch.CheckoutPreviousBranch,
@@ -655,6 +668,7 @@ var tests = []*components.IntegrationTest{
tag.ResetToDuplicateNamedBranch,
ui.Accordion,
ui.BackgroundRefreshKeepsScrollPosition,
ui.BackgroundRefreshScrollsToConflictedCommit,
ui.BranchesNotFirstTab,
ui.CommitsNotFirstTab,
ui.DisableSwitchTabWithPanelJumpKeys,
@@ -0,0 +1,37 @@
package ui
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var BackgroundRefreshScrollsToConflictedCommit = NewIntegrationTest(NewIntegrationTestArgs{
Description: "A background refresh that selects a newly conflicted commit scrolls it into view",
ExtraCmdArgs: []string{},
Skip: false,
Width: 120,
Height: 30,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.EmptyCommit("initial commit")
shell.CreateFileAndAdd("file.txt", "master content")
shell.Commit("master commit")
shell.NewBranchFrom("branch", "master^")
shell.CreateFileAndAdd("file.txt", "branch content")
shell.Commit("this will conflict")
shell.CreateNCommits(30)
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Focus().
SelectedLine(Contains("commit-30")).
Tap(func() {
t.Shell().RunCommandExpectError([]string{"git", "rebase", "master"})
t.RefreshInBackground()
}).
// The conflicted commit, below the 30 pending todos and their header
SelectedLineIdx(31).
SelectedLineIsVisible().
SelectedLine(Contains("<-- CONFLICT --- this will conflict"))
},
})