Skip to content

feat: add --pr shortcut flag for checking PR-changed files#660

Merged
jdx merged 3 commits intomainfrom
feat/pr-flag
Feb 2, 2026
Merged

feat: add --pr shortcut flag for checking PR-changed files#660
jdx merged 3 commits intomainfrom
feat/pr-flag

Conversation

@jdx
Copy link
Copy Markdown
Owner

@jdx jdx commented Feb 2, 2026

Summary

  • Adds a --pr flag to check/fix commands as a shortcut for --from-ref <default-branch> --to-ref HEAD
  • Checks only files changed relative to the default branch — the typical PR diff
  • Conflicts with --files, --all, --from-ref, and --to-ref to prevent ambiguous usage

Test plan

  • cargo build compiles
  • cargo test passes (134 tests, including sorted-flags check)
  • hk check --pr checks only files differing from the default branch
  • hk check --pr --all errors with conflicting flags
  • hk check --pr --from-ref main errors with conflicting flags

🤖 Generated with Claude Code


Note

Medium Risk
Moderate risk: changes CLI flag interactions and mutates from_ref/to_ref at runtime based on detected default branch, which could affect which files are selected for hooks in edge-case repos.

Overview
Adds a new --pr option to hook commands that scopes execution to files changed relative to the repo’s default branch by automatically setting from_ref to the configured/detected default branch and to_ref to HEAD.

Enforces mutual exclusivity with other file-selection flags (e.g., --all, --files, --glob, --from-ref, --to-ref) and adds Bats coverage validating both the selection behavior and conflict errors.

Written by Cursor Bugbot for commit bd5911c. This will update automatically on new commits. Configure here.

Adds a --pr flag to check/fix commands that serves as a shortcut for
--from-ref <default-branch> --to-ref HEAD, checking only files changed
relative to the default branch.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @jdx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the command-line interface by adding a convenient --pr flag. This flag streamlines the workflow for developers by automatically configuring the comparison range to include only files changed relative to the default branch, which is typical for pull request reviews. It aims to improve usability by providing a simpler way to target relevant files for checks or fixes, while also preventing conflicts with other file selection options.

Highlights

  • New --pr flag: Introduced a new --pr command-line flag as a shortcut for --from-ref <default-branch> --to-ref HEAD, simplifying the process of checking or fixing files changed in the current pull request or branch.
  • Conflict handling: The --pr flag is designed to conflict with other file selection flags such as --files, --all, --from-ref, and --to-ref to prevent ambiguous usage and ensure clarity in file targeting.
  • Dynamic default branch resolution: When the --pr flag is used, the system dynamically resolves the repository's default branch to set the from_ref argument, ensuring comparisons are always made against the correct base.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a convenient --pr flag as a shortcut for checking files changed in a pull request. The implementation is solid, but I've identified a minor inefficiency where the application configuration is loaded twice. I've provided a suggestion to load the configuration only once to improve performance and code clarity. Overall, a great addition!

Comment thread src/hook_options.rs Outdated
Comment on lines 77 to 82
if self.pr {
let repo = Git::new()?;
self.from_ref = Some(repo.resolve_default_branch());
self.to_ref = Some("HEAD".to_string());
}
let config = Config::get()?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This implementation calls Config::get() inside repo.resolve_default_branch() and then again on line 82. This is inefficient as it can cause the configuration to be loaded and processed twice.

It's better to load the config once at the beginning of the function and then use the loaded config object to determine the default branch. This improves performance and makes the logic clearer by removing the hidden dependency on Config within resolve_default_branch.

This change also slightly alters behavior for the better: if Config::get() fails, the function will now fail immediately, which is cleaner than continuing to calculate from_ref only to fail on the next line.

        let config = Config::get()?;
        if self.pr {
            let repo = Git::new()?;
            let from_ref = config.default_branch.as_deref()
                .filter(|s| !s.trim().is_empty())
                .map(str::to_string)
                .unwrap_or_else(|| repo.default_branch().unwrap_or_else(|_| "main".to_string()));
            self.from_ref = Some(from_ref);
            self.to_ref = Some("HEAD".to_string());
        }

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Comment thread src/hook_options.rs Outdated
- Add --glob to conflicts list to prevent silent ignore of --pr
- Load Config once and inline default branch resolution to avoid
  redundant Config::get() call

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jdx jdx enabled auto-merge (squash) February 2, 2026 13:13
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is ON, but a Cloud Agent failed to start.

Comment thread src/hook_options.rs
.as_deref()
.filter(|s| !s.trim().is_empty())
.map(str::to_string)
.unwrap_or_else(|| repo.default_branch().unwrap_or_else(|_| "main".to_string()));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Duplicates existing resolve_default_branch method logic

Medium Severity

The logic for determining the default branch duplicates the existing Git::resolve_default_branch() method in src/git.rs (lines 287-294). Replace this block with let default_branch = repo.resolve_default_branch(); to reuse the existing functionality.

Fix in Cursor Fix in Web

@jdx jdx merged commit 9169b56 into main Feb 2, 2026
20 checks passed
@jdx jdx deleted the feat/pr-flag branch February 2, 2026 13:20
@jdx jdx mentioned this pull request Feb 2, 2026
jdx added a commit that referenced this pull request Feb 9, 2026
### 🚀 Features

- **(cmake_format)** init by [@matdibu](https://github.com/matdibu) in
[#672](#672)
- **(deadnix)** init by [@matdibu](https://github.com/matdibu) in
[#670](#670)
- **(hclfmt)** init by [@matdibu](https://github.com/matdibu) in
[#675](#675)
- **(nil)** init by [@matdibu](https://github.com/matdibu) in
[#669](#669)
- **(nixf_diagnose)** init by [@matdibu](https://github.com/matdibu) in
[#671](#671)
- **(ruff_format)** use `--quiet` by
[@matdibu](https://github.com/matdibu) in
[#667](#667)
- **(tombi)** use `--quiet` by [@matdibu](https://github.com/matdibu) in
[#676](#676)
- add ty builtin by [@joonas](https://github.com/joonas) in
[#566](#566)
- add --pr shortcut flag for checking PR-changed files by
[@jdx](https://github.com/jdx) in
[#660](#660)
- add tmpdir step test option by
[@thejcannon](https://github.com/thejcannon) in
[#663](#663)

### 🐛 Bug Fixes

- **(bultins)** respect typos exclusions with --force-exclude by
[@CallumKerson](https://github.com/CallumKerson) in
[#659](#659)
- **(docs)** escape angle brackets in --pr flag description by
[@jdx](https://github.com/jdx) in
[#666](#666)
- **(docs)** use valid <br> tags instead of </br> in sea shanty by
[@jdx](https://github.com/jdx) in
[12e17f8](12e17f8)
- **(go_fumpt)** comment out broken check by
[@matdibu](https://github.com/matdibu) in
[#668](#668)
- **(yamllint)** enable strict mode by
[@matdibu](https://github.com/matdibu) in
[#673](#673)
- respect ignore when recursing by
[@thejcannon](https://github.com/thejcannon) in
[#661](#661)
- Deduplicate files in check-case-conflict to prevent false positives by
[@safinn](https://github.com/safinn) in
[#678](#678)
- Fix building of nix flake wiwth the inclusion of git subomdules by
[@jeffutter](https://github.com/jeffutter) in
[#681](#681)

### 🛡️ Security

- add tone calibration to release notes prompt by
[@jdx](https://github.com/jdx) in
[#679](#679)
- add opengraph meta tags by [@jdx](https://github.com/jdx) in
[#685](#685)

### 📦️ Dependency Updates

- lock file maintenance by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#658](#658)
- update anthropics/claude-code-action digest to b113f49 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#684](#684)
- update actions/checkout digest to de0fac2 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#683](#683)

### New Contributors

- @jeffutter made their first contribution in
[#681](#681)
- @matdibu made their first contribution in
[#673](#673)
- @safinn made their first contribution in
[#678](#678)
- @CallumKerson made their first contribution in
[#659](#659)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Mostly release bookkeeping, but the `Cargo.lock` refresh pulls in
multiple dependency version changes that could affect build/runtime
behavior.
> 
> **Overview**
> Updates the project release to **v1.36.0** by bumping version strings
across `Cargo.toml`, `hk.usage.kdl`, generated CLI docs/metadata, and
example PKL configuration URLs.
> 
> Adds the `1.36.0` section to `CHANGELOG.md` and refreshes generated
CLI documentation to include the `--pr` shortcut flag description for
`check`/`fix`/`run`.
> 
> Refreshes `Cargo.lock` with dependency updates (including several
transitive additions/removals) and updates the Pkl error hint in
`src/config.rs` to reference the new release URL.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
7925e85. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: mise-en-dev <123107610+mise-en-dev@users.noreply.github.com>
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Feb 9, 2026
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [hk](https://github.com/jdx/hk) | minor | `1.35.0` → `1.36.0` |

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>jdx/hk (hk)</summary>

### [`v1.36.0`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1360---2026-02-09)

[Compare Source](jdx/hk@v1.35.0...v1.36.0)

##### 🚀 Features

- **(cmake\_format)** init by [@&#8203;matdibu](https://github.com/matdibu) in [#&#8203;672](jdx/hk#672)
- **(deadnix)** init by [@&#8203;matdibu](https://github.com/matdibu) in [#&#8203;670](jdx/hk#670)
- **(hclfmt)** init by [@&#8203;matdibu](https://github.com/matdibu) in [#&#8203;675](jdx/hk#675)
- **(nil)** init by [@&#8203;matdibu](https://github.com/matdibu) in [#&#8203;669](jdx/hk#669)
- **(nixf\_diagnose)** init by [@&#8203;matdibu](https://github.com/matdibu) in [#&#8203;671](jdx/hk#671)
- **(ruff\_format)** use `--quiet` by [@&#8203;matdibu](https://github.com/matdibu) in [#&#8203;667](jdx/hk#667)
- **(tombi)** use `--quiet` by [@&#8203;matdibu](https://github.com/matdibu) in [#&#8203;676](jdx/hk#676)
- add ty builtin by [@&#8203;joonas](https://github.com/joonas) in [#&#8203;566](jdx/hk#566)
- add --pr shortcut flag for checking MR-changed files by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;660](jdx/hk#660)
- add tmpdir step test option by [@&#8203;thejcannon](https://github.com/thejcannon) in [#&#8203;663](jdx/hk#663)

##### 🐛 Bug Fixes

- **(bultins)** respect typos exclusions with --force-exclude by [@&#8203;CallumKerson](https://github.com/CallumKerson) in [#&#8203;659](jdx/hk#659)
- **(docs)** escape angle brackets in --pr flag description by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;666](jdx/hk#666)
- **(docs)** use valid <br> tags instead of </br> in sea shanty by [@&#8203;jdx](https://github.com/jdx) in [12e17f8](jdx/hk@12e17f8)
- **(go\_fumpt)** comment out broken check by [@&#8203;matdibu](https://github.com/matdibu) in [#&#8203;668](jdx/hk#668)
- **(yamllint)** enable strict mode by [@&#8203;matdibu](https://github.com/matdibu) in [#&#8203;673](jdx/hk#673)
- respect ignore when recursing by [@&#8203;thejcannon](https://github.com/thejcannon) in [#&#8203;661](jdx/hk#661)
- Deduplicate files in check-case-conflict to prevent false positives by [@&#8203;safinn](https://github.com/safinn) in [#&#8203;678](jdx/hk#678)
- Fix building of nix flake wiwth the inclusion of git subomdules by [@&#8203;jeffutter](https://github.com/jeffutter) in [#&#8203;681](jdx/hk#681)

##### 🛡️ Security

- add tone calibration to release notes prompt by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;679](jdx/hk#679)
- add opengraph meta tags by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;685](jdx/hk#685)

##### 🔍 Other Changes

- Use tmpdir for the tests by [@&#8203;thejcannon](https://github.com/thejcannon) in [#&#8203;677](jdx/hk#677)

##### 📦️ Dependency Updates

- lock file maintenance by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;658](jdx/hk#658)
- update anthropics/claude-code-action digest to [`b113f49`](jdx/hk@b113f49) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;684](jdx/hk#684)
- update actions/checkout digest to [`de0fac2`](jdx/hk@de0fac2) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;683](jdx/hk#683)

##### New Contributors

- [@&#8203;jeffutter](https://github.com/jeffutter) made their first contribution in [#&#8203;681](jdx/hk#681)
- [@&#8203;matdibu](https://github.com/matdibu) made their first contribution in [#&#8203;673](jdx/hk#673)
- [@&#8203;safinn](https://github.com/safinn) made their first contribution in [#&#8203;678](jdx/hk#678)
- [@&#8203;CallumKerson](https://github.com/CallumKerson) made their first contribution in [#&#8203;659](jdx/hk#659)

</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:eyJjcmVhdGVkSW5WZXIiOiI0Mi45Ni4wIiwidXBkYXRlZEluVmVyIjoiNDIuOTYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90IiwiYXV0b21hdGlvbjpib3QtYXV0aG9yZWQiLCJkZXBlbmRlbmN5LXR5cGU6Om1pbm9yIl19-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant