Skip to content

Infer branch for NDDB more consistently - #9328

Merged
outofambit merged 5 commits into
fix-prompt-for-update-branch-2from
fix-prompt-for-update-branch-3
Mar 25, 2020
Merged

outofambit merged 5 commits into
fix-prompt-for-update-branch-2from
fix-prompt-for-update-branch-3

Conversation

@rafeca

@rafeca rafeca commented Mar 20, 2020 •

Copy link
Copy Markdown
Contributor

Partially addresses #5293

This branch is based on #9320

Description

This PR changes the logic to infer the branch used for the NDDB to follow the rules that the code comments suggest:

The branch returned is determined by the following conditions:

  1. Given a pull request -> target branch of PR
  2. Given a forked repository -> default branch on upstream
  3. Given a hosted repository -> default branch on origin
  4. Fallback -> master branch

Before, there was some logic to default to branch on origin if the current branch was behind it, but this logic didn't work correctly all the time and it caused this inconsistencies. With this PR the logic is now deterministic and a little bit simpler.

Screenshots

Before:

before

With this fix, the inferred branch stays as upstream/master no matter which actions the user takes.

Release notes

Notes: no-notes

@rafeca
rafeca requested a review from outofambit March 20, 2020 19:28
Comment thread app/src/lib/stores/app-store.ts Outdated
Comment on lines +1052 to +1053
if (aheadBehindOfInferredBranch === null) {
aheadBehindOfInferredBranch = await aheadBehindUpdater.executeAsyncTask(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This logic may change slightly once I address the comment in #9319 (comment)

expect(branch!.upstream).toBe(branches[5].upstream)
})

it('Returns the default branch of the fork if it is ahead of the current branch', async () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This test is not relevant anymore, since now the origin branch is never returned for a fork

Comment on lines -98 to -101
const aheadBehind = comparisonCache.get(
currentBranch.tip.sha,
defaultBranch.tip.sha
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This read from the cache was causing the inconsistencies: the cache is not always populated and that caused differences on the inferred branch depending on the actions that the user had taken before.

@tierninho

Copy link
Copy Markdown
Contributor

Based on your changes, I should expect these scenarios to work or did I miss something?

  • Given a pull request -> target branch of PR
  • Given a forked repository -> default branch on upstream
  • Given a hosted repository -> default branch on origin
  • Fallback -> master branch

@rafeca

rafeca commented Mar 23, 2020

Copy link
Copy Markdown
Contributor Author

Based on your changes, I should expect these scenarios to work or did I miss something?

Exactly! that's the expected behaviour

@outofambit outofambit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this looks great! one question about a conditional we might be able to remove. 🎉

Comment thread app/src/lib/stores/app-store.ts Resolved
Comment thread app/src/lib/stores/app-store.ts Resolved
@outofambit outofambit self-assigned this Mar 24, 2020
@rafeca rafeca linked an issue Mar 25, 2020 that may be closed by this pull request
@outofambit
outofambit merged commit 89fc36d into fix-prompt-for-update-branch-2 Mar 25, 2020
@outofambit
outofambit deleted the fix-prompt-for-update-branch-3 branch March 25, 2020 19:33
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.

3 participants