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 scan-remote-repo --branch logic #250

Merged
merged 4 commits into from
Nov 2, 2021
Merged

Conversation

rbailey-godaddy
Copy link
Contributor

To help us get this pull request reviewed and merged quickly, please be sure to include the following items:

  • Tests (if applicable)
  • Documentation (if applicable)
  • Changelog entry
  • A full explanation here in the PR description of the work done

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Tests
  • Other

Backward Compatibility

Is this change backward compatible with the most recently released version? Does it introduce changes which might change the user experience in any way? Does it alter the API in any way?

  • Yes (backward compatible)
  • No (breaking changes)

Issue Linking

fixes #247

What's new?

  • A fresh-cloned repository does not have branch information for remote branches. We must follow the information in remotes.origin.refs instead of branches (which will have only the main/master branch).
  • We add a new is_remote flag so the common code knows which strategy to employ.
  • A side-effect appears to be that because HEAD appears in the reference list, we'll scan the default branch twice, but I can live with this.

A fresh-cloned repository does not have branch information for remote
branches. We must follow the information in `remotes.origin.refs`
instead of `branches` (which will have only the main/master branch).

We add a new `is_remote` flag so the common code knows which strategy
to employ.

A side-effect appears to be that because HEAD appears in the reference
list, we'll scan the default branch twice, but I can live with this.
Copy link
Contributor

@tarkatronic tarkatronic left a comment

Choose a reason for hiding this comment

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

Just one question/point of curiosity, to be sure we're not being excessive in our scan.

Also, is this something we're going to need to port over to the v3.x branch?

)
else:
# Everything
branches = unfiltered_branches
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this truly only be branches, or might this possibly include refs to PRs, tags, etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might be excessive (I know in simple testing that HEAD showed up in the references list). However, I feel this is "harmlessly excessive":

  • If user specifies a branch, we are looking for a reference with the name of the branch, and therefore will scan only the branch the user asked us to scan
  • If the user didn't, we'll scan "everything" (which is what is intended). We might end up scanning parts of "everything" multiple times, to the extent multiple references appear -- in which case I hope most of this will be short-circuited by the "I've seen this diff before" lru cache and the impact will be minimized.

The fix for v3.x is much better than this one, so I'm willing to sacrifice some efficiency for correctness in the short term, knowing that when people transition to v3 it won't be a problem any longer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Subtle change: In testing, I noted that the fresh-cloned scratch repo had only a main (or presumably master) branch defined, so the old default scan-remote-repo (without a branch) actually was probably only scanning the master branch and not the entire repository -- so people might be surprised to discover things getting scanned now that weren't scanned (at least not since v2.0.2).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's likely there will be a number of surprises for users as they move to v3.0 and find how much more accurate it is. 😄

@tarkatronic
Copy link
Contributor

(Ignore that last part of my comment -- just saw the other PR!)

Copy link
Contributor

@smimani-godaddy smimani-godaddy left a comment

Choose a reason for hiding this comment

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

LGTM 🦅

Copy link
Contributor

@sushantmimani sushantmimani left a comment

Choose a reason for hiding this comment

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

LGTM 🦅

@rbailey-godaddy rbailey-godaddy merged commit 9f13229 into main Nov 2, 2021
@rbailey-godaddy rbailey-godaddy deleted the fix-remote-branch-v2 branch November 2, 2021 13:28
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.

Specifying branch with remote repository is broken
5 participants