zsh-workers
 help / color / mirror / code / Atom feed
* Improved completion for git commit objects (__git_commit_objects)
@ 2015-03-03 23:46 Daniel Hahler
  2015-03-04  2:40 ` Daniel Shahaf
  2015-03-07  4:01 ` Daniel Shahaf
  0 siblings, 2 replies; 7+ messages in thread
From: Daniel Hahler @ 2015-03-03 23:46 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 3101 bytes --]

Hi,

I am trying to improve completion for Git commit objects.

__git_commit_objects is defined as follows (in Completion/Unix/Command/_git):

    __git_commit_objects () {
      _guard '[[:xdigit:]](#c,40)' 'commit object name'
    }

I think it would be great if it actually (optionally?) could provide
completion for commit objects, maybe only on second invocation / as fallback.

I am not sure what to use for completion here, but having completion of the
(shortened) hashes, with more information (subject of the commit) in the
description would be nice!
E.g., using the output from "git --no-pager log --oneline -20 --format='%h%n%s'"


I've experimented a bit with this:

First, I've also added __git_commits to _git-commit where relevant:

diff --git i/Completion/Unix/Command/_git w/Completion/Unix/Command/_git
index 9552780..0bfa057 100644
--- i/Completion/Unix/Command/_git
+++ w/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:' \
-    '--squash=[construct a commit message for use with rebase --autosquash]:commit to be amended:' \
+    '--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' \
     $reset_author_opt \
     '(        --porcelain --dry-run)--short[output dry run in short format]' \
     '(--short             --dry-run)--porcelain[output dry run in porcelain-ready format]' \


And then this (very much WIP):

@@ -5631,7 +5631,23 @@ __git_heads () {
 
 (( $+functions[__git_commit_objects] )) ||
 __git_commit_objects () {
+  local gitdir expl start
+  declare -A commits
+
+  # local -a logs
+  # logs=(${(f)"$(git --no-pager log --oneline -20)"})
+  # __git_command_successful $pipestatus || return 1
+  #
+  # for l in $logs; do
+  #   commits[${l%% *}]=${l#* }
+  # done
+
   _guard '[[:xdigit:]](#c,40)' 'commit object name'
+
+  : ${(AA)commits::=${(f)"$(_call_program commits git --no-pager log --oneline -2 --format='%h%n%s')"}}
+  __git_command_successful $pipestatus || return 1
+
+  _wanted commits expl 'commit object name' compadd "$@" -k - commits && ret=0
 }

I do not fully understand how "_guard" is meant to be used - I need to comment/remove it.
Should this get chained, e.g. with "_wanted", instead?
 

As for using the commit objects in the completion, I would not like to have then for
"git checkout <tab>" by default, but with "git commit --fixup=".
With "git checkout", any partial matching commit objects should be completed though,
and the list would be useful to have on second "<tab>".

What do you think?

Can the completion be improved in this regard?


Thanks,
Daniel.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 173 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-03-09 19:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-03 23:46 Improved completion for git commit objects (__git_commit_objects) Daniel Hahler
2015-03-04  2:40 ` Daniel Shahaf
2015-03-04  2:57   ` Daniel Shahaf
     [not found]   ` <54F7AF66.1010608@thequod.de>
2015-03-07  3:46     ` Daniel Shahaf
2015-03-07  4:01 ` Daniel Shahaf
2015-03-07 12:59   ` Mikael Magnusson
2015-03-09 19:54     ` Daniel Shahaf

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).