1 | import { GIT_ERROR, TASK_ERROR } from './messages.js'
|
2 | import {
|
3 | ApplyEmptyCommitError,
|
4 | TaskError,
|
5 | RestoreOriginalStateError,
|
6 | GitError,
|
7 | RestoreUnstagedChangesError,
|
8 | } from './symbols.js'
|
9 |
|
10 | export const getInitialState = ({ quiet = false } = {}) => ({
|
11 | hasPartiallyStagedFiles: null,
|
12 | shouldBackup: null,
|
13 | errors: new Set([]),
|
14 | output: [],
|
15 | quiet,
|
16 | })
|
17 |
|
18 | export const hasPartiallyStagedFiles = (ctx) => ctx.hasPartiallyStagedFiles
|
19 |
|
20 | export const applyModificationsSkipped = (ctx) => {
|
21 |
|
22 | if (!ctx.shouldBackup) return false
|
23 |
|
24 | if (ctx.errors.has(GitError)) {
|
25 | return GIT_ERROR
|
26 | }
|
27 |
|
28 | if (ctx.errors.has(TaskError)) {
|
29 | return TASK_ERROR
|
30 | }
|
31 | }
|
32 |
|
33 | export const restoreUnstagedChangesSkipped = (ctx) => {
|
34 |
|
35 | if (ctx.errors.has(GitError)) {
|
36 | return GIT_ERROR
|
37 | }
|
38 |
|
39 | if (ctx.errors.has(TaskError)) {
|
40 | return TASK_ERROR
|
41 | }
|
42 | }
|
43 |
|
44 | export const restoreOriginalStateEnabled = (ctx) =>
|
45 | ctx.shouldBackup &&
|
46 | (ctx.errors.has(TaskError) ||
|
47 | ctx.errors.has(ApplyEmptyCommitError) ||
|
48 | ctx.errors.has(RestoreUnstagedChangesError))
|
49 |
|
50 | export const restoreOriginalStateSkipped = (ctx) => {
|
51 |
|
52 | if (
|
53 | ctx.errors.has(GitError) &&
|
54 | !ctx.errors.has(ApplyEmptyCommitError) &&
|
55 | !ctx.errors.has(RestoreUnstagedChangesError)
|
56 | ) {
|
57 | return GIT_ERROR
|
58 | }
|
59 | }
|
60 |
|
61 | export const cleanupEnabled = (ctx) => ctx.shouldBackup
|
62 |
|
63 | export const cleanupSkipped = (ctx) => {
|
64 |
|
65 | if (
|
66 | ctx.errors.has(GitError) &&
|
67 | !ctx.errors.has(ApplyEmptyCommitError) &&
|
68 | !ctx.errors.has(RestoreUnstagedChangesError)
|
69 | ) {
|
70 | return GIT_ERROR
|
71 | }
|
72 |
|
73 | if (ctx.errors.has(RestoreOriginalStateError)) {
|
74 | return GIT_ERROR
|
75 | }
|
76 | }
|