1
+ # This does not include remote branches in any form.
2
+ # Accepted at:
3
+ # `git checkout <branch>`
4
+ # `git switch <branch>`
5
+ # `git rebase --onto <branch> <branch>`
1
6
def "nu-complete git branches" [] {
2
7
^ git branch | lines | each { |line | $line | str replace ' \* ' " " | str trim }
3
8
}
4
9
10
+ # This includes remote branches without remote prefix, which will be created
11
+ # locally if switched to.
12
+ # Accepted at:
13
+ # `git checkout <branch>`
14
+ # `git switch <branch>`
5
15
def "nu-complete git switchable branches" [] {
6
- let remotes_regex = ([" (" , ((nu-complete git remotes | each {|r | [' remotes/' , $r , ' /' ] | str join }) | str join " |" ), " )" ] | str join )
7
- ^ git branch - a
8
- | lines
9
- | parse - r ([' ^[\* ]+' , $remotes_regex , ' ?(?P<branch>\S+)' ] | flatten | str join )
10
- | get branch
11
- | uniq
12
- | where {|branch | $branch != " HEAD" }
16
+ let remotes_regex = ([" (" , ((nu-complete git remotes | each {|r | [' remotes/' , $r , ' /' ] | str join }) | str join " |" ), " )" ] | str join )
17
+ ^ git branch - a
18
+ | lines
19
+ | parse - r ([' ^[\* ]+' , $remotes_regex , ' ?(?P<branch>\S+)' ] | flatten | str join )
20
+ | get branch
21
+ | uniq
22
+ | where {|branch | $branch != " HEAD" }
23
+ }
24
+
25
+ # This includes remote branches with remote prefix.
26
+ # Accepted at:
27
+ # `git checkout <branch>`
28
+ # `git rebase --onto <branch> <branch>`
29
+ def "nu-complete git local and remote branches" [] {
30
+ ^ git branch
31
+ | lines
32
+ | parse - r ' \*?\s*(?P<branch>\S+)'
33
+ | get branch
34
+ | append (^ git branch - r | lines | parse - r ' ^\*?(\s*|\s*\S* -> )(?P<branch>\S*$)' | get branch | uniq )
13
35
}
14
36
15
37
def "nu-complete git remotes" [] {
@@ -24,37 +46,41 @@ def "nu-complete git commits" [] {
24
46
^ git rev-list -- all -- remotes -- pretty=oneline | lines | parse " {value} {description}"
25
47
}
26
48
49
+ # This includes local branches, remote branches with remote prefix and commits.
50
+ # Accepted at:
51
+ # `git checkout <value>`
52
+ # `git rebase --onto <value> <value>`
27
53
def "nu-complete git branches and commits" [] {
28
- nu-complete git switchable branches
54
+ nu-complete git local and remote branches
29
55
| parse " {value}"
30
56
| insert description Branch
31
57
| append (nu-complete git commits )
32
58
}
33
59
34
60
# Check out git branches and files
35
61
export extern "git checkout" [
36
- ... targets : string @" nu-complete git switchable branches" # name of the branch or files to checkout
37
- -- conflict : string # conflict style (merge or diff3)
38
- -- detach(-d) # detach HEAD at named commit
39
- -- force(-f) # force checkout (throw away local modifications)
40
- -- guess # second guess 'git checkout <no-such-branch>' (default)
41
- -- ignore-other-worktrees # do not check if another worktree is holding the given ref
42
- -- ignore-skip-worktree-bits # do not limit pathspecs to sparse entries only
43
- -- merge(-m) # perform a 3-way merge with the new branch
44
- -- orphan : string # new unparented branch
45
- -- ours(-2) # checkout our version for unmerged files
46
- -- overlay # use overlay mode (default)
47
- -- overwrite-ignore # update ignored files (default)
48
- -- patch(-p) # select hunks interactively
49
- -- pathspec-from-file : string # read pathspec from file
50
- -- progress # force progress reporting
51
- -- quiet(-q) # suppress progress reporting
52
- -- recurse-submodules : string # control recursive updating of submodules
53
- -- theirs(-3) # checkout their version for unmerged files
54
- -- track(-t) # set upstream info for new branch
55
- - b : string # create and checkout a new branch
56
- - B : string # create/reset and checkout a branch
57
- - l # create reflog for new branch
62
+ ... targets : string @" nu-complete git local and remote branches" # name of the branch or files to checkout
63
+ -- conflict : string # conflict style (merge or diff3)
64
+ -- detach(-d) # detach HEAD at named commit
65
+ -- force(-f) # force checkout (throw away local modifications)
66
+ -- guess # second guess 'git checkout <no-such-branch>' (default)
67
+ -- ignore-other-worktrees # do not check if another worktree is holding the given ref
68
+ -- ignore-skip-worktree-bits # do not limit pathspecs to sparse entries only
69
+ -- merge(-m) # perform a 3-way merge with the new branch
70
+ -- orphan : string # new unparented branch
71
+ -- ours(-2) # checkout our version for unmerged files
72
+ -- overlay # use overlay mode (default)
73
+ -- overwrite-ignore # update ignored files (default)
74
+ -- patch(-p) # select hunks interactively
75
+ -- pathspec-from-file : string # read pathspec from file
76
+ -- progress # force progress reporting
77
+ -- quiet(-q) # suppress progress reporting
78
+ -- recurse-submodules : string # control recursive updating of submodules
79
+ -- theirs(-3) # checkout their version for unmerged files
80
+ -- track(-t) # set upstream info for new branch
81
+ - b : string # create and checkout a new branch
82
+ - B : string # create/reset and checkout a branch
83
+ - l # create reflog for new branch
58
84
]
59
85
60
86
# Download objects and refs from another repository
0 commit comments