From 097dedf9ab549902d31e286a429b41246d5e2fbd Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sat, 7 Mar 2015 02:05:44 +0000 Subject: 34671: git completion: only offer recent commits' tags/heads for --fixup --- Completion/Unix/Command/_git | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'Completion') 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' -- cgit 1.4.1