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

Fix bundle outdated crashing when both ref and branch specified for a git gem in Gemfile #6959

Merged
merged 3 commits into from
Sep 15, 2023

Conversation

pboling
Copy link
Contributor

@pboling pboling commented Sep 14, 2023

Fixes #6951 to honor ref > branch. This in turn fixes bundle outdated for Gemfiles with dependencies specifying both branch and ref.

Also:

  • Raises an error when ref or branch are specified with tag, as that's an ambiguous state.
  • Improves spec for GitProxy

What was the end-user or developer problem that led to this PR?

  1. When specifying both branch and ref on a git source, some bundler commands break (e.g. bundle outdated see bundle outdated uses incorrect git command when branch and ref specified #6951)
  2. If it were to work, branch had higher precedence than ref, which is incorrect.
  3. tag was in between branch and ref in precedence, which doesn't make any sense, and in fact, tag should never be specified with branch or ref, as it creates an ambiguous reference that has until now been arbitrarily decided by the code in bundler (should it be the tag, or the branch/ref?).
  4. Last commit is strictly RuboCop lint fixes, which, if undesired as unrelated, I'm happy to pop off of this PR to keep it focused.
  5. First commit just synchronizes the platforms for latest MacOS/Darwin across some lockfiles.

What is your fix for the problem, implemented in this PR?

This implementation raises an error, and I expect it can affect users who unwittingly specified ambiguous references in their Gemfile, but for whom bundle commands currently work. As such this might be considered a breaking change, but it is also definitely a bugfix. In many cases this would only affect users for whom the bundle / git commands are already broken, such as the case in #6951.

Make sure the following tasks are checked

@pboling pboling force-pushed the fix-git-proxy-for-branch-and-ref branch 2 times, most recently from 22d7f4c to dbc1ce6 Compare September 14, 2023 05:03
let(:revision) { nil }
let(:git_source) { nil }
let(:clone_result) { double(Process::Status, :success? => true) }
let(:base_clone_args) { ["clone", "--bare", "--no-hardlinks", "--quiet", "--no-tags", "--depth", "1", "--single-branch"] }
subject { described_class.new(path, uri, ref, revision, git_source) }
Copy link
Contributor Author

@pboling pboling Sep 14, 2023

Choose a reason for hiding this comment

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

Note that the signature for GitProxy.new is not followed here, sending 'HEAD' as ref instead of the actual expected 3rd argument of options as a Hash. This is the case for all tests in this file, clearly indicating that these tests did zero testing of any options. It was working only because of ducky handling:

>> opt = "HEAD"
=> "HEAD"
>> opt["tag"]
=> nil

@pboling pboling changed the title Fix git proxy for branch and ref Fix GitProxy for branch and ref Sep 14, 2023
@martinemde martinemde self-requested a review September 14, 2023 16:59
Copy link
Member

@martinemde martinemde left a comment

Choose a reason for hiding this comment

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

This is great. Thank you for this. I had made a quick pass at flipping the order, saw that not one single test failed, and decided I would have to come back to it. Thanks for taking the time to increase the test coverage and make more than zero tests cover this behavior, and for raising the error when the nonsensical is given.

bundler/lib/bundler/source/git/git_proxy.rb Outdated Show resolved Hide resolved
bundler/spec/bundler/source/git/git_proxy_spec.rb Outdated Show resolved Hide resolved
@martinemde
Copy link
Member

martinemde commented Sep 14, 2023

By the way, I'm fine with the multiple unrelated commits. We just won't squash this when we merge it so the commit messages can stay coupled to their changes even though they are not themselves related. It would also be fine to make separate PRs with each of them.

@martinemde martinemde self-requested a review September 14, 2023 17:21
@pboling pboling force-pushed the fix-git-proxy-for-branch-and-ref branch 2 times, most recently from 91213e3 to 0f47ea6 Compare September 14, 2023 20:24
- Specs for GitProxy were incorrect and insufficient
- Specs are now correct and less insufficient
@pboling pboling force-pushed the fix-git-proxy-for-branch-and-ref branch from 0f47ea6 to 2851e05 Compare September 14, 2023 20:27
@pboling
Copy link
Contributor Author

pboling commented Sep 14, 2023

Rebased on latest upstream/master

@martinemde martinemde merged commit c2c0966 into rubygems:master Sep 15, 2023
92 checks passed
@pboling pboling deleted the fix-git-proxy-for-branch-and-ref branch September 15, 2023 12:01
@deivid-rodriguez deivid-rodriguez changed the title Fix GitProxy for branch and ref Fix bundle outdatedcrashing when both ref and branch specified for a git gem in Gemfile Sep 21, 2023
@deivid-rodriguez deivid-rodriguez changed the title Fix bundle outdatedcrashing when both ref and branch specified for a git gem in Gemfile Fix bundle outdated crashing when both ref and branch specified for a git gem in Gemfile Sep 21, 2023
deivid-rodriguez pushed a commit that referenced this pull request Sep 21, 2023
deivid-rodriguez pushed a commit that referenced this pull request Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bundle outdated uses incorrect git command when branch and ref specified
4 participants