Merge pull request #16681 from samuelko123/bugfix-for-issue-12994

This commit is contained in:
Sergio Padrino 2023-08-02 17:40:05 +02:00 committed by GitHub
commit 00a46bfe36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 47 deletions

View file

@ -6581,10 +6581,7 @@ export class AppStore extends TypedBaseStore<IAppState> {
/** This shouldn't be called directly. See `Dispatcher`. */
public async _popStashEntry(repository: Repository, stashEntry: IStashEntry) {
const gitStore = this.gitStoreCache.get(repository)
await gitStore.performFailableOperation(() => {
return popStashEntry(repository, stashEntry.stashSha)
})
await popStashEntry(repository, stashEntry.stashSha)
log.info(
`[AppStore. _popStashEntry] popped stash with commit id ${stashEntry.stashSha}`
)

View file

@ -359,8 +359,7 @@ export class RepositoryView extends React.Component<
private renderStashedChangesContent(): JSX.Element | null {
const { changesState } = this.props.state
const { selection, stashEntry, workingDirectory } = changesState
const isWorkingTreeClean = workingDirectory.files.length === 0
const { selection, stashEntry } = changesState
if (selection.kind !== ChangesSelectionKind.Stash || stashEntry === null) {
return null
@ -379,7 +378,6 @@ export class RepositoryView extends React.Component<
askForConfirmationOnDiscardStash={
this.props.askForConfirmationOnDiscardStash
}
isWorkingTreeClean={isWorkingTreeClean}
showSideBySideDiff={this.props.showSideBySideDiff}
onOpenBinaryFile={this.onOpenBinaryFile}
onOpenSubmodule={this.onOpenSubmodule}

View file

@ -3,16 +3,14 @@ import { IStashEntry } from '../../models/stash-entry'
import { Dispatcher } from '../dispatcher'
import { Repository } from '../../models/repository'
import { PopupType } from '../../models/popup'
import { Octicon } from '../octicons'
import * as OcticonSymbol from '../octicons/octicons.generated'
import { OkCancelButtonGroup } from '../dialog/ok-cancel-button-group'
import { ErrorWithMetadata } from '../../lib/error-with-metadata'
interface IStashDiffHeaderProps {
readonly stashEntry: IStashEntry
readonly repository: Repository
readonly dispatcher: Dispatcher
readonly askForConfirmationOnDiscardStash: boolean
readonly isWorkingTreeClean: boolean
}
interface IStashDiffHeaderState {
@ -38,7 +36,6 @@ export class StashDiffHeader extends React.Component<
}
public render() {
const { isWorkingTreeClean } = this.props
const { isRestoring, isDiscarding } = this.state
return (
@ -47,44 +44,23 @@ export class StashDiffHeader extends React.Component<
<div className="row">
<OkCancelButtonGroup
okButtonText="Restore"
okButtonDisabled={
isRestoring || !isWorkingTreeClean || isDiscarding
}
okButtonDisabled={isRestoring || isDiscarding}
onOkButtonClick={this.onRestoreClick}
cancelButtonText="Discard"
cancelButtonDisabled={isRestoring || isDiscarding}
onCancelButtonClick={this.onDiscardClick}
/>
{this.renderExplanatoryText()}
<div className="explanatory-text">
<span className="text">
<strong>Restore</strong> will move your stashed files to the
Changes list.
</span>
</div>
</div>
</div>
)
}
private renderExplanatoryText() {
const { isWorkingTreeClean } = this.props
if (isWorkingTreeClean || this.state.isRestoring) {
return (
<div className="explanatory-text">
<span className="text">
<strong>Restore</strong> will move your stashed files to the Changes
list.
</span>
</div>
)
}
return (
<div className="explanatory-text">
<Octicon symbol={OcticonSymbol.alert} />
<span className="text">
Unable to restore stash when changes are present on your branch.
</span>
</div>
)
}
private onDiscardClick = async () => {
const {
dispatcher,
@ -117,8 +93,16 @@ export class StashDiffHeader extends React.Component<
private onRestoreClick = async () => {
const { dispatcher, repository, stashEntry } = this.props
this.setState({ isRestoring: true }, () => {
dispatcher.popStash(repository, stashEntry)
})
try {
this.setState({ isRestoring: true })
await dispatcher.popStash(repository, stashEntry)
} catch (err) {
const errorWithMetadata = new ErrorWithMetadata(err, {
repository: repository,
})
dispatcher.postError(errorWithMetadata)
} finally {
this.setState({ isRestoring: false })
}
}
}

View file

@ -33,9 +33,6 @@ interface IStashDiffViewerProps {
/** Whether we should display side by side diffs. */
readonly showSideBySideDiff: boolean
/** Are there any uncommitted changes */
readonly isWorkingTreeClean: boolean
/**
* Called when the user requests to open a binary file in an the
* system-assigned application for said file type.
@ -96,7 +93,6 @@ export class StashDiffViewer extends React.PureComponent<IStashDiffViewerProps>
repository,
dispatcher,
imageDiffType,
isWorkingTreeClean,
fileListWidth,
onOpenBinaryFile,
onChangeImageDiffType,
@ -131,7 +127,6 @@ export class StashDiffViewer extends React.PureComponent<IStashDiffViewerProps>
stashEntry={stashEntry}
repository={repository}
dispatcher={dispatcher}
isWorkingTreeClean={isWorkingTreeClean}
askForConfirmationOnDiscardStash={
this.props.askForConfirmationOnDiscardStash
}