mirror of
https://github.com/desktop/desktop
synced 2024-11-05 20:49:32 +00:00
Refactor to a boolean isCherryPickHeadFound
This commit is contained in:
parent
30eda681ed
commit
e9c39c22af
1 changed files with 8 additions and 15 deletions
|
@ -203,8 +203,7 @@ function parseCherryPickResult(result: IGitResult): CherryPickResult {
|
||||||
export async function getCherryPickSnapshot(
|
export async function getCherryPickSnapshot(
|
||||||
repository: Repository
|
repository: Repository
|
||||||
): Promise<ICherryPickSnapshot | null> {
|
): Promise<ICherryPickSnapshot | null> {
|
||||||
const cherryPickHead = readCherryPickHead(repository)
|
if (isCherryPickHeadFound(repository)) {
|
||||||
if (cherryPickHead === null) {
|
|
||||||
// If there no cherry pick head, there is no cherry pick in progress.
|
// If there no cherry pick head, there is no cherry pick in progress.
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -321,8 +320,7 @@ export async function continueCherryPick(
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure cherry pick is still in progress to continue
|
// make sure cherry pick is still in progress to continue
|
||||||
const cherryPickCurrentCommit = await readCherryPickHead(repository)
|
if (await isCherryPickHeadFound(repository)) {
|
||||||
if (cherryPickCurrentCommit === null) {
|
|
||||||
return CherryPickResult.Aborted
|
return CherryPickResult.Aborted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,29 +366,24 @@ export async function abortCherryPick(repository: Repository) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to read the `.git/CHERRY_PICK_HEAD` file inside a repository to confirm
|
* Check if the `.git/CHERRY_PICK_HEAD` file exists
|
||||||
* the cherry pick is still active.
|
|
||||||
*/
|
*/
|
||||||
async function readCherryPickHead(
|
export async function isCherryPickHeadFound(
|
||||||
repository: Repository
|
repository: Repository
|
||||||
): Promise<string | null> {
|
): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
const cherryPickHead = Path.join(
|
const cherryPickHeadPath = Path.join(
|
||||||
repository.path,
|
repository.path,
|
||||||
'.git',
|
'.git',
|
||||||
'CHERRY_PICK_HEAD'
|
'CHERRY_PICK_HEAD'
|
||||||
)
|
)
|
||||||
const cherryPickCurrentCommitOutput = await FSE.readFile(
|
return FSE.pathExists(cherryPickHeadPath)
|
||||||
cherryPickHead,
|
|
||||||
'utf8'
|
|
||||||
)
|
|
||||||
return cherryPickCurrentCommitOutput.trim()
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.warn(
|
log.warn(
|
||||||
`[cherryPick] a problem was encountered reading .git/CHERRY_PICK_HEAD,
|
`[cherryPick] a problem was encountered reading .git/CHERRY_PICK_HEAD,
|
||||||
so it is unsafe to continue cherry picking`,
|
so it is unsafe to continue cherry picking`,
|
||||||
err
|
err
|
||||||
)
|
)
|
||||||
return null
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue