Skip to content

extract stash creation in AppStore._checkoutBranch into its own method #7609

Closed

Description

@outofambit

This is a follow up refactor issue (and a subset of the work captured in #7607) to simplify some logic in AppStore._checkoutBranch and localize variable creation and assignment for

let stashToPop: IStashEntry | null = null

The idea is to encapsulate the following code block into its own private function on AppStore that returns Promise<StashEntry | null> so we can assign that result directly to stashToPop.

const { tip } = branchesState
const currentBranch = tip.kind === TipState.Valid ? tip.branch : null
if (
currentBranch !== null &&
uncommittedChangesStrategy.kind ===
UncommittedChangesStrategyKind.stashOnCurrentBranch
) {
await this._createStashAndDropPreviousEntry(
repository,
currentBranch.name
)
} else if (
uncommittedChangesStrategy.kind ===
UncommittedChangesStrategyKind.moveToNewBranch
) {
const hasDeletedFiles = changesState.workingDirectory.files.some(
file => file.status.kind === AppFileStatusKind.Deleted
)
if (hasDeletedFiles) {
const stashCreated = await gitStore.performFailableOperation(() => {
return createDesktopStashEntry(repository, foundBranch.name)
})
if (stashCreated) {
stashToPop = await getLastDesktopStashEntryForBranch(
repository,
foundBranch.name
)
}
}
}
}

And then check the stashToPop later in _checkoutBranch to see if we have something non-null to pop.

Originally posted by @outofambit in #7474

Activity

  1. added
    tech-debt
    epic:stashing
    on May 22, 2019
  2. self-assigned this
    on Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

epic:stashingtech-debt

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions