-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
status.ts
131 lines (109 loc) · 3.21 KB
/
status.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
'use strict';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import { GitReference, GitStatus, Repository } from '../../git/git';
import { CommandQuickPickItem, GitCommandQuickPickItem } from '../../quickpicks';
import { Strings } from '../../system';
import { ViewsWithRepositoryFolders } from '../../views/viewBase';
import {
PartialStepState,
pickRepositoryStep,
QuickCommand,
showRepositoryStatusStep,
StepGenerator,
StepResult,
StepState,
} from '../quickCommand';
interface Context {
repos: Repository[];
associatedView: ViewsWithRepositoryFolders;
status: GitStatus;
title: string;
}
interface State {
repo: string | Repository;
}
export interface StatusGitCommandArgs {
readonly command: 'status';
state?: Partial<State>;
}
type StatusStepState<T extends State = State> = ExcludeSome<StepState<T>, 'repo', string>;
export class StatusGitCommand extends QuickCommand<State> {
constructor(args?: StatusGitCommandArgs) {
super('status', 'status', 'Status', {
description: 'shows status information about a repository',
});
let counter = 0;
if (args?.state?.repo != null) {
counter++;
}
this.initialState = {
counter: counter,
confirm: false,
...args?.state,
};
}
override get canConfirm() {
return false;
}
protected async *steps(state: PartialStepState<State>): StepGenerator {
const context: Context = {
repos: Container.instance.git.openRepositories,
associatedView: Container.instance.commitsView,
status: undefined!,
title: this.title,
};
let skippedStepOne = false;
while (this.canStepsContinue(state)) {
context.title = this.title;
if (state.counter < 1 || state.repo == null || typeof state.repo === 'string') {
skippedStepOne = false;
if (context.repos.length === 1) {
skippedStepOne = true;
if (state.repo == null) {
state.counter++;
}
state.repo = context.repos[0];
} else {
const result = yield* pickRepositoryStep(state, context);
// Always break on the first step (so we will go back)
if (result === StepResult.Break) break;
state.repo = result;
}
}
context.status = (await state.repo.getStatus())!;
if (context.status == null) return;
context.title = `${this.title}${Strings.pad(GlyphChars.Dot, 2, 2)}${GitReference.toString(
GitReference.create(context.status.branch, state.repo.path, {
refType: 'branch',
name: context.status.branch,
remote: false,
upstream:
context.status.upstream != null ? { name: context.status.upstream, missing: false } : undefined,
}),
{ icon: false },
)}`;
const result = yield* showRepositoryStatusStep(state as StatusStepState, context);
if (result === StepResult.Break) {
// If we skipped the previous step, make sure we back up past it
if (skippedStepOne) {
state.counter--;
}
continue;
}
if (result instanceof GitCommandQuickPickItem) {
const r = yield* result.executeSteps(this.pickedVia);
state.counter--;
if (r === StepResult.Break) {
QuickCommand.endSteps(state);
}
continue;
}
if (result instanceof CommandQuickPickItem) {
QuickCommand.endSteps(state);
void result.execute();
break;
}
}
}
}