114
done
115
}
116
117
+__git_tags ()
118
+{
119
+ local cmd i is_hash=y dir="$(__gitdir "$1")"
120
+ if [ -d "$dir" ]; then
121
+ for i in $(git --git-dir="$dir" \
122
+ for-each-ref --format='%(refname)' \
123
+ refs/tags ); do
124
+ echo "${i#refs/tags/}"
125
+ done
126
+ return
127
+ fi
128
+ for i in $(git-ls-remote "$1" 2>/dev/null); do
129
+ case "$is_hash,$i" in
130
+ y,*) is_hash=n ;;
131
+ n,*^{}) is_hash=y ;;
132
+ n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
133
+ n,*) is_hash=y; echo "$i" ;;
134
+ esac
135
+ done
136
+}
137
+
138
__git_refs ()
139
{
140
local cmd i is_hash=y dir="$(__gitdir "$1")"
1071
fi
1072
}
1073
1074
+_git_tag ()
1075
+{
1076
+ local i c=1 f=0
1077
+ while [ $c -lt $COMP_CWORD ]; do
1078
+ i="${COMP_WORDS[c]}"
1079
+ case "$i" in
1080
+ -d|-v)
1081
+ __gitcomp "$(__git_tags)"
1082
+ return
1083
+ ;;
1084
+ -f)
1085
+ f=1
1086
+ ;;
1087
+ esac
1088
+ c=$((++c))
1089
+ done
1090
+
1091
+ case "${COMP_WORDS[COMP_CWORD-1]}" in
1092
+ -m|-F)
1093
+ COMPREPLY=()
1094
+ ;;
1095
+ -*|tag|git-tag)
1096
+ if [ $f = 1 ]; then
1097
+ __gitcomp "$(__git_tags)"
1098
+ else
1099
+ COMPREPLY=()
1100
+ fi
1101
+ ;;
1102
+ *)
1103
+ __gitcomp "$(__git_refs)"
1104
+ ;;
1105
+ esac
1106
+}
1107
+
1108
_git ()
1109
{
1110
local i c=1 command __git_dir
1172
show-branch) _git_log ;;
1173
stash) _git_stash ;;
1174
submodule) _git_submodule ;;
1175
+ tag) _git_tag ;;
1176
whatchanged) _git_log ;;
1177
*) COMPREPLY=() ;;
1178
esac
1223
complete -o default -o nospace -F _git_stash git-stash
1224
complete -o default -o nospace -F _git_submodule git-submodule
1225
complete -o default -o nospace -F _git_log git-show-branch
1226
+complete -o default -o nospace -F _git_tag git-tag
1227
complete -o default -o nospace -F _git_log git-whatchanged
1228
1229
# The following are necessary only for Cygwin, and only are needed
1249
complete -o default -o nospace -F _git_shortlog git-shortlog.exe
1250
complete -o default -o nospace -F _git_show git-show.exe
1251
complete -o default -o nospace -F _git_log git-show-branch.exe
1252
+complete -o default -o nospace -F _git_tag git-tag.exe
1253
complete -o default -o nospace -F _git_log git-whatchanged.exe
1254
fi