From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21588 invoked by alias); 19 Aug 2015 02:05:41 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36237 Received: (qmail 15910 invoked from network); 19 Aug 2015 02:05:40 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=p2zp17ARO0P3kEiRPho5IY7pzNg=; b=KlolqD hs4UtqhfrHYS3PESE+KWsrW3N9plFI1DrKkgpi5xtUe5QBxq+2OIQ5epazvhro1n lzW8vL1L+fNFFva440JzY8M8z3xp+xK7NpinsNlf7mXkPSfuIpD7bZYTPpPmtKlT MfFHAHujLu5GzqQf37JgE3SxV6xw2WYrmERb8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-sasl-enc :x-sasl-enc; s=smtpout; bh=p2zp17ARO0P3kEiRPho5IY7pzNg=; b=LRxBm f+THpeR7WUukGtWUILQr1ud4L28FrGYmO5PNCz5LMKkEimTfpSZHnN9V4UYWcZoT xUf73Y44SYsPBz3VDFZhU9wEo1p0COLpudNI0gQShBTFCLQWB+cxG1KIJTmDacmS FsZdlcOukX90BfHKKKOAhxAgW/kwd6n6BinK/g= X-Sasl-enc: HwkYpdqsC4DpYOWYa+zHaRJnfpB+6xva5sTHYNAz+01m 1439949938 Date: Wed, 19 Aug 2015 02:05:36 +0000 From: Daniel Shahaf To: zsh-workers@zsh.org Subject: [PATCH] _git-cat-file blob completion fix Message-ID: <20150819020536.GE2005@tarsus.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.5.21 (2010-09-15) 'git cat-file HEAD:', when cwd is a subdirectory of a repository, completes files within that subdirectory, but should complete files relative to the repository root. The attach patch implements that. Review would be appreciated — I might have missed something while reverse-engineering the semantics of everything. (I already checked gitrevisions(7) and tested 'git rev-parse HEAD:'.) I didn't make --root-relative a zparseopts option because I didn't want to have to name the same as git option it maps to. Cheers, Daniel diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index 6922393..e9adc70 100644 --- a/Completion/Unix/Command/_git +++ b/Completion/Unix/Command/_git @@ -5739,7 +5739,7 @@ __git_tree_ishs () { __git_objects () { compset -P '*:' if [[ -n $IPREFIX ]]; then - __git_tree_files "$PREFIX" "${IPREFIX%:}" + __git_tree_files --root-relative "$PREFIX" "${IPREFIX%:}" else _alternative \ 'revisions::__git_revisions' \ @@ -5984,12 +5984,23 @@ __git_changed_files () { 'changed-in-working-tree-files::__git_changed-in-working-tree_files' } +# __git_tree_files [--root-relative] FSPATH TREEISH [TREEISH...] [COMPADD OPTIONS] +# +# Complete [presently: a single level of] repository files under FSPATH. +# FSPATH is interpreted as a directory path within each TREEISH. +# FSPATH is relative to cwd, unless --root-relative is specified, in +# which case it is relative to the repository root. (( $+functions[__git_tree_files] )) || __git_tree_files () { local multi_parts_opts local tree Path integer at_least_one_tree_added local -a tree_files compadd_opts + local -a extra_args + + if [[ $1 == --root-relative ]]; then + extra_args+=(--full-tree) + fi zparseopts -D -E -a compadd_opts V: J: 1 2 n f X: M: P: S: r: R: q F: @@ -5997,7 +6008,7 @@ __git_tree_files () { shift (( at_least_one_tree_added = 0 )) for tree in $*; do - tree_files+=(${(ps:\0:)"$(_call_program tree-files git ls-tree --name-only -z $tree $Path 2>/dev/null)"}) + tree_files+=(${(ps:\0:)"$(_call_program tree-files git ls-tree $extra_args --name-only -z $tree $Path 2>/dev/null)"}) __git_command_successful $pipestatus && (( at_least_one_tree_added = 1 )) done