about summary refs log tree commit diff
path: root/Completion/Unix/Command
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2015-03-07 02:05:44 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2015-03-16 09:25:39 +0000
commit097dedf9ab549902d31e286a429b41246d5e2fbd (patch)
treecbc4dcef01ea438285c45a4ef3d8f944686754f1 /Completion/Unix/Command
parent7e994fe145cd5beaadf8719468bbd682c17512b5 (diff)
downloadzsh-097dedf9ab549902d31e286a429b41246d5e2fbd.tar.gz
zsh-097dedf9ab549902d31e286a429b41246d5e2fbd.tar.xz
zsh-097dedf9ab549902d31e286a429b41246d5e2fbd.zip
34671: git completion: only offer recent commits' tags/heads for --fixup
Diffstat (limited to 'Completion/Unix/Command')
-rw-r--r--Completion/Unix/Command/_git36
1 files changed, 34 insertions, 2 deletions
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 58d642216..aa1124706 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -647,8 +647,8 @@ _git-commit () {
   # TODO: --interactive isn't explicitly listed in the documentation.
   _arguments -w -S -s \
     '(-a --all --interactive -o --only -i --include *)'{-a,--all}'[stage all modified and deleted paths]' \
-    '--fixup=[construct a commit message for use with rebase --autosquash]:commit to be amended:__git_commits' \
-    '--squash=[construct a commit message for use with rebase --autosquash]:commit to be amended:__git_commits' \
+    '--fixup=[construct a commit message for use with rebase --autosquash]:commit to be amended:__git_recent_commits' \
+    '--squash=[construct a commit message for use with rebase --autosquash]:commit to be amended:__git_recent_commits' \
     $reset_author_opt \
     '(        --porcelain --dry-run)--short[output dry run in short format]' \
     '(--short             --dry-run)--porcelain[output dry run in porcelain-ready format]' \
@@ -5640,6 +5640,38 @@ __git_commit_objects () {
   _describe -t commits 'commit object name' commits
 }
 
+(( $+functions[__git_recent_commits] )) ||
+__git_recent_commits () {
+  local gitdir expl start
+  declare -a descr tags heads commits
+  local i j k
+
+  # Careful: most %d will expand to the empty string.  Quote properly!
+  : "${(A)commits::=${(@f)"$(_call_program commits git --no-pager log -20 --format='%h%n%d%n%s')"}}"
+  __git_command_successful $pipestatus || return 1
+
+  for i j k in "$commits[@]" ; do
+    descr+=($i:$k)
+    j=${${j# \(}%\)} # strip leading ' (' and trailing ')'
+    for j in ${(s:, :)j}; do
+      if [[ $j == 'tag: '* ]] ; then
+        tags+=( ${j#tag: } )
+      else
+        heads+=( $j )
+      fi
+    done
+  done
+
+  ret=1
+  # Resetting expl to avoid it 'leaking' from one line to the next.
+  expl=()
+  _wanted commit-tags expl 'commit tag' compadd "$@" -a - tags && ret=0
+  expl=()
+  _wanted heads expl 'head' compadd "$@" -a - heads && ret=0
+  expl=()
+  _describe -t commits 'commit object name' descr && ret=0
+}
+
 (( $+functions[__git_blob_objects] )) ||
 __git_blob_objects () {
   _guard '[[:xdigit:]](#c,40)' 'blob object name'