Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion custom-completions/git/git-completions.nu
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ def "nu-complete git remote branches nonlocal without prefix" [] {
^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 }
}

# Yield local and remote branch names which can be passed to `git merge`
def "nu-complete git mergable sources" [] {
let current = (^git branch --show-current)
let long_current = $'origin/($current)'
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 } }
let siblings = $git_table | where u == null and n starts-with 'origin/' | get n | str substring 7..
let remote_branches = $git_table | filter {|r| $r.u == null and not ($r.n starts-with 'origin/') } | get n
[...($siblings | wrap value | insert description Local), ...($remote_branches | wrap value | insert description Remote)]
}

def "nu-complete git switch" [] {
(nu-complete git local branches)
| parse "{value}"
Expand Down Expand Up @@ -163,6 +173,14 @@ def "nu-complete git pull rebase" [] {
["false","true","merges","interactive"]
}

def "nu-complete git merge strategies" [] {
['ort', 'octopus']
}

def "nu-complete git merge strategy options" [] {
['ours', 'theirs']
}


# Check out git branches and files
export extern "git checkout" [
Expand Down Expand Up @@ -383,6 +401,24 @@ export extern "git rebase" [
--root # start rebase from root commit
]

# Merge from a branch
export extern "git merge" [
# For now, to make it simple, we only complete branches (not commits) and support single-parent case.
branch?: string@"nu-complete git mergable sources" # The source branch
--edit(-e) # Edit the commit message prior to committing
--no-edit # Do not edit commit message
--no-commit(-n) # Apply changes without making any commit
--signoff # Add Signed-off-by line to the commit message
--ff # Fast-forward if possible
--continue # Continue after resolving a conflict
--abort # Abort resolving conflict and go back to original state
--quit # Forget about the current merge in progress
--strategy(-s): string@"nu-complete git merge strategies" # Merge strategy
-X: string@"nu-complete git merge strategy options" # Option for merge strategy
--verbose(-v)
--help
]

# List or change branches
export extern "git branch" [
branch?: string@"nu-complete git local branches" # name of branch to operate on
Expand Down Expand Up @@ -800,5 +836,5 @@ export extern "git grep" [
]

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