-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
397 lines (311 loc) · 10.8 KB
/
Copy pathmodels.py
File metadata and controls
397 lines (311 loc) · 10.8 KB
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
"""Pydantic models for Git operations"""
from typing import Literal
from pydantic import AliasChoices, BaseModel, Field, model_validator
class GitStatus(BaseModel):
repo_path: str
porcelain: bool = False
class GitDiffUnstaged(BaseModel):
repo_path: str
stat_only: bool | None = False
max_lines: int | None = None
name_only: bool | None = False
paths: list[str] | None = None
class GitDiffStaged(BaseModel):
repo_path: str
stat_only: bool | None = False
max_lines: int | None = None
name_only: bool | None = False
paths: list[str] | None = None
class GitDiff(BaseModel):
repo_path: str
target: str | None = None # Made optional for commit range scenarios
stat_only: bool | None = False
max_lines: int | None = None
name_only: bool | None = False
commit_range: str | None = None
base_commit: str | None = None
target_commit: str | None = None
paths: list[str] | None = None
class GitCommit(BaseModel):
repo_path: str
message: str
amend: bool = Field(
default=False,
description="Amend the most recent commit instead of creating a new one",
)
gpg_sign: bool = False
gpg_key_id: str | None = None
allow_empty: bool = Field(
default=False,
description="Allow creating a commit with no staged changes (--allow-empty)",
)
class GitAdd(BaseModel):
repo_path: str
files: list[str]
class GitReset(BaseModel):
repo_path: str
mode: str | None = None # --soft, --mixed, --hard
target: str | None = None # commit hash, branch, tag
files: list[str] | None = None # specific files to reset
class GitLog(BaseModel):
repo_path: str
max_count: int = 10
oneline: bool = False
graph: bool = False
format: str | None = None
since: str | None = None # Date filter: "2024-01-01", "1 week ago"
until: str | None = None # Date filter: "yesterday", "2024-12-31"
author: str | None = None # Author filter: email or name
grep: str | None = None # Commit message search (regex)
files: list[str] | None = None # Commits affecting these files
branch: str | None = None # Specific branch (default: current)
reverse: bool = False # Reverse chronological order
merges: bool | None = None # None=all, True=only merges, False=no merges
class GitCreateBranch(BaseModel):
repo_path: str
branch_name: str
base_branch: str | None = None
start_point: str | None = None
checkout: bool = True # Switch HEAD to the new branch (issue #162)
class GitCheckout(BaseModel):
repo_path: str
branch_name: str
class GitShow(BaseModel):
repo_path: str
revision: str
stat_only: bool | None = False
max_lines: int | None = None
class GitInit(BaseModel):
repo_path: str
class GitClone(BaseModel):
repo_url: str
target_path: str
branch: str | None = None
depth: int | None = None
single_branch: bool = False
recurse_submodules: bool = False
class GitPush(BaseModel):
repo_path: str
remote: str = "origin"
branch: str | None = None
set_upstream: bool = False
force: bool = False
# Issue #161: safer force-push variants
force_with_lease: bool = False
force_with_lease_expect: str | None = None # "<refname>:<sha>" or "<sha>"
force_if_includes: bool = False # git 2.30+, composes with force_with_lease
# Issue #173: delete remote branch and raw refspec support
delete: bool = Field(
False,
description=(
"Delete the remote branch (git push <remote> --delete <branch>). "
"Mutually exclusive with force/refspec."
),
)
refspec: str | None = Field(
None,
description=(
"Raw push refspec (e.g., 'src:dst' or ':branch' to delete). "
"Mutually exclusive with branch/delete."
),
)
dry_run: bool = Field(
False,
description=(
"Show what would be pushed without actually pushing (git push --dry-run). "
"Compatible with all push modes including delete and refspec."
),
)
@model_validator(mode="after")
def _validate_delete_and_refspec(self) -> "GitPush":
if self.delete:
if not self.branch:
raise ValueError("delete=True requires branch to be set")
if self.force or self.force_with_lease or self.force_if_includes:
raise ValueError(
"delete=True cannot be combined with force/force_with_lease/force_if_includes"
)
if self.set_upstream:
raise ValueError("delete=True cannot be combined with set_upstream")
if self.refspec is not None:
raise ValueError("delete=True cannot be combined with refspec")
if self.refspec is not None:
if self.branch is not None:
raise ValueError("refspec cannot be combined with branch")
if self.delete:
raise ValueError("refspec cannot be combined with delete")
if self.set_upstream:
raise ValueError("refspec cannot be combined with set_upstream")
return self
class GitPull(BaseModel):
repo_path: str
remote: str = "origin"
branch: str | None = None
class GitDiffBranches(BaseModel):
"""Compare two branches.
Accepts both 'base_branch'/'compare_branch' and 'branch1'/'branch2' naming.
"""
repo_path: str
base_branch: str = Field(validation_alias=AliasChoices("base_branch", "branch1"))
compare_branch: str = Field(
validation_alias=AliasChoices("compare_branch", "branch2")
)
stat_only: bool | None = False
max_lines: int | None = None
class GitRebase(BaseModel):
repo_path: str
target_branch: str
onto: str | None = Field(
default=None, description="Rebase --onto target (new base)"
)
fork_point: str | None = Field(
default=None, description="Fork point / old base for --onto"
)
branch: str | None = Field(
default=None, description="Branch to rebase (default: current HEAD)"
)
class GitMerge(BaseModel):
repo_path: str
source_branch: str
strategy: str = "merge"
message: str | None = None
class GitCherryPick(BaseModel):
repo_path: str
commit_hash: str
no_commit: bool = False
class GitAbort(BaseModel):
repo_path: str
operation: str
class GitContinue(BaseModel):
repo_path: str
operation: str
class GitSecurityValidate(BaseModel):
repo_path: str
class GitSecurityEnforce(BaseModel):
repo_path: str
strict_mode: bool = True
class GitBranchList(BaseModel):
repo_path: str
branch_type: Literal["local", "remote", "all"] = Field(
"local", description="Which branches to list: local, remote, or all"
)
pattern: str | None = Field(
None, description="fnmatch glob filter, e.g. 'feature/*'"
)
contains: str | None = Field(
None, description="commit-ish; only branches containing this commit"
)
merged: bool | None = Field(
None,
description="True=only merged into HEAD, False=only unmerged, None=no filter",
)
sort: str | None = Field(
None,
description="Sort key, e.g. '-committerdate' (most-recent first), 'refname', 'authordate'. "
"Mirrors `git for-each-ref --sort=<key>` semantics. None = no ordering guarantee.",
)
class GitMergeBase(BaseModel):
repo_path: str
ref1: str
ref2: str
class GitSubmoduleStatus(BaseModel):
repo_path: str
class GitSubmoduleAdd(BaseModel):
repo_path: str
url: str
path: str
branch: str | None = None
class GitSubmoduleUpdate(BaseModel):
repo_path: str
init: bool = True
recursive: bool = False
remote: bool = False
paths: list[str] | None = None
class GitSubmoduleSync(BaseModel):
repo_path: str
recursive: bool = False
class GitConfigGet(BaseModel):
repo_path: str
key: str
file: str | None = None
scope: str | None = None
class GitConfigSet(BaseModel):
repo_path: str
key: str
value: str
file: str | None = None
scope: str | None = None
class GitConfigList(BaseModel):
repo_path: str
file: str | None = None
scope: str | None = None
class GitRestore(BaseModel):
repo_path: str
files: list[str] = Field(description="Files to restore")
staged: bool = Field(
default=False, description="Unstage files (git restore --staged)"
)
source: str | None = Field(
default=None,
description="Restore from specific commit/ref (git restore --source)",
)
class GitBranchUpdate(BaseModel):
repo_path: str
branch_name: str = Field(description="Branch to update or delete")
target: str | None = Field(
default=None,
description="Target ref for force-update (git branch -f <name> <target>)",
)
delete: bool = Field(default=False, description="Delete the branch")
force: bool = Field(
default=False, description="Force delete even if not merged (git branch -D)"
)
class GitBranchDelete(BaseModel):
repo_path: str
branch_name: str = Field(description="Branch to delete")
force: bool = Field(
default=False, description="Force delete unmerged branch (-D)"
)
class GitWorktreeList(BaseModel):
repo_path: str
class GitWorktreeRemove(BaseModel):
repo_path: str
worktree_path: str = Field(description="Path of worktree to remove")
force: bool = Field(
default=False, description="Force removal even with modifications"
)
class GitWorktreeAdd(BaseModel):
"""Inputs for git_worktree_add — create a new linked worktree."""
repo_path: str = Field(..., description="Path to the existing git repository.")
worktree_path: str = Field(
..., description="Filesystem path where the new worktree should be created."
)
branch: str | None = Field(
default=None,
description="Existing branch to check out in the new worktree.",
)
new_branch: str | None = Field(
default=None,
description="Name of a NEW branch to create and check out (uses -b, or -B with force).",
)
force: bool = Field(
default=False,
description="Pass --force to git worktree add. When combined with new_branch, uses -B (force-create) instead of -b.",
)
class GitMergeTree(BaseModel):
repo_path: str
branch1: str = Field(description="First branch (typically current)")
branch2: str = Field(description="Second branch (typically incoming)")
class GitRm(BaseModel):
repo_path: str
file: str = Field(
description="Single file path to remove (no wildcards, no directories)"
)
cached: bool = Field(
default=False,
description="Remove from index only, keep working tree file (--cached)",
)
dry_run: bool = Field(
default=False,
description="Show what would be removed without doing it (--dry-run)",
)