Skip to content

put history view into the correct state after a successful pull - #3541

Merged
iAmWillShepherd merged 9 commits into
masterfrom
history-out-of-sync
Dec 12, 2017
Merged

iAmWillShepherd merged 9 commits into
masterfrom
history-out-of-sync

Conversation

@shiftkey

@shiftkey shiftkey commented Dec 8, 2017 •

Copy link
Copy Markdown
Member

Fixes #2737

The problem manifests itself in a couple of ways:

  • you have some existing history to look at
  • you perform a pull which merges in some remote commits

Because of how loadHistory merges new commits with the current history, you can find yourself in a situation where remote commits (which occurred before the tip of the current history) are not loaded into this array of commits.

let existingHistory = this._history
if (existingHistory.length > 0) {
const mostRecent = existingHistory[0]
const index = commits.findIndex(c => c.sha === mostRecent)
// If we found the old HEAD, then we can just splice the new commits into
// the history we already loaded.
//
// But if we didn't, it means the history we had and the history we just
// loaded have diverged significantly or in some non-trivial way
// (e.g., HEAD reset). So just throw it out and we'll start over fresh.
if (index > -1) {
commits = commits.slice(0, index)
} else {
existingHistory = []
}
}

The quick fix for this is to nuke the history and let it reload, but results in a flicker when you are viewing the list. This is also probably bad for scenarios where you've scrolled down the history.

The better fix for this is to reconcile the two histories manually. Given the remote ref and local branch should share a common ancestor, we should be able to invalidate a subset of the commits currently loaded:

$ git merge-base master origin/master
b7641d1de6ca0b05b0279266df9120f6a945bf52

This also means that an existing selected commit is remembered, even after moving the history around.

@shiftkey shiftkey added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Dec 8, 2017

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

We will be moving away from relying on JS truthiness in conditional statements - #3538


if (state.branchesState.tip.kind === TipState.Unborn) {
if (tip.kind === TipState.Unborn) {
throw new Error('The current branch is unborn.')

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

* after a pull has completed, to include merged remote commits.
*/
public async reconcileHistory(mergeBase: string): Promise<void> {
if (this._history.length === 0) {

This comment was marked as spam.

Comment thread app/src/lib/stores/git-store.ts Outdated
const commits = await this.performFailableOperation(() =>
getCommits(this.repository, `HEAD..${mergeBase}`, CommitBatchSize)
)
if (!commits) {

This comment was marked as spam.

This comment was marked as spam.

@shiftkey

shiftkey commented Dec 8, 2017

Copy link
Copy Markdown
Member Author

🍎

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

⚡️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants