diff --git a/app/src/lib/stores/app-store.ts b/app/src/lib/stores/app-store.ts index e1ca99e100..8388bdec33 100644 --- a/app/src/lib/stores/app-store.ts +++ b/app/src/lib/stores/app-store.ts @@ -2376,90 +2376,106 @@ export class AppStore extends TypedBaseStore { const gitStore = this.gitStoreCache.get(repository) - const result = await this.isCommitting(repository, () => { - return gitStore.performFailableOperation(async () => { + return this.withIsCommitting(repository, async () => { + const result = await gitStore.performFailableOperation(async () => { const message = await formatCommitMessage(repository, context) - return createCommit(repository, message, selectedFiles) + return createCommit(repository, message, selectedFiles) !== undefined }) + + if (result) { + await this._recordCommitStats( + gitStore, + repository, + state, + context, + files + ) + + await this._refreshRepository(repository) + await this.refreshChangesSection(repository, { + includingStatus: true, + clearPartialState: true, + }) + } + + return result || false }) + } - if (result) { - this.statsStore.recordCommit() + private async _recordCommitStats( + gitStore: GitStore, + repository: Repository, + repositoryState: IRepositoryState, + context: ICommitContext, + files: readonly WorkingDirectoryFileChange[] + ) { + this.statsStore.recordCommit() - const includedPartialSelections = files.some( - file => file.selection.getSelectionType() === DiffSelectionType.Partial - ) - if (includedPartialSelections) { - this.statsStore.recordPartialCommit() - } - - const { trailers } = context - if (trailers !== undefined && trailers.some(isCoAuthoredByTrailer)) { - this.statsStore.recordCoAuthoredCommit() - } - - const account = getAccountForRepository(this.accounts, repository) - if (repository.gitHubRepository !== null) { - if (account !== null) { - if (account.endpoint === getDotComAPIEndpoint()) { - this.statsStore.recordCommitToDotcom() - } else { - this.statsStore.recordCommitToEnterprise() - } - - const { commitAuthor } = state - if (commitAuthor !== null) { - const commitEmail = commitAuthor.email.toLowerCase() - const attributableEmails = getAttributableEmailsFor(account) - const commitEmailMatchesAccount = attributableEmails.some( - email => email.toLowerCase() === commitEmail - ) - if (!commitEmailMatchesAccount) { - this.statsStore.recordUnattributedCommit() - } - } - } - - const branchProtectionsFound = await this.repositoriesStore.hasBranchProtectionsConfigured( - repository.gitHubRepository - ) - - if (branchProtectionsFound) { - this.statsStore.recordCommitToRepositoryWithBranchProtections() - } - - const branchName = findRemoteBranchName( - gitStore.tip, - gitStore.currentRemote, - repository.gitHubRepository - ) - - if (branchName !== null) { - const { changesState } = this.repositoryStateCache.get(repository) - if (changesState.currentBranchProtected) { - this.statsStore.recordCommitToProtectedBranch() - } - } - - if ( - repository.gitHubRepository !== null && - !hasWritePermission(repository.gitHubRepository) - ) { - this.statsStore.recordCommitToRepositoryWithoutWriteAccess() - this.statsStore.recordRepositoryCommitedInWithoutWriteAccess( - repository.gitHubRepository.dbID - ) - } - } - - await this._refreshRepository(repository) - await this.refreshChangesSection(repository, { - includingStatus: true, - clearPartialState: true, - }) + const includedPartialSelections = files.some( + file => file.selection.getSelectionType() === DiffSelectionType.Partial + ) + if (includedPartialSelections) { + this.statsStore.recordPartialCommit() } - return result || false + const { trailers } = context + if (trailers !== undefined && trailers.some(isCoAuthoredByTrailer)) { + this.statsStore.recordCoAuthoredCommit() + } + + const account = getAccountForRepository(this.accounts, repository) + if (repository.gitHubRepository !== null) { + if (account !== null) { + if (account.endpoint === getDotComAPIEndpoint()) { + this.statsStore.recordCommitToDotcom() + } else { + this.statsStore.recordCommitToEnterprise() + } + + const { commitAuthor } = repositoryState + if (commitAuthor !== null) { + const commitEmail = commitAuthor.email.toLowerCase() + const attributableEmails = getAttributableEmailsFor(account) + const commitEmailMatchesAccount = attributableEmails.some( + email => email.toLowerCase() === commitEmail + ) + if (!commitEmailMatchesAccount) { + this.statsStore.recordUnattributedCommit() + } + } + } + + const branchProtectionsFound = await this.repositoriesStore.hasBranchProtectionsConfigured( + repository.gitHubRepository + ) + + if (branchProtectionsFound) { + this.statsStore.recordCommitToRepositoryWithBranchProtections() + } + + const branchName = findRemoteBranchName( + gitStore.tip, + gitStore.currentRemote, + repository.gitHubRepository + ) + + if (branchName !== null) { + const { changesState } = this.repositoryStateCache.get(repository) + if (changesState.currentBranchProtected) { + this.statsStore.recordCommitToProtectedBranch() + } + } + + if ( + repository.gitHubRepository !== null && + !hasWritePermission(repository.gitHubRepository) + ) { + this.statsStore.recordCommitToRepositoryWithoutWriteAccess() + this.statsStore.recordRepositoryCommitedInWithoutWriteAccess( + repository.gitHubRepository.dbID + ) + } + } } /** This shouldn't be called directly. See `Dispatcher`. */ @@ -3562,14 +3578,14 @@ export class AppStore extends TypedBaseStore { }) } - private async isCommitting( + private async withIsCommitting( repository: Repository, - fn: () => Promise - ): Promise { + fn: () => Promise + ): Promise { const state = this.repositoryStateCache.get(repository) // ensure the user doesn't try and commit again if (state.isCommitting) { - return + return false } this.repositoryStateCache.update(repository, () => ({ @@ -3578,8 +3594,7 @@ export class AppStore extends TypedBaseStore { this.emitUpdate() try { - const sha = await fn() - return sha !== undefined + return await fn() } finally { this.repositoryStateCache.update(repository, () => ({ isCommitting: false, diff --git a/app/src/ui/changes/changes-list.tsx b/app/src/ui/changes/changes-list.tsx index d02a962db9..91157a88fe 100644 --- a/app/src/ui/changes/changes-list.tsx +++ b/app/src/ui/changes/changes-list.tsx @@ -776,7 +776,10 @@ export class ChangesList extends React.Component< selectedRows={this.state.selectedRows} selectionMode="multi" onSelectionChanged={this.props.onFileSelectionChanged} - invalidationProps={this.props.workingDirectory} + invalidationProps={{ + workingDirectory: this.props.workingDirectory, + isCommitting: this.props.isCommitting, + }} onRowClick={this.props.onRowClick} onScroll={this.onScroll} setScrollTop={this.props.changesListScrollTop}