Skip to content

[gh pr checkout] Add --no-tags option to git fetch commands in checko… - #10479

Merged
williammartin merged 2 commits into
cli:trunkfrom
latzskim:gh-pr-checkout-with-no-tags
Feb 21, 2025
Merged

[gh pr checkout] Add --no-tags option to git fetch commands in checko…#10479
williammartin merged 2 commits into
cli:trunkfrom
latzskim:gh-pr-checkout-with-no-tags

Conversation

@latzskim

Copy link
Copy Markdown
Contributor

Fixes #10254

Scenario:

Given I have a repository with Git tags
When I run gh pr checkout
Then the branch is fetched with --no-tags

How to test:

  1. Verify that there are no tags at all:
gqlc git:(main) GIT_TRACE=1 GIT_CURL_VERBOSE=1 git show-ref --tags -d
19:15:16.299293 git.c:455               trace: built-in: git show-ref --tags -d
  1. Create test tags:
    image

  2. Run gh pr checkout XXX and check if --no-tag appears in the fetch section.

 GH_DEBUG=1 gh pr checkout 1
[git remote -v]
[git config --get-regexp ^remote\..*\.gh-resolved$]
* Request at 2025-02-20 19:21:59.275807833 +0100 CET m=+0.073196802
* Request to https://api.github.com/graphql
* Request took 347.500805ms
[git remote -v]
[git config --get-regexp ^remote\..*\.gh-resolved$]
* Request at 2025-02-20 19:21:59.632861839 +0100 CET m=+0.430250808
* Request to https://api.github.com/graphql
* Request took 288.433004ms
* Request at 2025-02-20 19:21:59.921556543 +0100 CET m=+0.718945612
* Request to https://api.github.com/graphql
⣽* Request took 233.577603ms
[git remote -v]
[git config --get-regexp ^remote\..*\.gh-resolved$]
[git show-ref --verify -- refs/heads/testbranch]
[git -c credential.helper= -c credential.helper=!"/usr/bin/gh" auth git-credential fetch origin +refs/heads/testbranch:refs/remotes/origin/testbranch --no-tags]
[git checkout testbranch]
Switched to branch 'testbranch'
Your branch is up to date with 'origin/testbranch'.
[git merge --ff-only refs/remotes/origin/testbranch]
Already up to date.
  1. Ensure there are still no tags:
GIT_TRACE=1 GIT_CURL_VERBOSE=1 git show-ref --tags -d
19:23:01.201215 git.c:455               trace: built-in: git show-ref --tags -d
  1. Fetch tags to double-check: git fetch --tags.
From github.com:latzskim/gqlc
 * [new tag]         0.0.1-tag-main       -> 0.0.1-tag-main
 * [new tag]         0.0.1-tag-testbranch -> 0.0.1-tag-testbranch
 GIT_TRACE=1 GIT_CURL_VERBOSE=1 git show-ref --tags -d
19:26:22.878336 git.c:455               trace: built-in: git show-ref --tags -d
09547691e30013ec6626152e67ca736ba3ffd3af refs/tags/0.0.1-tag-main
237f2b896af7730953f95fcd87cf451f3b74a7b6 refs/tags/0.0.1-tag-testbranch

@latzskim
latzskim requested a review from a team as a code owner February 20, 2025 18:26
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Feb 20, 2025
@williammartin

williammartin commented Feb 21, 2025

Copy link
Copy Markdown
Member

Acceptance Criteria

Original A/C:

Given I have a repository with Git tags
When I run gh pr checkout
Then the branch is fetched with --no-tags

My slightly adjusted black-box A/C:

Given there are remote tags that have not been fetched to my local clone

➜  test-repo-copy git:(feature) git ls-remote --tags upstream
72a9798eef0819a1ec81600616bccc1b83d33407        refs/tags/foobar
➜  test-repo git:(feature) git tag | wc -l
       0

When I run gh pr checkout

➜  test-repo git:(feature) ~/workspace/cli/bin/gh pr checkout 10
remote: Enumerating objects: 1, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 1 (delta 0), reused 1 (delta 0), pack-reused 0 (from 0)
Unpacking objects: 100% (1/1), 172 bytes | 57.00 KiB/s, done.
From https://github.com/williammartin-test-org/test-repo
 * [new branch]      test-pr-checkout -> upstream/test-pr-checkout
branch 'test-pr-checkout' set up to track 'upstream/test-pr-checkout'.
Switched to a new branch 'test-pr-checkout'

Then the remote tags are not fetched

➜  test-repo git:(test-pr-checkout) git tag | wc -l
       0

Comparing to current release of gh:

➜  test-repo git:(test-pr-checkout) gh pr checkout 10
From https://github.com/williammartin-test-org/test-repo
 * [new tag]         foobar     -> foobar
 * [new tag]         v0.0.1     -> v0.0.1
Already on 'test-pr-checkout'
Your branch is up to date with 'upstream/test-pr-checkout'.
Already up to date.

➜  test-repo git:(test-pr-checkout) git tag
foobar
v0.0.1

@williammartin williammartin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I added a test for a branch that was uncovered, and just did a slight refactoring on the implementation there.

I did explore removing all --no-tags additions, looping over the commands (or using the loop inside executeCmds and appending --no-tags if the command was fetch. I did this because it seemed easy to make mistakes manually adding --no-tags to all fetch commands. However, I backed it out because I valued the clarity of each command being self-contained, and not being mutated later.

Thanks for the very clear A/C steps in your PR description. Very valuable.

@williammartin
williammartin merged commit 537a222 into cli:trunk Feb 21, 2025
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Mar 6, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cli/cli](https://github.com/cli/cli) | minor | `v2.67.0` -> `v2.68.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>cli/cli (cli/cli)</summary>

### [`v2.68.0`](https://github.com/cli/cli/releases/tag/v2.68.0): GitHub CLI 2.68.0

[Compare Source](cli/cli@v2.67.0...v2.68.0)

#### What's Changed

##### ✨ Features

-   \[gh repo view] Improve error message for forked repo by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10334
-   Add signer-digest, source-ref, and source-digest options for `gh attestation verify` by [@&#8203;malancas](https://github.com/malancas) in cli/cli#10308
-   \[gh pr checkout] Add --no-tags option to git fetch commands in checkout by [@&#8203;latzskim](https://github.com/latzskim) in cli/cli#10479
-   \[`gh issue/pr comment`] Add `--create-if-none` and prompts to create a comment if no comment already exists  by [@&#8203;latzskim](https://github.com/latzskim) in cli/cli#10427
-   \[gh cache delete --all] Add `--succeed-on-no-caches` flag to return exit code 0 by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10327
-   \[gh release create] Fail when there are no new commits since the last release by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10398
-   update default upstream when forking repo during MR creation by [@&#8203;daviddl9](https://github.com/daviddl9) in cli/cli#10458

##### 🐛 Fixes

-   Refactor `GetLocalAttestations` and clean up custom registry transport by [@&#8203;malancas](https://github.com/malancas) in cli/cli#10382
-   Check `GH_REPO` too in addition to `--repo` for disambiguation by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10539
    -   (Fixes `gh secret` subcommands not working outside of a repository)
-   Fix unhandled panic in FindWorkflow and add tests by [@&#8203;jtmcg](https://github.com/jtmcg) in cli/cli#10521
-   Fix checkout when URL arg is from fork and cwd is upstream by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10512
-   \[gh api] Escape package name (URL encoding) for packages endpoint by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10384
-   Fix `remoteResolver` caching issue by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10456
-   Fix gh project item-edit to allow --number 0 as a valid value by [@&#8203;aryanbhosale](https://github.com/aryanbhosale) in cli/cli#10417
-   Add mutex to fix race in attestation test client by [@&#8203;codysoyland](https://github.com/codysoyland) in cli/cli#10439
-   Base64 decode GPG passphrase in deployment workflow by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10546

##### 📚 Docs & Chores

-   Deep Dive Document Release Process by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10503
-   Inconsistent format of examples in help text by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10508
-   Inconsistent format of description of flags (starting with lowercase letter) by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10507
-   Update Go version to 1.23 in CONTRIBUTING.md by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10504
-   Fix minor auth login help typo by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10501
-   docs: document how to revoke `gh` OAuth tokens in `auth logout`'s help by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10490
-   chore: update codespaces Go version by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10491
-   Allow injection of TUFMetadataDir in tests by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10478
-   refactor: use a more straightforward return value by [@&#8203;beforetech](https://github.com/beforetech) in cli/cli#10489
-   Use subtests in attestation verification integration tests by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#10463
-   Fix typo in README by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10445
-   Update usage to lower-kebab-case by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10447
-   Standardize URLs by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10429
-   Remove trailing whitespace by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10430

##### :dependabot: Dependencies

-   Bump actions/attest-build-provenance from 2.2.0 to 2.2.2 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10518
-   Bump github.com/go-jose/go-jose/v4 from 4.0.2 to 4.0.5 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10499
-   Bump github.com/spf13/pflag from 1.0.5 to 1.0.6 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10338

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

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh pr checkout defies negative refspec in remote.*.<name>

3 participants