|
1 | 1 | import type Types from '../types' |
| 2 | +import { REBASE_MARKS } from './rebase-marks' |
2 | 3 | import { TRANSIENT_STATE_FILES } from './transient-state-files' |
3 | 4 |
|
4 | 5 | /** |
5 | 6 | * Whether the repository is mid-merge, mid-rebase, mid-cherry-pick or |
6 | | - * mid-revert, from one listing of the git directory. |
| 7 | + * mid-revert, from a listing of the git directory. |
7 | 8 | * |
8 | | - * A state file counts only as a real file; a symbolic link by that name is |
9 | | - * never touched. |
| 9 | + * A state file counts only as a real file and a rebase's folder only as a |
| 10 | + * real directory, listed once more to tell a rebase's from `git am`'s; a |
| 11 | + * symbolic link by any of those names is never touched. |
10 | 12 | * |
11 | 13 | * @param entryKindsOf the host's directory listing |
12 | 14 | * @param gitDir the repository's own git directory, absolute |
13 | | - * @returns whether any of TRANSIENT_STATE_FILES is present as a file |
| 15 | + * @returns whether a state file, or a rebase's file beside its folder, is there |
14 | 16 | */ |
15 | 17 | export async function isTransient( |
16 | 18 | entryKindsOf: Types.GitDeps['entryKindsOf'], |
17 | 19 | gitDir: string, |
18 | 20 | ): Promise<boolean> { |
19 | 21 | const entries = await entryKindsOf(gitDir) |
| 22 | + const isStopped = entries?.get(REBASE_MARKS.head) === 'file' |
| 23 | + const isApplying = isStopped && entries?.get(REBASE_MARKS.apply) === 'dir' |
20 | 24 |
|
21 | | - return TRANSIENT_STATE_FILES.some(file => entries?.get(file) === 'file') |
| 25 | + const applied = isApplying |
| 26 | + ? await entryKindsOf(`${gitDir}/${REBASE_MARKS.apply}`) |
| 27 | + : null |
| 28 | + |
| 29 | + const isRebasing = |
| 30 | + isStopped && |
| 31 | + (entries?.get(REBASE_MARKS.merge) === 'dir' || |
| 32 | + applied?.get(REBASE_MARKS.rebasing) === 'file') |
| 33 | + |
| 34 | + return ( |
| 35 | + isRebasing || |
| 36 | + TRANSIENT_STATE_FILES.some(file => entries?.get(file) === 'file') |
| 37 | + ) |
22 | 38 | } |
0 commit comments