@@ -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+
4656def "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
168186export 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
387423export 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
802838export 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