Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose {{.SelectedCommitRange}} to custom commands #4204

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

stefanhaller
Copy link
Collaborator

@stefanhaller stefanhaller commented Jan 23, 2025

  • PR Description

Expose {{.SelectedCommitRange}} to custom commands. It has fields .To and .From (the hashes of the last and the first selected commits, respectively), and it is useful for creating git commands that act on a range of commits.

Fixes #4184.

  • Please check if the PR fulfills these requirements
  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

Copy link

codacy-production bot commented Jan 23, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for d7683271 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (d768327) Report Missing Report Missing Report Missing
Head commit (4baf008) 52075 45027 86.47%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#4204) 44 44 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

@@ -314,6 +315,11 @@ CheckedOutBranch

To see what fields are available on e.g. the `SelectedFile`, see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/gui/services/custom_commands/models.go) (all the modelling lives in the same file).

We don't support accessing all elements of a range selection yet; the properties above only give you the moving end of the range. We might add this in the future, but as a special case you can access the range of selected commits by using `SelectedCommitRange`, which has two properties `.To` and `.From` which are the hashes of the bottom and top selected commits, respectively. This is useful for passing them to a git command that operates on a range of commits. For example, to create patches for all selected commits, you might use
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part:

; the properties above only give you the moving end of the range

Confused me for a bit because I didn't know what it meant. I don't think this part is necessary: it's sufficient to just say we don't support range selection.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it would be good to explain what happens if you access the single-element properties while there's a range selection, since I don't find this entirely obvious. And "moving end of the range" is the only way I could come up with to describe this.

But apparently it didn't work, so I'm happy to take this out if it's more confusing than helpful (9e57418).

Feel free to push a fixup if you want to improve the text further, I'll leave the PR open for a day or two more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it would be good to explain what happens if you access the single-element properties while there's a range selection, since I don't find this entirely obvious. And "moving end of the range" is the only way I could come up with to describe this.

I think that's an edge case we don't need to worry about.

Code LGTM so feel free to merge

Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending one thing, nice work

It has fields .To and .From (the hashes of the last and the first selected
commits, respectively), and it is useful for creating git commands that act on a
range of commits.
@stefanhaller stefanhaller force-pushed the expose-commit-range-to-custom-commands branch from 9e57418 to 4baf008 Compare January 27, 2025 08:00
@stefanhaller stefanhaller merged commit 5523680 into master Jan 27, 2025
15 checks passed
@stefanhaller stefanhaller deleted the expose-commit-range-to-custom-commands branch January 27, 2025 08:03
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Feb 25, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [jesseduffield/lazygit](https://github.com/jesseduffield/lazygit) | minor | `v0.45.2` -> `v0.47.1` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jesseduffield/lazygit (jesseduffield/lazygit)</summary>

### [`v0.47.1`](https://github.com/jesseduffield/lazygit/releases/tag/v0.47.1)

[Compare Source](jesseduffield/lazygit@v0.46.0...v0.47.1)

<!-- Release notes generated using configuration in .github/release.yml at v0.47.1 -->

#### What's Changed

##### Maintenance ⚙️

-   Fix race condition with reselecting the focused branch and rendering by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4268

**Full Changelog**: jesseduffield/lazygit@v0.47.0...v0.47.1

### [`v0.46.0`](https://github.com/jesseduffield/lazygit/releases/tag/v0.46.0)

[Compare Source](jesseduffield/lazygit@v0.45.2...v0.46.0)

It's time for another Lazygit release! Thanks to all who contributed to this release.

#### What's Changed

##### Enhancements 🔥

-   Preserve pending commit message when closing/re-opening by [@&#8203;AzraelSec](https://github.com/AzraelSec) in jesseduffield/lazygit#4191
-   Swap position of checkout-commit and checkout-branch menu items by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4238
    -   In a previous release we had made it so that when you press space on a commit, the first option in the menu was to check out the corresponding branch, rather than the commit itself. We've made it so that now the first option is to check out the commit itself, for the sake of everybody's muscle memory.
-   Allow user to filter the files view to only show untracked files by [@&#8203;jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4226
-   Expose {{.SelectedCommitRange}} to custom commands by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4204
-   Show background fetch status in bottom line by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4215
-   Support copying tags to clipboard by [@&#8203;brunofjesus](https://github.com/brunofjesus) in jesseduffield/lazygit#4218
-   Add option to delete local and remote tag by [@&#8203;AnvarU](https://github.com/AnvarU) in jesseduffield/lazygit#4217
-   Show confirmation menu when trying to amend changes while there are conflicts by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4222
-   Improve error reporting on config migration by [@&#8203;kas2020-commits](https://github.com/kas2020-commits) in jesseduffield/lazygit#4210
-   Show files filter status by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4230
-   Improve contrast of highlighted search results by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4242

##### Fixes 🔧

-   Don't try killing processes if we already know the command finished by [@&#8203;brandondong](https://github.com/brandondong) in jesseduffield/lazygit#4231
    -   We believe this was causing all sorts of problems for windows users.
-   Add '--' to 'git rev-list' to disambiguate branch name from path by [@&#8203;efussi](https://github.com/efussi) in jesseduffield/lazygit#4185
-   Fix adding blank line at end of commit message by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4182
-   Fix checking out a different branch while pushing a branch for the first time by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4214
-   Fix tag being truncated when copying to clipboard by [@&#8203;brunofjesus](https://github.com/brunofjesus) in jesseduffield/lazygit#4232
-   Disable staging and unstaging lines or hunks when the diff context size is 0 by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4235
-   Fix incorrect stash diff after rename by [@&#8203;brandondong](https://github.com/brandondong) in jesseduffield/lazygit#4213
-   Fix possible crash when deleting a branch while filtering is active by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4195
-   Fix pasting multi-line text into commit message panel by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4234
-   fix: properly detect icon for BAZEL and WORKSPACE files by [@&#8203;PeterCardenas](https://github.com/PeterCardenas) in jesseduffield/lazygit#4252
-   Fix json schema for context of CustomCommand by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4255

##### Maintenance ⚙️

-   Bump go-deadlock version to fix crash with go 1.23 in debug mode by [@&#8203;ChrisMcD1](https://github.com/ChrisMcD1) in jesseduffield/lazygit#4248
-   Fix auto-release workflow by [@&#8203;jesseduffield](https://github.com/jesseduffield) in jesseduffield/lazygit#4265

##### I18n 🌎

-   Update translations; includes a new Portuguese translation by [@&#8203;stefanhaller](https://github.com/stefanhaller) in jesseduffield/lazygit#4250

#### New Contributors

-   [@&#8203;efussi](https://github.com/efussi) made their first contribution in jesseduffield/lazygit#4185
-   [@&#8203;brunofjesus](https://github.com/brunofjesus) made their first contribution in jesseduffield/lazygit#4218
-   [@&#8203;AnvarU](https://github.com/AnvarU) made their first contribution in jesseduffield/lazygit#4217
-   [@&#8203;kas2020-commits](https://github.com/kas2020-commits) made their first contribution in jesseduffield/lazygit#4210
-   [@&#8203;ChrisMcD1](https://github.com/ChrisMcD1) made their first contribution in jesseduffield/lazygit#4248
-   [@&#8203;PeterCardenas](https://github.com/PeterCardenas) made their first contribution in jesseduffield/lazygit#4252

**Full Changelog**: jesseduffield/lazygit@v0.45.2...v0.46.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xNzAuMSIsInVwZGF0ZWRJblZlciI6IjM5LjE3Ni40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose selected commit ranges to custom commands
2 participants