Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle warnings if stash creation encounters permission issue #7351

Merged
merged 10 commits into from Apr 25, 2019
31 changes: 29 additions & 2 deletions app/src/lib/git/stash.ts
@@ -1,12 +1,15 @@
import { GitError as DugiteError } from 'dugite'
import { git } from '.'

import { Repository } from '../../models/repository'
import { GitError as DugiteError } from 'dugite'
import {
IStashEntry,
StashedChangesLoadStates,
StashedFileChanges,
} from '../../models/stash-entry'
import { CommittedFileChange } from '../../models/status'

import { GitError } from './core'
import { parseChangedFiles } from './log'

export const DesktopStashEntryMarker = '!!GitHub_Desktop'
Expand Down Expand Up @@ -92,7 +95,31 @@ export async function createDesktopStashEntry(
) {
const message = createDesktopStashMessage(branchName)
const args = ['stash', 'push', '--include-untracked', '-m', message]
await git(args, repository.path, 'createStashEntry')

const result = await git(args, repository.path, 'createStashEntry', {
successExitCodes: new Set<number>([0, 1]),
})

if (result.exitCode === 1) {
// search for any line starting with `error:` - /m here to ensure this is
// applied to each line, without needing to split the text
const errorPrefixRe = /^error: /m

const matches = errorPrefixRe.exec(result.stderr)
if (matches !== null && matches.length > 0) {
// rethrow, because these messages should prevent the stash from being created
throw new GitError(result, args)
}

// if no error messages were emitted by Git, we should log but continue because
// a valid stash was created and this should not interfere with the checkout

log.info(
`[createDesktopStashEntry] a stash was created successfully but exit code ${
result.exitCode
} reported. stderr: ${result.stderr}`
)
}
}

async function getStashEntryMatchingSha(repository: Repository, sha: string) {
Expand Down