* [PATCH] Fix __git_is_treeish and add __git_is_committish
@ 2010-06-09 16:29 Holger Weiss
2010-06-09 20:38 ` Nikolai Weibull
0 siblings, 1 reply; 4+ messages in thread
From: Holger Weiss @ 2010-06-09 16:29 UTC (permalink / raw)
To: Zsh Workers
The __git_is_treeish function is meant to check whether the provided
argument specifies a "tree-ish" Git object. The function runs
git rev-parse $1 --
and passes the result on to "git cat-file". However, due to the
trailing "--", "git rev-parse" spits out two lines, such as:
2719f952d367293602d481dddec8827771e12197
--
Therefore, the "git cat-file" call always fails and __git_is_treeish
always returns false.
This patch simply removes the "--" argument from the "git rev-parse"
call. While at it, it also adds a __git_is_committish function (which
I'll use in my next patch) and lets both functions call the generic
__git_is_type function.
---
Completion/Unix/Command/_git | 24 +++++++++++++++++-------
1 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 9c2d486..e53018f 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -1597,13 +1597,6 @@ _git-branch () {
}
__git_zstyle_default ':completion::complete:git-branch:delete-argument-rest:*' ignore-line yes
-(( $+functions[__git_is_treeish] )) ||
-__git_is_treeish () {
- local sha1
- sha1="$(git rev-parse $1 -- 2> /dev/null)" &&
- [[ "$(git cat-file -t "${sha1}^{tree}" 2> /dev/null)" == tree ]]
-}
-
# TODO: __git_tree_ishs is just stupid. It should be giving us a list of tags
# and perhaps also allow all that just with ^{tree} and so on. Not quite sure
# how to do that, though.
@@ -4423,6 +4416,23 @@ __git_setup_revision_arguments () {
# ---
+(( $+functions[__git_is_type] )) ||
+__git_is_type () {
+ local sha1
+ sha1="$(git rev-parse $2 2> /dev/null)" &&
+ [[ "$(git cat-file -t "${sha1}^{$1}" 2> /dev/null)" == $1 ]]
+}
+
+(( $+functions[__git_is_committish] )) ||
+__git_is_committish () {
+ __git_is_type commit $1
+}
+
+(( $+functions[__git_is_treeish] )) ||
+__git_is_treeish () {
+ __git_is_type tree $1
+}
+
(( $+functions[__git_is_indexed] )) ||
__git_is_indexed () {
[[ -n $(git ls-files $REPLY) ]]
--
Holger
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix __git_is_treeish and add __git_is_committish
2010-06-09 16:29 [PATCH] Fix __git_is_treeish and add __git_is_committish Holger Weiss
@ 2010-06-09 20:38 ` Nikolai Weibull
2010-06-09 20:54 ` Holger Weiß
0 siblings, 1 reply; 4+ messages in thread
From: Nikolai Weibull @ 2010-06-09 20:38 UTC (permalink / raw)
To: Zsh Workers
On Wed, Jun 9, 2010 at 18:29, Holger Weiss <holger@cis.fu-berlin.de> wrote:
> The __git_is_treeish function is meant to check whether the provided
> argument specifies a "tree-ish" Git object. The function runs
>
> git rev-parse $1 --
> This patch simply removes the "--" argument from the "git rev-parse"
> call.
Shouldn’t that be
git rev-parse -- $1
as -- is used to separte options from arguments?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix __git_is_treeish and add __git_is_committish
2010-06-09 20:38 ` Nikolai Weibull
@ 2010-06-09 20:54 ` Holger Weiß
2010-06-09 21:24 ` Nikolai Weibull
0 siblings, 1 reply; 4+ messages in thread
From: Holger Weiß @ 2010-06-09 20:54 UTC (permalink / raw)
To: Zsh Workers
* Nikolai Weibull <now@bitwi.se> [2010-06-09 22:38]:
> On Wed, Jun 9, 2010 at 18:29, Holger Weiss <holger@cis.fu-berlin.de> wrote:
> > The __git_is_treeish function is meant to check whether the provided
> > argument specifies a "tree-ish" Git object. The function runs
> >
> > git rev-parse $1 --
>
> > This patch simply removes the "--" argument from the "git rev-parse"
> > call.
>
> Shouldn't that be
>
> git rev-parse -- $1
>
> as -- is used to separte options from arguments?
"git rev-parse" doesn't interpret "--" that way:
% git rev-parse HEAD
3b703ccc9862106dd5eba7ee7e01e291866e9d1f
% git rev-parse HEAD --
3b703ccc9862106dd5eba7ee7e01e291866e9d1f
--
% git rev-parse -- HEAD
--
HEAD
Holger
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-06-09 21:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-09 16:29 [PATCH] Fix __git_is_treeish and add __git_is_committish Holger Weiss
2010-06-09 20:38 ` Nikolai Weibull
2010-06-09 20:54 ` Holger Weiß
2010-06-09 21:24 ` Nikolai Weibull
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).