Skip to content

Commit c850839

Browse files
authored
Autocomplete for "git merge". (#1048)
Just support most often-used options and flags, though. ![image](https://github.com/user-attachments/assets/e9d411b7-6665-4796-bd7e-f06a80d06b73) ![image](https://github.com/user-attachments/assets/780482af-0022-4c16-9ffa-bc78a041c2de)
1 parent 07050f8 commit c850839

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

custom-completions/git/git-completions.nu

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ def "nu-complete git remote branches nonlocal without prefix" [] {
4343
^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 }
4444
}
4545

46+
# Yield local and remote branch names which can be passed to `git merge`
47+
def "nu-complete git mergable sources" [] {
48+
let current = (^git branch --show-current)
49+
let long_current = $'origin/($current)'
50+
let git_table = ^git branch -a --format '%(refname:lstrip=2)%09%(upstream:lstrip=2)' | lines | str trim | where { ($in != $long_current) and not ($in starts-with $"($current)\t") and not ($in ends-with 'HEAD') } | each {|v| if "\t" in $v { $v | split row "\t" -n 2 | {'n': $in.0, 'u': $in.1 } } else {'n': $v, 'u': null } }
51+
let siblings = $git_table | where u == null and n starts-with 'origin/' | get n | str substring 7..
52+
let remote_branches = $git_table | filter {|r| $r.u == null and not ($r.n starts-with 'origin/') } | get n
53+
[...($siblings | wrap value | insert description Local), ...($remote_branches | wrap value | insert description Remote)]
54+
}
55+
4656
def "nu-complete git switch" [] {
4757
(nu-complete git local branches)
4858
| parse "{value}"
@@ -163,6 +173,14 @@ def "nu-complete git pull rebase" [] {
163173
["false","true","merges","interactive"]
164174
}
165175

176+
def "nu-complete git merge strategies" [] {
177+
['ort', 'octopus']
178+
}
179+
180+
def "nu-complete git merge strategy options" [] {
181+
['ours', 'theirs']
182+
}
183+
166184

167185
# Check out git branches and files
168186
export extern "git checkout" [
@@ -383,6 +401,24 @@ export extern "git rebase" [
383401
--root # start rebase from root commit
384402
]
385403

404+
# Merge from a branch
405+
export extern "git merge" [
406+
# For now, to make it simple, we only complete branches (not commits) and support single-parent case.
407+
branch?: string@"nu-complete git mergable sources" # The source branch
408+
--edit(-e) # Edit the commit message prior to committing
409+
--no-edit # Do not edit commit message
410+
--no-commit(-n) # Apply changes without making any commit
411+
--signoff # Add Signed-off-by line to the commit message
412+
--ff # Fast-forward if possible
413+
--continue # Continue after resolving a conflict
414+
--abort # Abort resolving conflict and go back to original state
415+
--quit # Forget about the current merge in progress
416+
--strategy(-s): string@"nu-complete git merge strategies" # Merge strategy
417+
-X: string@"nu-complete git merge strategy options" # Option for merge strategy
418+
--verbose(-v)
419+
--help
420+
]
421+
386422
# List or change branches
387423
export extern "git branch" [
388424
branch?: string@"nu-complete git local branches" # name of branch to operate on
@@ -800,5 +836,5 @@ export extern "git grep" [
800836
]
801837

802838
export extern "git" [
803-
command?: string@"nu-complete git subcommands" # subcommand to show help for
839+
command?: string@"nu-complete git subcommands" # subcommands
804840
]

0 commit comments

Comments
 (0)