about summary refs log tree commit diff
path: root/Completion/Unix/Command/_git
diff options
context:
space:
mode:
authorJordan Klassen <jordan@klassen.me.uk>2016-07-05 23:22:11 +0200
committerOliver Kiddle <opk@zsh.org>2016-07-05 23:29:40 +0200
commit92d516cfa7686b58ba7731b942766e706cae29ae (patch)
tree7d40ce5ddede40d0e02c1b7d2dd9a7ac51a77cce /Completion/Unix/Command/_git
parent8468f24af48154e01869d5998160eb3903ad0e43 (diff)
downloadzsh-92d516cfa7686b58ba7731b942766e706cae29ae.tar.gz
zsh-92d516cfa7686b58ba7731b942766e706cae29ae.tar.xz
zsh-92d516cfa7686b58ba7731b942766e706cae29ae.zip
users/21551 (tweaked per users/21560): new git subtree completion
Diffstat (limited to 'Completion/Unix/Command/_git')
-rw-r--r--Completion/Unix/Command/_git92
1 files changed, 92 insertions, 0 deletions
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 739fff1db..73273ad43 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -1747,6 +1747,91 @@ _git-submodule () {
   return ret
 }
 
+(( $+functions[_git-subtree] )) ||
+_git-subtree () {
+  local curcontext="$curcontext" state state_descr line ret=1
+  declare -A opt_args
+
+  # TODO: -P should only complete paths inside the current repository.
+  _arguments -C \
+    '(-q --quiet)'{-q,--quiet}'[suppress progress output]' \
+    '(-P --prefix)'{-P,--prefix=}'[the path to the subtree in the repository to manipulate]: :_directories' \
+    '-d[show debug messages]' \
+    ': :->command' \
+    '*::: := ->option-or-argument' && ret=0
+
+  case $state in
+    (command)
+      declare -a commands
+
+      commands=(
+        add:'create the subtree by importing its contents'
+        merge:'merge recent changes up to specified commit into the subtree'
+        pull:'fetch from remote repository and merge recent changes into the subtree'
+        push:'does a split and `git push`'
+        split:'extract a new synthetic project history from a subtree')
+
+      _describe -t commands command commands && ret=0
+    ;;
+    (option-or-argument)
+      curcontext=${curcontext%:*}-$line[1]:
+      case $line[1] in
+        (add)
+          _arguments \
+            '(-q --quiet)'{-q,--quiet}'[suppress progress output]' \
+            '(-m --message)'{-m,--message}'[use the given message as the commit message for the merge commit]' \
+            '(-P --prefix)'{-P,--prefix=}'[the path to the subtree in the repository to manipulate]: :_directories' \
+            '--squash[import only a single commit from the subproject]' \
+            ': :__git_any_repositories_or_references' \
+            ':: :__git_ref_specs' && ret=0
+	;;
+        (merge)
+          _arguments -S \
+            '(-q --quiet)'{-q,--quiet}'[suppress progress output]' \
+            '(-P --prefix)'{-P,--prefix=}'[the path to the subtree in the repository to manipulate]: :_directories' \
+            '(-m --message)'{-m,--message}'[use the given message as the commit message for the merge commit]' \
+            '--squash[import only a single commit from the subproject]' \
+            ': :__git_references' && ret=0
+	;;
+        (pull)
+          _arguments -S \
+            '(-q --quiet)'{-q,--quiet}'[suppress progress output]' \
+            '(-P --prefix)'{-P,--prefix=}'[the path to the subtree in the repository to manipulate]: :_directories' \
+            '(-m --message)'{-m,--message}'[use the given message as the commit message for the merge commit]' \
+            '--squash[import only a single commit from the subproject]' \
+            ': :__git_any_repositories' \
+            ':: :__git_ref_specs' && ret=0
+	;;
+        (push)
+          _arguments -S \
+            '(-q --quiet)'{-q,--quiet}'[suppress progress output]' \
+            '(-P --prefix)'{-P,--prefix=}'[the path to the subtree in the repository to manipulate]: :_directories' \
+            '(-m --message)'{-m,--message}'[use the given message as the commit message for the merge commit]' \
+            ': :__git_any_repositories' \
+            ':: :__git_ref_specs' && ret=0
+	;;
+        (split)
+          _arguments -S \
+            '(-q --quiet)'{-q,--quiet}'[suppress progress output]' \
+            '(-P --prefix)'{-P,--prefix=}'[the path to the subtree in the repository to manipulate]: :_directories' \
+            '(-b --branch)'{-b,--branch=}'[create a new branch]' \
+            '--onto=[try connecting new tree to an existing one]: :__git_ref_specs' \
+            '(-m --message)'{-m,--message}'[use the given message as the commit message for the merge commit]' \
+            '--ignore-joins[ignore prior --rejoin commits]' \
+            '--onto=[try connecting new tree to an existing one]: :__git_ref_specs' \
+            '--rejoin[use the given message as the commit message for the merge commit]' \
+            '*: :__git_references' && ret=0
+	;;
+        (*)
+          _default && ret=0
+	;;
+      esac
+    ;;
+  esac
+
+  return ret
+}
+
 (( $+functions[_git-tag] )) ||
 _git-tag () {
   local -a message_opts
@@ -6274,6 +6359,13 @@ __git_any_repositories () {
     'remote-repositories::__git_remote_repositories'
 }
 
+(( $+functions[__git_any_repositories_or_references] )) ||
+__git_any_repositories_or_references () {
+  _alternative \
+    'repositories::__git_any_repositories' \
+    'references::__git_references'
+}
+
 # Common Guards
 
 (( $+functions[__git_guard] )) ||