Skip to content

Fix "stale info" error for git push #7

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

Merged
merged 1 commit into from
May 16, 2025
Merged

Conversation

ArchieMeng
Copy link
Contributor

@ArchieMeng ArchieMeng commented May 13, 2025

Fetch new remote before push

Summary by Sourcery

Bug Fixes:

  • Fetch the current branch from origin before pushing to avoid stale information errors

Fetch new remote before push
Copy link

sourcery-ai bot commented May 13, 2025

Reviewer's Guide

Updates the push workflow to authenticate the remote URL, fetch the latest branch state from origin, and then push with force-with-lease to avoid stale information errors.

File-Level Changes

Change Details Files
Introduce authenticated remote URL setup and pre-push fetch
  • Use 'git remote set-url origin' with GITHUB_TOKEN for authentication
  • Fetch the current branch from origin before attempting the push
  • Push to the named 'origin' remote with force-with-lease instead of inline URL
action.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ArchieMeng
Copy link
Contributor Author

ArchieMeng commented May 13, 2025

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ArchieMeng - I've reviewed your changes - here's some feedback:

  • Consider capturing the current branch name in a variable to avoid repeating git branch --show-current and improve readability.
  • Instead of permanently setting the remote URL, you could pass the token-embedded URL directly to git push (or restore the original URL afterward) to avoid side effects.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟡 Security: 1 issue found
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@imba-tjd
Copy link
Owner

imba-tjd commented May 14, 2025

Hello, I wrote those code 4 years ago so maybe I don't fully remember them. 😂

As I understand the existing code. It does the rebase regardless upstream changes. Then compare local with "remote origin". If it showed "diverged" text, then push is needed.

I don't understand how (stale info) appears. Would you mind elaborating?

I think, if there are commits into fork between checkout, rebase and push, it's correct to refuse to push, if that's the cause of the stale error.

@ArchieMeng
Copy link
Contributor Author

No, the reason is that:

git push "${ORIGIN_URL/https:\/\//https:\/\/$GITHUB_TOKEN@}" $(git branch --show-current) --force-with-lease;

This line didn't add the url as a remote, and thus in a not fetched status. Which results in making Git thinking that the status of this remote is not clean, might have some commits not fetched, and rejects the push. The push url should be added as a remote and do fetch at least once before push.

You can also check this stackoverflow answer.https://stackoverflow.com/questions/56191415/why-is-git-push-force-with-lease-failing-with-rejected-stale-info-even

@imba-tjd
Copy link
Owner

imba-tjd commented May 14, 2025

How about doing git fetch in the first place, right after the checkout?

And will the fetch unshadow commit history? (I guess not, because there is an --unshadow option)

@ArchieMeng
Copy link
Contributor Author

Is there any suggested changes? You can directly edit on my PR to give a suggested change.
And I think the current git fetch position is good because if there is no need to commit, then this action doesn't need to do git fetch which is basically for git push.

@imba-tjd imba-tjd merged commit 559f427 into imba-tjd:master May 16, 2025
@imba-tjd
Copy link
Owner

OK, thank you!

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.

2 participants