From eea3bd5fc3717bb81cff39082d42ea4d97c50108 Mon Sep 17 00:00:00 2001
From: Johannes Altmanninger <aclopte@gmail.com>
Date: Tue, 10 Sep 2019 08:51:59 +0200
Subject: [PATCH] completions/git: improve completion for git restore and git
 switch

- suggest relevant files for git restore
- add `-r` to require an argument for some options
---
 share/completions/git.fish | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/share/completions/git.fish b/share/completions/git.fish
index e9bb6be7a..01f1b3049 100644
--- a/share/completions/git.fish
+++ b/share/completions/git.fish
@@ -1448,7 +1448,7 @@ complete -f -c git -n '__fish_git_using_command reset; and not contains -- -- (c
 ### restore and switch
 # restore options
 complete -f -c git -n '__fish_git_needs_command' -a restore -d 'Restore working tree files'
-complete -f -c git -n '__fish_git_using_command restore' -s s -l source -d 'Specify the source tree used to restore the working tree'
+complete -f -c git -n '__fish_git_using_command restore' -r -s s -l source -d 'Specify the source tree used to restore the working tree' -a '(__fish_git_refs)'
 complete -f -c git -n '__fish_git_using_command restore' -s p -l patch -d 'Interactive mode'
 complete -f -c git -n '__fish_git_using_command restore' -s W -l worktree -d 'Restore working tree (default)'
 complete -f -c git -n '__fish_git_using_command restore' -s S -l staged -d 'Restore the index'
@@ -1459,11 +1459,14 @@ complete -f -c git -n '__fish_git_using_command restore' -l ignore-unmerged -d '
 complete -f -c git -n '__fish_git_using_command restore' -l ignore-skip-worktree-bits -d 'Ignore the sparse-checkout file and unconditionally restore any files in <pathspec>'
 complete -f -c git -n '__fish_git_using_command restore' -l overlay -d 'Never remove files when restoring'
 complete -f -c git -n '__fish_git_using_command restore' -l no-overlay -d 'Remove files when restoring (default)'
+complete -f -c git -n '__fish_git_using_command restore' -a '(__fish_git_files modified deleted unmerged)'
+complete -f -c git -n '__fish_git_using_command restore; and contains -- --staged (commandline -op)' -a '(__fish_git_files added modified-staged deleted-staged renamed copied)'
+complete -f -c git -n '__fish_git_using_command restore; and __fish_contains_opt -s s source' -a '(git ls-files)'
 # switch options
 complete -f -c git -n '__fish_git_needs_command' -a switch -d 'Switch to a branch'
-complete -k -f -c git -n '__fish_git_using_command switch; and not contains -- -- (commandline -op)' -a '(__fish_git_branches)'
-complete -f -c git -n '__fish_git_using_command switch' -s c -l create -d 'Create a new branch'
-complete -f -c git -n '__fish_git_using_command switch' -s C -l force-create -d 'Force create a new branch'
+complete -k -f -c git -n '__fish_git_using_command switch' -a '(__fish_git_branches)'
+complete -f -c git -n '__fish_git_using_command switch' -r -s c -l create -d 'Create a new branch'
+complete -f -c git -n '__fish_git_using_command switch' -r -s C -l force-create -d 'Force create a new branch'
 complete -f -c git -n '__fish_git_using_command switch' -s d -l detach -d 'Switch to a commit for inspection and discardable experiment'
 complete -f -c git -n '__fish_git_using_command switch' -l guess -d 'Guess branch name from remote branch (default)'
 complete -f -c git -n '__fish_git_using_command switch' -l no-guess -d 'Do not guess branch name from remote branch'
@@ -1471,7 +1474,7 @@ complete -f -c git -n '__fish_git_using_command switch' -s f -l force -l discard
 complete -f -c git -n '__fish_git_using_command switch' -s m -l merge -d 'Merge the current branch and contents of the working tree into a new branch'
 complete -f -c git -n '__fish_git_using_command switch' -s t -l track -d 'Track remote branch when creating a new branch'
 complete -f -c git -n '__fish_git_using_command switch' -l no-track -d 'Do not track remote branch when creating a new branch'
-complete -f -c git -n '__fish_git_using_command switch' -l orphan -d 'Create a new orphan branch'
+complete -f -c git -n '__fish_git_using_command switch' -r -l orphan -d 'Create a new orphan branch'
 complete -f -c git -n '__fish_git_using_command switch' -l ignore-other-worktrees -d 'Force check out of the reference'
 complete -f -c git -n '__fish_git_using_command switch' -l recurse-submodules -d 'Update the work trees of submodules'
 complete -f -c git -n '__fish_git_using_command switch' -l no-recurse-submodules -d 'Do not update the work trees of submodules'