-
-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathcommands.py
359 lines (285 loc) · 8.03 KB
/
commands.py
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
from __future__ import annotations
import typer
from typing import List, TYPE_CHECKING
from git_sim.enums import ResetMode, StashSubCommand
from git_sim.settings import settings
if TYPE_CHECKING:
from manim import Scene
def handle_animations(scene: Scene) -> None:
from git_sim.animations import handle_animations as _handle_animations
return _handle_animations(scene)
def add(
files: List[str] = typer.Argument(
default=None,
help="The names of one or more files to add to Git's staging area",
)
):
from git_sim.add import Add
settings.hide_first_tag = True
scene = Add(files=files)
handle_animations(scene=scene)
def branch(
name: str = typer.Argument(
...,
help="The name of the new branch",
)
):
from git_sim.branch import Branch
scene = Branch(name=name)
handle_animations(scene=scene)
def checkout(
branch: str = typer.Argument(
...,
help="The name of the branch to checkout",
),
b: bool = typer.Option(
False,
"-b",
help="Create the specified branch if it doesn't already exist",
),
):
from git_sim.checkout import Checkout
scene = Checkout(branch=branch, b=b)
handle_animations(scene=scene)
def cherry_pick(
commit: str = typer.Argument(
...,
help="The ref (branch/tag), or commit ID to simulate cherry-pick onto active branch",
),
edit: str = typer.Option(
None,
"--edit",
"-e",
help="Specify a new commit message for the cherry-picked commit",
),
):
from git_sim.cherrypick import CherryPick
scene = CherryPick(commit=commit, edit=edit)
handle_animations(scene=scene)
def clean():
from git_sim.clean import Clean
settings.hide_first_tag = True
scene = Clean()
handle_animations(scene=scene)
def clone(
url: str = typer.Argument(
...,
help="The web URL or filesystem path of the Git repo to clone",
),
):
from git_sim.clone import Clone
scene = Clone(url=url)
handle_animations(scene=scene)
def commit(
message: str = typer.Option(
"New commit",
"--message",
"-m",
help="The commit message of the new commit",
),
amend: bool = typer.Option(
default=False,
help="Amend the last commit message, must be used with the --message flag",
),
):
from git_sim.commit import Commit
settings.hide_first_tag = True
scene = Commit(message=message, amend=amend)
handle_animations(scene=scene)
def fetch(
remote: str = typer.Argument(
default=None,
help="The name of the remote to fetch from",
),
branch: str = typer.Argument(
default=None,
help="The name of the branch to fetch",
),
):
from git_sim.fetch import Fetch
scene = Fetch(remote=remote, branch=branch)
handle_animations(scene=scene)
def log(
ctx: typer.Context,
n: int = typer.Option(
None,
"-n",
help="Number of commits to display from branch heads",
),
all: bool = typer.Option(
False,
"--all",
help="Display all local branches in the log output",
),
):
from git_sim.log import Log
scene = Log(ctx=ctx, n=n, all=all)
handle_animations(scene=scene)
def merge(
branch: str = typer.Argument(
...,
help="The name of the branch to merge into the active checked-out branch",
),
no_ff: bool = typer.Option(
False,
"--no-ff",
help="Simulate creation of a merge commit in all cases, even when the merge could instead be resolved as a fast-forward",
),
message: str = typer.Option(
"Merge commit",
"--message",
"-m",
help="The commit message of the new merge commit",
),
):
from git_sim.merge import Merge
scene = Merge(branch=branch, no_ff=no_ff, message=message)
handle_animations(scene=scene)
def mv(
file: str = typer.Argument(
default=None,
help="The name of the file to change the name/path of",
),
new_file: str = typer.Argument(
default=None,
help="The new name/path of the file",
),
):
from git_sim.mv import Mv
settings.hide_first_tag = True
scene = Mv(file=file, new_file=new_file)
handle_animations(scene=scene)
def pull(
remote: str = typer.Argument(
default=None,
help="The name of the remote to pull from",
),
branch: str = typer.Argument(
default=None,
help="The name of the branch to pull",
),
):
from git_sim.pull import Pull
scene = Pull(remote=remote, branch=branch)
handle_animations(scene=scene)
def push(
remote: str = typer.Argument(
default=None,
help="The name of the remote to push to",
),
branch: str = typer.Argument(
default=None,
help="The name of the branch to push",
),
):
from git_sim.push import Push
scene = Push(remote=remote, branch=branch)
handle_animations(scene=scene)
def rebase(
branch: str = typer.Argument(
...,
help="The branch to simulate rebasing the checked-out commit onto",
)
):
from git_sim.rebase import Rebase
scene = Rebase(branch=branch)
handle_animations(scene=scene)
def reset(
commit: str = typer.Argument(
default="HEAD",
help="The ref (branch/tag), or commit ID to simulate reset to",
),
mode: ResetMode = typer.Option(
default="mixed",
help="Either mixed, soft, or hard",
),
soft: bool = typer.Option(
default=False,
help="Simulate a soft reset, shortcut for --mode=soft",
),
mixed: bool = typer.Option(
default=False,
help="Simulate a mixed reset, shortcut for --mode=mixed",
),
hard: bool = typer.Option(
default=False,
help="Simulate a soft reset, shortcut for --mode=hard",
),
):
from git_sim.reset import Reset
settings.hide_first_tag = True
scene = Reset(commit=commit, mode=mode, soft=soft, mixed=mixed, hard=hard)
handle_animations(scene=scene)
def restore(
files: List[str] = typer.Argument(
default=None,
help="The names of one or more files to restore",
)
):
from git_sim.restore import Restore
settings.hide_first_tag = True
scene = Restore(files=files)
handle_animations(scene=scene)
def revert(
commit: str = typer.Argument(
default="HEAD",
help="The ref (branch/tag), or commit ID to simulate revert",
)
):
from git_sim.revert import Revert
settings.hide_first_tag = True
scene = Revert(commit=commit)
handle_animations(scene=scene)
def rm(
files: List[str] = typer.Argument(
default=None,
help="The names of one or more files to remove from Git's index",
)
):
from git_sim.rm import Rm
settings.hide_first_tag = True
scene = Rm(files=files)
handle_animations(scene=scene)
def stash(
command: StashSubCommand = typer.Argument(
default=None,
help="Stash subcommand (push, pop, apply)",
),
files: List[str] = typer.Argument(
default=None,
help="The name of the file to stash changes for",
),
):
from git_sim.stash import Stash
settings.hide_first_tag = True
scene = Stash(files=files, command=command)
handle_animations(scene=scene)
def status():
from git_sim.status import Status
settings.hide_first_tag = True
settings.allow_no_commits = True
scene = Status()
handle_animations(scene=scene)
def switch(
branch: str = typer.Argument(
...,
help="The name of the branch to switch to",
),
c: bool = typer.Option(
False,
"-c",
help="Create the specified branch if it doesn't already exist",
),
):
from git_sim.switch import Switch
scene = Switch(branch=branch, c=c)
handle_animations(scene=scene)
def tag(
name: str = typer.Argument(
...,
help="The name of the new tag",
)
):
from git_sim.tag import Tag
scene = Tag(name=name)
handle_animations(scene=scene)