nushell/git-completions.nu 45.4 K raw
1
def "nu-complete git available upstream" [] {
2
  ^git branch --no-color -a | lines | each { |line| $line | str replace '* ' "" | str trim }
3
}
4
5
def "nu-complete git remotes" [] {
6
  ^git remote | lines | each { |line| $line | str trim }
7
}
8
9
def "nu-complete git log" [] {
10
  ^git log --pretty=%h | lines | each { |line| $line | str trim }
11
}
12
13
# Yield all existing commits in descending chronological order.
14
def "nu-complete git commits all" [] {
15
  ^git rev-list --all --remotes --pretty=oneline | lines | parse "{value} {description}"
16
}
17
18
# Yield commits of current branch only. This is useful for e.g. cut points in
19
# `git rebase`.
20
def "nu-complete git commits current branch" [] {
21
  ^git log --pretty="%h %s" | lines | parse "{value} {description}"
22
}
23
24
# Yield local branches like `main`, `feature/typo_fix`
25
def "nu-complete git local branches" [] {
26
  ^git branch --no-color | lines | each { |line| $line | str replace '* ' "" | str trim }
27
}
28
29
# Yield remote branches like `origin/main`, `upstream/feature-a`
30
def "nu-complete git remote branches with prefix" [] {
31
  ^git branch --no-color -r | lines | parse -r '^\*?(\s*|\s*\S* -> )(?P<branch>\S*$)' | get branch | uniq
32
}
33
34
# Yield remote branches *without* prefix which do not have a local counterpart.
35
# E.g. `upstream/feature-a` as `feature-a` to checkout and track in one command
36
# with `git checkout` or `git switch`.
37
def "nu-complete git remote branches nonlocal without prefix" [] {
38
  # Get regex to strip remotes prefixes. It will look like `(origin|upstream)`
39
  # for the two remotes `origin` and `upstream`.
40
  let remotes_regex = (["(", ((nu-complete git remotes | each {|r| [$r, '/'] | str join}) | str join "|"), ")"] | str join)
41
  let local_branches = (nu-complete git local branches)
42
  ^git branch --no-color -r | lines | parse -r (['^[\* ]+', $remotes_regex, '?(?P<branch>\S+)'] | flatten | str join) | get branch | uniq | where {|branch| $branch != "HEAD"} | where {|branch| $branch not-in $local_branches }
43
}
44
45
def "nu-complete git switch" [] {
46
  (nu-complete git local branches)
47
  | parse "{value}"
48
  | insert description "local branch"
49
  | append (nu-complete git remote branches nonlocal without prefix
50
            | parse "{value}"
51
            | insert description "remote branch")
52
}
53
54
def "nu-complete git checkout" [] {
55
  (nu-complete git local branches)
56
  | parse "{value}"
57
  | insert description "local branch"
58
  | append (nu-complete git remote branches nonlocal without prefix
59
            | parse "{value}"
60
            | insert description "remote branch")
61
  | append (nu-complete git remote branches with prefix
62
            | parse "{value}"
63
            | insert description "remote branch")
64
  | append (nu-complete git commits all)
65
  | append (nu-complete git files | where description != "Untracked" | select value)
66
}
67
68
# Arguments to `git rebase --onto <arg1> <arg2>`
69
def "nu-complete git rebase" [] {
70
  (nu-complete git local branches)
71
  | parse "{value}"
72
  | insert description "local branch"
73
  | append (nu-complete git remote branches with prefix
74
            | parse "{value}"
75
            | insert description "remote branch")
76
  | append (nu-complete git commits all)
77
}
78
79
def "nu-complete git stash-list" [] {
80
  git stash list | lines | parse "{value}: {description}"
81
}
82
83
def "nu-complete git tags" [] {
84
  ^git tag --no-color | lines
85
}
86
87
# See `man git-status` under "Short Format"
88
# This is incomplete, but should cover the most common cases.
89
const short_status_descriptions = {
90
  ".D": "Deleted"
91
  ".M": "Modified"
92
  "!" : "Ignored"
93
  "?" : "Untracked"
94
  "AU": "Staged, not merged"
95
  "MD": "Some modifications staged, file deleted in work tree"
96
  "MM": "Some modifications staged, some modifications untracked"
97
  "R.": "Renamed"
98
  "UU": "Both modified (in merge conflict)"
99
}
100
101
def "nu-complete git files" [] {
102
  let relevant_statuses = ["?",".M", "MM", "MD", ".D", "UU"]
103
  ^git status -uall --porcelain=2
104
  | lines
105
  | each { |$it|
106
    if $it starts-with "1 " {
107
      $it | parse --regex "1 (?P<short_status>\\S+) (?:\\S+\\s?){6} (?P<value>\\S+)"
108
    } else if $it starts-with "2 " {
109
      $it | parse --regex "2 (?P<short_status>\\S+) (?:\\S+\\s?){6} (?P<value>\\S+)"
110
    } else if $it starts-with "u " {
111
      $it | parse --regex "u (?P<short_status>\\S+) (?:\\S+\\s?){8} (?P<value>\\S+)"
112
    } else if $it starts-with "? " {
113
      $it | parse --regex "(?P<short_status>.{1}) (?P<value>.+)"
114
    } else {
115
      { short_status: 'unknown', value: $it }
116
    }
117
  }
118
  | flatten
119
  | where $it.short_status in $relevant_statuses
120
  | insert "description" { |e| $short_status_descriptions | get $e.short_status}
121
}
122
123
def "nu-complete git built-in-refs" [] {
124
  [HEAD FETCH_HEAD ORIG_HEAD]
125
}
126
127
def "nu-complete git refs" [] {
128
  nu-complete git local branches
129
  | parse "{value}"
130
  | insert description Branch
131
  | append (nu-complete git tags | parse "{value}" | insert description Tag)
132
  | append (nu-complete git built-in-refs)
133
}
134
135
def "nu-complete git files-or-refs" [] {
136
  nu-complete git local branches
137
  | parse "{value}"
138
  | insert description Branch
139
  | append (nu-complete git files | where description == "Modified" | select value)
140
  | append (nu-complete git tags | parse "{value}" | insert description Tag)
141
  | append (nu-complete git built-in-refs)
142
}
143
144
def "nu-complete git subcommands" [] {
145
  ^git help -a | lines | where $it starts-with "   " | parse -r '\s*(?P<value>[^ ]+) \s*(?P<description>\w.*)'
146
}
147
148
def "nu-complete git add" [] {
149
  nu-complete git files
150
}
151
152
def "nu-complete git pull rebase" [] {
153
  ["false","true","merges","interactive"]
154
}
155
156
157
# Check out git branches and files
158
export extern "git checkout" [
159
  ...targets: string@"nu-complete git checkout"   # name of the branch or files to checkout
160
  --conflict: string                              # conflict style (merge or diff3)
161
  --detach(-d)                                    # detach HEAD at named commit
162
  --force(-f)                                     # force checkout (throw away local modifications)
163
  --guess                                         # second guess 'git checkout <no-such-branch>' (default)
164
  --ignore-other-worktrees                        # do not check if another worktree is holding the given ref
165
  --ignore-skip-worktree-bits                     # do not limit pathspecs to sparse entries only
166
  --merge(-m)                                     # perform a 3-way merge with the new branch
167
  --orphan: string                                # new unparented branch
168
  --ours(-2)                                      # checkout our version for unmerged files
169
  --overlay                                       # use overlay mode (default)
170
  --overwrite-ignore                              # update ignored files (default)
171
  --patch(-p)                                     # select hunks interactively
172
  --pathspec-from-file: string                    # read pathspec from file
173
  --progress                                      # force progress reporting
174
  --quiet(-q)                                     # suppress progress reporting
175
  --recurse-submodules                            # control recursive updating of submodules
176
  --theirs(-3)                                    # checkout their version for unmerged files
177
  --track(-t)                                     # set upstream info for new branch
178
  -b                                              # create and checkout a new branch
179
  -B: string                                      # create/reset and checkout a branch
180
  -l                                              # create reflog for new branch
181
]
182
183
# Download objects and refs from another repository
184
export extern "git fetch" [
185
  repository?: string@"nu-complete git remotes" # name of the branch to fetch
186
  --all                                         # Fetch all remotes
187
  --append(-a)                                  # Append ref names and object names to .git/FETCH_HEAD
188
  --atomic                                      # Use an atomic transaction to update local refs.
189
  --depth: int                                  # Limit fetching to n commits from the tip
190
  --deepen: int                                 # Limit fetching to n commits from the current shallow boundary
191
  --shallow-since: string                       # Deepen or shorten the history by date
192
  --shallow-exclude: string                     # Deepen or shorten the history by branch/tag
193
  --unshallow                                   # Fetch all available history
194
  --update-shallow                              # Update .git/shallow to accept new refs
195
  --negotiation-tip: string                     # Specify which commit/glob to report while fetching
196
  --negotiate-only                              # Do not fetch, only print common ancestors
197
  --dry-run                                     # Show what would be done
198
  --write-fetch-head                            # Write fetched refs in FETCH_HEAD (default)
199
  --no-write-fetch-head                         # Do not write FETCH_HEAD
200
  --force(-f)                                   # Always update the local branch
201
  --keep(-k)                                    # Keep downloaded pack
202
  --multiple                                    # Allow several arguments to be specified
203
  --auto-maintenance                            # Run 'git maintenance run --auto' at the end (default)
204
  --no-auto-maintenance                         # Don't run 'git maintenance' at the end
205
  --auto-gc                                     # Run 'git maintenance run --auto' at the end (default)
206
  --no-auto-gc                                  # Don't run 'git maintenance' at the end
207
  --write-commit-graph                          # Write a commit-graph after fetching
208
  --no-write-commit-graph                       # Don't write a commit-graph after fetching
209
  --prefetch                                    # Place all refs into the refs/prefetch/ namespace
210
  --prune(-p)                                   # Remove obsolete remote-tracking references
211
  --prune-tags(-P)                              # Remove any local tags that do not exist on the remote
212
  --no-tags(-n)                                 # Disable automatic tag following
213
  --refmap: string                              # Use this refspec to map the refs to remote-tracking branches
214
  --tags(-t)                                    # Fetch all tags
215
  --recurse-submodules: string                  # Fetch new commits of populated submodules (yes/on-demand/no)
216
  --jobs(-j): int                               # Number of parallel children
217
  --no-recurse-submodules                       # Disable recursive fetching of submodules
218
  --set-upstream                                # Add upstream (tracking) reference
219
  --submodule-prefix: string                    # Prepend to paths printed in informative messages
220
  --upload-pack: string                         # Non-default path for remote command
221
  --quiet(-q)                                   # Silence internally used git commands
222
  --verbose(-v)                                 # Be verbose
223
  --progress                                    # Report progress on stderr
224
  --server-option(-o): string                   # Pass options for the server to handle
225
  --show-forced-updates                         # Check if a branch is force-updated
226
  --no-show-forced-updates                      # Don't check if a branch is force-updated
227
  -4                                            # Use IPv4 addresses, ignore IPv6 addresses
228
  -6                                            # Use IPv6 addresses, ignore IPv4 addresses
229
]
230
231
# Push changes
232
export extern "git push" [
233
  remote?: string@"nu-complete git remotes",         # the name of the remote
234
  ...refs: string@"nu-complete git local branches"   # the branch / refspec
235
  --all                                              # push all refs
236
  --atomic                                           # request atomic transaction on remote side
237
  --delete(-d)                                       # delete refs
238
  --dry-run(-n)                                      # dry run
239
  --exec: string                                     # receive pack program
240
  --follow-tags                                      # push missing but relevant tags
241
  --force-with-lease                                 # require old value of ref to be at this value
242
  --force(-f)                                        # force updates
243
  --ipv4(-4)                                         # use IPv4 addresses only
244
  --ipv6(-6)                                         # use IPv6 addresses only
245
  --mirror                                           # mirror all refs
246
  --no-verify                                        # bypass pre-push hook
247
  --porcelain                                        # machine-readable output
248
  --progress                                         # force progress reporting
249
  --prune                                            # prune locally removed refs
250
  --push-option(-o): string                          # option to transmit
251
  --quiet(-q)                                        # be more quiet
252
  --receive-pack: string                             # receive pack program
253
  --recurse-submodules: string                       # control recursive pushing of submodules
254
  --repo: string                                     # repository
255
  --set-upstream(-u)                                 # set upstream for git pull/status
256
  --signed: string                                   # GPG sign the push
257
  --tags                                             # push tags (can't be used with --all or --mirror)
258
  --thin                                             # use thin pack
259
  --verbose(-v)                                      # be more verbose
260
]
261
262
# Pull changes
263
export extern "git pull" [
264
  remote?: string@"nu-complete git remotes",         # the name of the remote
265
  ...refs: string@"nu-complete git local branches",  # the branch / refspec
266
  --rebase(-r): string@"nu-complete git pull rebase",    # rebase current branch on top of upstream after fetching
267
  --quiet(-q)                                        # suppress output during transfer and merge
268
  --verbose(-v)                                      # be more verbose
269
  --commit                                           # perform the merge and commit the result
270
  --no-commit                                        # perform the merge but do not commit the result
271
  --edit(-e)                                         # edit the merge commit message
272
  --no-edit                                          # use the auto-generated merge commit message
273
  --cleanup: string                                  # specify how to clean up the merge commit message
274
  --ff                                               # fast-forward if possible
275
  --no-ff                                            # create a merge commit in all cases
276
  --gpg-sign(-S)                                     # GPG-sign the resulting merge commit
277
  --no-gpg-sign                                      # do not GPG-sign the resulting merge commit
278
  --log: int                                         # include log messages from merged commits
279
  --no-log                                           # do not include log messages from merged commits
280
  --signoff                                          # add Signed-off-by trailer
281
  --no-signoff                                       # do not add Signed-off-by trailer
282
  --stat(-n)                                         # show a diffstat at the end of the merge
283
  --no-stat                                          # do not show a diffstat at the end of the merge
284
  --squash                                           # produce working tree and index state as if a merge happened
285
  --no-squash                                        # perform the merge and commit the result
286
  --verify                                           # run pre-merge and commit-msg hooks
287
  --no-verify                                        # do not run pre-merge and commit-msg hooks
288
  --strategy(-s): string                             # use the given merge strategy
289
  --strategy-option(-X): string                      # pass merge strategy-specific option
290
  --verify-signatures                                # verify the tip commit of the side branch being merged
291
  --no-verify-signatures                             # do not verify the tip commit of the side branch being merged
292
  --summary                                          # show a summary of the merge
293
  --no-summary                                       # do not show a summary of the merge
294
  --autostash                                        # create a temporary stash entry before the operation
295
  --no-autostash                                     # do not create a temporary stash entry before the operation
296
  --allow-unrelated-histories                        # allow merging histories without a common ancestor
297
  --no-rebase                                        # do not rebase the current branch on top of the upstream branch
298
  --all                                              # fetch all remotes
299
  --append(-a)                                       # append fetched refs to existing contents of FETCH_HEAD
300
  --atomic                                           # use an atomic transaction to update local refs
301
  --depth: int                                       # limit fetching to the specified number of commits
302
  --deepen: int                                      # deepen the history by the specified number of commits
303
  --shallow-since: string                            # deepen or shorten the history since a specified date
304
  --shallow-exclude: string                          # exclude commits reachable from a specified branch or tag
305
  --unshallow                                        # convert a shallow repository to a complete one
306
  --update-shallow                                   # update .git/shallow with new refs
307
  --tags(-t)                                         # fetch all tags from the remote
308
  --jobs(-j): int                                    # number of parallel children for fetching
309
  --set-upstream                                     # add upstream (tracking) reference
310
  --upload-pack: string                              # specify non-default path for upload-pack on the remote
311
  --progress                                         # force progress status even if stderr is not a terminal
312
  --server-option(-o): string                        # transmit the given string to the server
313
]
314
315
# Switch between branches and commits
316
export extern "git switch" [
317
  switch?: string@"nu-complete git switch"        # name of branch to switch to
318
  --create(-c)                                    # create a new branch
319
  --detach(-d): string@"nu-complete git log"      # switch to a commit in a detached state
320
  --force-create(-C): string                      # forces creation of new branch, if it exists then the existing branch will be reset to starting point
321
  --force(-f)                                     # alias for --discard-changes
322
  --guess                                         # if there is no local branch which matches then name but there is a remote one then this is checked out
323
  --ignore-other-worktrees                        # switch even if the ref is held by another worktree
324
  --merge(-m)                                     # attempts to merge changes when switching branches if there are local changes
325
  --no-guess                                      # do not attempt to match remote branch names
326
  --no-progress                                   # do not report progress
327
  --no-recurse-submodules                         # do not update the contents of sub-modules
328
  --no-track                                      # do not set "upstream" configuration
329
  --orphan: string                                # create a new orphaned branch
330
  --progress                                      # report progress status
331
  --quiet(-q)                                     # suppress feedback messages
332
  --recurse-submodules                            # update the contents of sub-modules
333
  --track(-t)                                     # set "upstream" configuration
334
]
335
336
# Apply the change introduced by an existing commit
337
export extern "git cherry-pick" [
338
  commit?: string@"nu-complete git commits all" # The commit ID to be cherry-picked
339
  --edit(-e)                                    # Edit the commit message prior to committing
340
  --no-commit(-n)                               # Apply changes without making any commit
341
  --signoff(-s)                                 # Add Signed-off-by line to the commit message
342
  --ff                                          # Fast-forward if possible
343
  --continue                                    # Continue the operation in progress
344
  --abort                                       # Cancel the operation
345
  --skip                                        # Skip the current commit and continue with the rest of the sequence
346
]
347
348
# Rebase the current branch
349
export extern "git rebase" [
350
  branch?: string@"nu-complete git rebase"    # name of the branch to rebase onto
351
  upstream?: string@"nu-complete git rebase"  # upstream branch to compare against
352
  --continue                                  # restart rebasing process after editing/resolving a conflict
353
  --abort                                     # abort rebase and reset HEAD to original branch
354
  --quit                                      # abort rebase but do not reset HEAD
355
  --interactive(-i)                           # rebase interactively with list of commits in editor
356
  --onto?: string@"nu-complete git rebase"    # starting point at which to create the new commits
357
  --root                                      # start rebase from root commit
358
]
359
360
# List or change branches
361
export extern "git branch" [
362
  branch?: string@"nu-complete git local branches"               # name of branch to operate on
363
  --abbrev                                                       # use short commit hash prefixes
364
  --edit-description                                             # open editor to edit branch description
365
  --merged                                                       # list reachable branches
366
  --no-merged                                                    # list unreachable branches
367
  --set-upstream-to: string@"nu-complete git available upstream" # set upstream for branch
368
  --unset-upstream                                               # remote upstream for branch
369
  --all                                                          # list both remote and local branches
370
  --copy                                                         # copy branch together with config and reflog
371
  --format                                                       # specify format for listing branches
372
  --move                                                         # rename branch
373
  --points-at                                                    # list branches that point at an object
374
  --show-current                                                 # print the name of the current branch
375
  --verbose                                                      # show commit and upstream for each branch
376
  --color                                                        # use color in output
377
  --quiet                                                        # suppress messages except errors
378
  --delete(-d)                                                   # delete branch
379
  --list                                                         # list branches
380
  --contains: string@"nu-complete git commits all"               # show only branches that contain the specified commit
381
  --no-contains                                                  # show only branches that don't contain specified commit
382
  --track(-t)                                                    # when creating a branch, set upstream
383
]
384
385
# List or change tracked repositories
386
export extern "git remote" [
387
  --verbose(-v)                            # Show URL for remotes
388
]
389
390
# Add a new tracked repository
391
export extern "git remote add" [
392
]
393
394
# Rename a tracked repository
395
export extern "git remote rename" [
396
  remote: string@"nu-complete git remotes"             # remote to rename
397
  new_name: string                                     # new name for remote
398
]
399
400
# Remove a tracked repository
401
export extern "git remote remove" [
402
  remote: string@"nu-complete git remotes"             # remote to remove
403
]
404
405
# Get the URL for a tracked repository
406
export extern "git remote get-url" [
407
  remote: string@"nu-complete git remotes"             # remote to get URL for
408
]
409
410
# Set the URL for a tracked repository
411
export extern "git remote set-url" [
412
  remote: string@"nu-complete git remotes"             # remote to set URL for
413
  url: string                                          # new URL for remote
414
]
415
416
# Show changes between commits, working tree etc
417
export extern "git diff" [
418
  rev1_or_file?: string@"nu-complete git files-or-refs"
419
  rev2?: string@"nu-complete git refs"
420
  --cached                                             # show staged changes
421
  --name-only                                          # only show names of changed files
422
  --name-status                                        # show changed files and kind of change
423
  --no-color                                           # disable color output
424
]
425
426
# Commit changes
427
export extern "git commit" [
428
  --all(-a)                                           # automatically stage all modified and deleted files
429
  --amend                                             # amend the previous commit rather than adding a new one
430
  --message(-m): string                               # specify the commit message rather than opening an editor
431
  --no-edit                                           # don't edit the commit message (useful with --amend)
432
  --reuse-message(-C): string                         # reuse the message from a previous commit
433
  --reedit-message(-c): string                        # reuse and edit message from a commit
434
  --fixup: string                                     # create a fixup/amend commit
435
  --squash: string                                    # squash commit for autosquash rebase
436
  --reset-author                                      # reset author information
437
  --short                                             # short-format output for dry-run
438
  --branch                                            # show branch info in short-format
439
  --porcelain                                         # porcelain-ready format for dry-run
440
  --long                                              # long-format output for dry-run
441
  --null(-z)                                          # use NUL instead of LF in output
442
  --file(-F): string                                  # read commit message from file
443
  --author: string                                    # override commit author
444
  --date: string                                      # override author date
445
  --template(-t): string                              # use commit message template file
446
  --signoff(-s)                                       # add Signed-off-by trailer
447
  --no-signoff                                        # do not add Signed-off-by trailer
448
  --trailer: string                                   # add trailer to commit message
449
  --no-verify(-n)                                     # bypass pre-commit and commit-msg hooks
450
  --verify                                            # do not bypass pre-commit and commit-msg hooks
451
  --allow-empty                                       # allow commit with no changes
452
  --allow-empty-message                               # allow commit with empty message
453
  --cleanup: string                                   # cleanup commit message
454
  --edit(-e)                                          # edit commit message
455
  --no-edit                                           # do not edit commit message
456
  --include(-i)                                       # include given paths in commit
457
  --only(-o)                                          # commit only specified paths
458
  --pathspec-from-file: string                        # read pathspec from file
459
  --pathspec-file-nul                                 # use NUL character for pathspec file
460
  --untracked-files(-u): string                       # show untracked files
461
  --verbose(-v)                                       # show diff in commit message template
462
  --quiet(-q)                                         # suppress commit summary
463
  --dry-run                                           # show paths to be committed without committing
464
  --status                                            # include git-status output in commit message
465
  --no-status                                         # do not include git-status output
466
  --gpg-sign(-S):string                               # GPG-sign commit
467
  --no-gpg-sign                                       # do not GPG-sign commit
468
  ...pathspec: string                                 # commit files matching pathspec
469
]
470
471
# List commits
472
export extern "git log" [
473
  # Ideally we'd allow completion of revisions here, but that would make completion of filenames not work.
474
  -U                                                  # show diffs
475
  --follow                                            # show history beyond renames (single file only)
476
  --grep: string                                      # show log entries matching supplied regular expression
477
]
478
479
# Show or change the reflog
480
export extern "git reflog" [
481
]
482
483
# Stage files
484
export extern "git add" [
485
  ...file: string@"nu-complete git add"               # file to add
486
  --all(-A)                                           # add all files
487
  --dry-run(-n)                                       # don't actually add the file(s), just show if they exist and/or will be ignored
488
  --edit(-e)                                          # open the diff vs. the index in an editor and let the user edit it
489
  --force(-f)                                         # allow adding otherwise ignored files
490
  --interactive(-i)                                   # add modified contents in the working tree interactively to the index
491
  --patch(-p)                                         # interactively choose hunks to stage
492
  --verbose(-v)                                       # be verbose
493
]
494
495
# Delete file from the working tree and the index
496
export extern "git rm" [
497
  -r                                                   # recursive
498
  --force(-f)                                          # override the up-to-date check
499
  --dry-run(-n)                                        # Don't actually remove any file(s)
500
  --cached                                             # unstage and remove paths only from the index
501
]
502
503
# Show the working tree status
504
export extern "git status" [
505
  --verbose(-v)                                       # be verbose
506
  --short(-s)                                         # show status concisely
507
  --branch(-b)                                        # show branch information
508
  --show-stash                                        # show stash information
509
]
510
511
# Stash changes for later
512
export extern "git stash push" [
513
  --patch(-p)                                         # interactively choose hunks to stash
514
]
515
516
# Unstash previously stashed changes
517
export extern "git stash pop" [
518
  stash?: string@"nu-complete git stash-list"          # stash to pop
519
  --index(-i)                                          # try to reinstate not only the working tree's changes, but also the index's ones
520
]
521
522
# List stashed changes
523
export extern "git stash list" [
524
]
525
526
# Show a stashed change
527
export extern "git stash show" [
528
  stash?: string@"nu-complete git stash-list"
529
  -U                                                  # show diff
530
]
531
532
# Drop a stashed change
533
export extern "git stash drop" [
534
  stash?: string@"nu-complete git stash-list"
535
]
536
537
# Create a new git repository
538
export extern "git init" [
539
  --initial-branch(-b): string                         # initial branch name
540
]
541
542
# List or manipulate tags
543
export extern "git tag" [
544
  --delete(-d): string@"nu-complete git tags"         # delete a tag
545
]
546
547
# Prune all unreachable objects
548
export extern "git prune" [
549
  --dry-run(-n)                                       # dry run
550
  --expire: string                                    # expire objects older than
551
  --progress                                          # show progress
552
  --verbose(-v)                                       # report all removed objects
553
]
554
555
# Start a binary search to find the commit that introduced a bug
556
export extern "git bisect start" [
557
  bad?: string                 # a commit that has the bug
558
  good?: string                # a commit that doesn't have the bug
559
]
560
561
# Mark the current (or specified) revision as bad
562
export extern "git bisect bad" [
563
]
564
565
# Mark the current (or specified) revision as good
566
export extern "git bisect good" [
567
]
568
569
# Skip the current (or specified) revision
570
export extern "git bisect skip" [
571
]
572
573
# End bisection
574
export extern "git bisect reset" [
575
]
576
577
# Show help for a git subcommand
578
export extern "git help" [
579
  command: string@"nu-complete git subcommands"       # subcommand to show help for
580
]
581
582
# git worktree
583
export extern "git worktree" [
584
  --help(-h)            # display the help message for this command
585
  ...args
586
]
587
588
# create a new working tree
589
export extern "git worktree add" [
590
  path: path            # directory to clone the branch
591
  branch: string@"nu-complete git available upstream" # Branch to clone
592
  --help(-h)            # display the help message for this command
593
  --force(-f)           # checkout <branch> even if already checked out in other worktree
594
  -b                    # create a new branch
595
  -B                    # create or reset a branch
596
  --detach(-d)          # detach HEAD at named commit
597
  --checkout            # populate the new working tree
598
  --lock                # keep the new working tree locked
599
  --reason              # reason for locking
600
  --quiet(-q)           # suppress progress reporting
601
  --track               # set up tracking mode (see git-branch(1))
602
  --guess-remote        # try to match the new branch name with a remote-tracking branch
603
  ...args
604
]
605
606
# list details of each worktree
607
export extern "git worktree list" [
608
  --help(-h)            # display the help message for this command
609
  --porcelain           # machine-readable output
610
  --verbose(-v)         # show extended annotations and reasons, if available
611
  --expire              # add 'prunable' annotation to worktrees older than <time>
612
  -z                    # terminate records with a NUL character
613
  ...args
614
]
615
616
def "nu-complete worktree list" [] {
617
  ^git worktree list | to text | parse --regex '(?P<value>\S+)\s+(?P<commit>\w+)\s+(?P<description>\S.*)'
618
}
619
620
# prevent a working tree from being pruned
621
export extern "git worktree lock" [
622
  worktree: string@"nu-complete worktree list"
623
  --reason: string      # reason because the tree is locked
624
  --help(-h)            # display the help message for this command
625
  --reason              # reason for locking
626
  ...args
627
]
628
629
# move a working tree to a new location
630
export extern "git worktree move" [
631
  --help(-h)            # display the help message for this command
632
  --force(-f)           # force move even if worktree is dirty or locked
633
  ...args
634
]
635
636
# prune working tree information
637
export extern "git worktree prune" [
638
  --help(-h)            # display the help message for this command
639
  --dry-run(-n)         # do not remove, show only
640
  --verbose(-v)         # report pruned working trees
641
  --expire              # expire working trees older than <time>
642
  ...args
643
]
644
645
# remove a working tree
646
export extern "git worktree remove" [
647
  worktree: string@"nu-complete worktree list"
648
  --help(-h)            # display the help message for this command
649
  --force(-f)           # force removal even if worktree is dirty or locked
650
]
651
652
# allow working tree to be pruned, moved or deleted
653
export extern "git worktree unlock" [
654
  worktree: string@"nu-complete worktree list"
655
  ...args
656
]
657
658
# clones a repo
659
export extern "git clone" [
660
  --help(-h)                    # display the help message for this command
661
  --local(-l)                   # cloning from the local machine
662
  --no-local                    # use the git transport mechanism even if cloning from a local path
663
  --no-hardlinks                # force git to copy files when cloning from the local machine
664
  --shared(-s)                  # setup .git/objects/info/alternates to share objects with the source local repo
665
  --reference: string           # setup .git/objects/info/alternates to share objects with the =<reference> local repo
666
  --reference-if-able: string   # same as --reference, but skips empty folders
667
  --dissociate                  # borrow objects from the referenced repo (--reference)
668
  --quiet(-q)                   # suppress progress reporting
669
  --verbose(-v)                 # be verbose
670
  --progress                    # report progress unless --quiet
671
  --server-option: string       # transmit the =<option> to the server
672
  --no-checkout(-n)             # no checkout of HEAD
673
  --reject-shallow              # reject shallow repository as source
674
  --no-reject-shallow           # do not reject shallow repository as source
675
  --bare                        # make a bare git repo
676
  --sparse                      # initialize the sparse-checkout file
677
  --filter: string              # partial clone using the given =<filter-spec>
678
  --mirror                      # mirror the source repo
679
  --origin(-o): string          # use <name> as the name for the remote origin
680
  --branch(-b): string          # point HEAD to <name> branch
681
  --upload-pack(-u): string     # use <upload-pack> as the path in the other end when using ssh
682
  --template: string            # use <template-dir> as the templates directory
683
  --config(-c): string          # set a <key>=<value> config variable
684
  --depth: int                  # shallow clone <depth> commits
685
  --shallow-since: string       # shallow clone commits newer than =<date>
686
  --shallow-exclude: string     # do not clone commits reachable from <revision> (branch or tag)
687
  --single-branch               # clone commit history from a single branch
688
  --no-single-Branch            # do not clone only one branch
689
  --no-tags                     # do not clone any tags
690
  --recurse-submodules: string  # clone the submodules
691
  --shallow-submodules          # shallow clone submodules with depth 1
692
  --no-shallow-submodules       # do not shallow clone submodules
693
  --remote-submodules           # submodules are updating using their remote tracking branch
694
  --no-remote-submodules        # do not track submodules remote
695
  --separate-git-dir: string    # place the clone at =<git dir> and link it here
696
  --jobs(-j): int               # number of simultaneous submodules fetch
697
  ...args
698
]
699
700
# Restores files in working tree or index to previous versions
701
export extern "git restore" [
702
  --help(-h)                                    # Display the help message for this command
703
  --source(-s)                                  # Restore the working tree files with the content from the given tree
704
  --patch(-p)                                   # Interactively choose hunks to restore
705
  --worktree(-W)                                # Restore working tree (default if neither --worktree or --staged is used)
706
  --staged(-S)                                  # Restore index
707
  --quiet(-q)                                   # Quiet, suppress feedback messages
708
  --progress                                    # Force progress reporting
709
  --no-progress                                 # Suppress progress reporting
710
  --ours                                        # Restore from index using our version for unmerged files
711
  --theirs                                      # Restore from index using their version for unmerged files
712
  --merge(-m)                                   # Restore from index and recreate the conflicted merge in unmerged files
713
  --conflict: string                            # Like --merge but changes the conflict presentation with =<style>
714
  --ignore-unmerged                             # Restore from index and ignore unmerged entries (unmerged files are left as is)
715
  --ignore-skip-worktree-bits                   # Ignore sparse checkout patterns and unconditionally restores any files in <pathspec>
716
  --recurse-submodules                          # Restore the contents of sub-modules in working tree
717
  --no-recurse-submodules                       # Do not restore the contents of sub-modules in working tree (default)
718
  --overlay                                     # Do not remove files that don't exist when restoring from tree with --source
719
  --no-overlay                                  # Remove files that don't exist when restoring from tree with --source (default)
720
  --pathspec-from-file: string                  # Read pathspec from file
721
  --pathspec-file-nul                           # Separate pathspec elements with NUL character when reading from file
722
  ...pathspecs: string@"nu-complete git files"  # Target pathspecs to restore
723
]
724
725
# Print lines matching a pattern
726
export extern "git grep" [
727
  --help(-h)                            # Display the help message for this command
728
  --cached                              # Search blobs registered in the index file instead of worktree
729
  --untracked                           # Include untracked files in search
730
  --no-index                            # Similar to `grep -r`, but with additional benefits, such as using pathspec patterns to limit paths; Cannot be used together with --cached or --untracked
731
  --no-exclude-standard                 # Include ignored files in search (only useful with --untracked)
732
  --exclude-standard                    # No not include ignored files in search (only useful with --no-index)
733
  --recurse-submodules                  # Recursively search in each submodule that is active and checked out
734
  --text(-a)                            # Process binary files as if they were text
735
  --textconv                            # Honor textconv filter settings
736
  --no-textconv                         # Do not honor textconv filter settings (default)
737
  --ignore-case(-i)                     # Ignore case differences between patterns and files
738
  -I                                    # Don’t match the pattern in binary files
739
  --max-depth: int                      # Max <depth> to descend down directories for each pathspec. A value of -1 means no limit.
740
  --recursive(-r)                       # Same as --max-depth=-1
741
  --no-recursive                        # Same as --max-depth=0
742
  --word-regexp(-w)                     # Match the pattern only at word boundary
743
  --invert-match(-v)                    # Select non-matching lines
744
  -H                                    # Suppress filename in output of matched lines
745
  --full-name                           # Force relative path to filename from top directory
746
  --extended-regexp(-E)                 # Use POSIX extended regexp for patterns
747
  --basic-regexp(-G)                    # Use POSIX basic regexp for patterns (default)
748
  --perl-regexp(-P)                     # Use Perl-compatible regular expressions for patterns
749
  --line-number(-n)                     # Prefix the line number to matching lines
750
  --column                              # Prefix the 1-indexed byte-offset of the first match from the start of the matching line
751
  --files-with-matches(-l)              # Print filenames of files that contains matches
752
  --name-only                           # Same as --files-with-matches
753
  --files-without-match(-L)             # Print filenames of files that do not contain matches
754
  --null(-z)                            # Use \0 as the delimiter for pathnames in the output, and print them verbatim
755
  --only-matching(-o)                   # Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line
756
  --count(-c)                           # Instead of showing every matched line, show the number of lines that match
757
  --no-color                            # Same as --color=never
758
  --break                               # Print an empty line between matches from different files.
759
  --heading                             # Show the filename above the matches in that file instead of at the start of each shown line.
760
  --show-function(-p)                   # Show the preceding line that contains the function name of the match, unless the matching line is a function name itself.
761
  --context(-C): int                    # Show <num> leading and trailing lines, and place a line containing -- between contiguous groups of matches.
762
  --after-context(-A): int              # Show <num> trailing lines, and place a line containing -- between contiguous groups of matches.
763
  --before-context(-B): int             # Show <num> leading lines, and place a line containing -- between contiguous groups of matches.
764
  --function-context(-W)                # Show the surrounding text from the previous line containing a function name up to the one before the next function name
765
  --max-count(-m): int                  # Limit the amount of matches per file. When using the -v or --invert-match option, the search stops after the specified number of non-matches.
766
  --threads: int                        # Number of grep worker threads to use. Use --help for more information on grep threads.
767
  -f: string                            # Read patterns from <file>, one per line.
768
  -e: string                            # Next parameter is the pattern. Multiple patterns are combined by --or.
769
  --and                                 # Search for lines that match multiple patterns.
770
  --or                                  # Search for lines that match at least one of multiple patterns. --or is implied between patterns without --and or --not.
771
  --not                                 # Search for lines that does not match pattern.
772
  --all-match                           # When giving multiple pattern expressions combined with --or, this flag is specified to limit the match to files that have lines to match all of them.
773
  --quiet(-q)                           # Do not output matched lines; instead, exit with status 0 when there is a match and with non-zero status when there isn’t.
774
  ...pathspecs: string                  # Target pathspecs to limit the scope of the search.
775
]