Skip to content

Avoid an infinite loop when git commands fail to execute when Changesets try to retrieve commits that added files - #584

Merged
Andarist merged 6 commits into
mainfrom
fix/infinite-loop-git
Jun 26, 2026
Merged

Avoid an infinite loop when git commands fail to execute when Changesets try to retrieve commits that added files#584
Andarist merged 6 commits into
mainfrom
fix/infinite-loop-git

Conversation

@Andarist

@Andarist Andarist commented May 2, 2021

Copy link
Copy Markdown
Member

This addresses the direct problem in #571 . We need to investigate the issue more to address the core of the problem though.

fix #571

…ets try to retrieve commits that added files
@Andarist
Andarist requested a review from emmatown May 2, 2021 09:20
@changeset-bot

changeset-bot Bot commented May 2, 2021

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8ac0acd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@changesets/git Patch
@changesets/cli Patch
@changesets/apply-release-plan Patch
@changesets/read Patch
@changesets/release-utils Patch
@changesets/get-release-plan Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Andarist

Andarist commented May 2, 2021

Copy link
Copy Markdown
Member Author

I will address the failing tests later - I don't think this should block the potential PR approval though (unless you think otherwise).

@emmatown emmatown 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.

Could you add the command that was run to the error that is thrown?

@emmatown

emmatown commented May 2, 2021

Copy link
Copy Markdown
Member

I will address the failing tests later - I don't think this should block the potential PR approval though (unless you think otherwise).

We've explicitly intended to support running Changesets without git and the tests failing seem like they would break that?

@Andarist

Andarist commented May 2, 2021

Copy link
Copy Markdown
Member Author

Could you add the command that was run to the error that is thrown?

Sure thing.

We've explicitly intended to support running Changesets without git and the tests failing seem like they would break that?

That's interesting - because the original report was stating that the infinite loop has been caused by the lack of git in the container but that would mean that our tests would not be able to complete before this change here. So there has to be some additional thing about the setup of the reporter.

Gonna try to investigate this later.

@kenrick95

Copy link
Copy Markdown

Hi @Andarist, are there any blockers on this PR? Seems like would be helpful to solve #571

@yonran

yonran commented Jun 18, 2025

Copy link
Copy Markdown

Could you add the command that was run to the error that is thrown?

I ran into this infinite loop with no error printed in a GitHub Workflow when I ran changeset version in a shallow checkout without git credentials:

on:
    workflow_dispatch:
jobs:
    release:
        name: Create Release
        runs-on: ubuntu-latest
        permissions:
            contents: write
            packages: write
        steps:
            - uses: actions/checkout@v4
              with:
                  # don’t save GITHUB_TOKEN to .git/config; use credential helper instead
                  # because we don't want postinstall scripts
                  # to have access to write credentials
                  persist-credentials: false
            - name: Install node
              uses: actions/setup-node@v4
            - name: configure git to use $GIT_PASSWORD for github credential
              shell: bash
              run: |
                  set -eux
                  git config --global credential.https://github.com.helper '!f(){ test "$1" = get && printf "username=x-access-token\npassword=%s\n" "$GIT_PASSWORD"; }; f'
            - run: npm ci --ignore-scripts
            # - run: npm reinstall dependencies with postinstall scripts
            - run: npx changeset version
              env:
                # I didn’t realize that I need this:
                # GIT_PASSWORD: ${{ github.token }}

Steps to reproduce locally:

First, do a shallow clone

git clone --depth=1 --branch=<branch> https://github.com/<org>/<repo>.git

Then, remove github credentials

  • e.g. if using git-credential-osxkeychain, then in Keychain Access, for the github.com Internet Password, remove git-credential-osxkeychain from authorized programs in Access Control
  • e.g. if using gh auth authorize-git, remove the [credential "https://gist.github.com "] helper = "!gh auth git-credential" from ~/.gitconfig or ~/.config/git/config/

Then run changeset version

npm ci --ignore-scripts
npx changeset version

@codecov

codecov Bot commented Nov 18, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.49%. Comparing base (dae394c) to head (8ac0acd).

Files with missing lines Patch % Lines
packages/git/src/index.ts 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #584      +/-   ##
==========================================
- Coverage   85.51%   85.49%   -0.03%     
==========================================
  Files          70       70              
  Lines        2548     2550       +2     
  Branches      686      688       +2     
==========================================
+ Hits         2179     2180       +1     
- Misses        338      339       +1     
  Partials       31       31              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bluwy

bluwy commented Nov 18, 2025

Copy link
Copy Markdown
Member

We need to investigate the issue more to address the core of the problem though.

I believe #1045 may be the solution to the core problem

@bluwy bluwy 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 went ahead and revert some non-0 handling since it's impossible for them to return non-0. @Andarist can you check the code again?

Honestly, not really happy with the git functions, some doesn't error and returns a boolean, some throws an error, some does a console.log. Argument format is also a bit sporadic. But I don't really want to change those for now.

@Andarist
Andarist added this pull request to the merge queue Jun 26, 2026
@Andarist

Copy link
Copy Markdown
Member Author

I agree this package isn't particularly consistent - it woul be nice to clean it up some time later.

Merged via the queue into main with commit 6c79210 Jun 26, 2026
10 of 12 checks passed
@Andarist
Andarist deleted the fix/infinite-loop-git branch June 26, 2026 06:46
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.

Infinite loop makes changeset version command hang

6 participants