File tree Expand file tree Collapse file tree 2 files changed +55
-18
lines changed Expand file tree Collapse file tree 2 files changed +55
-18
lines changed Original file line number Diff line number Diff line change @@ -1120,26 +1120,44 @@ __git_pretty_aliases ()
1120
1120
# __git_aliased_command requires 1 argument
1121
1121
__git_aliased_command ()
1122
1122
{
1123
- local word cmdline=$( __git config --get " alias.$1 " )
1124
- for word in $cmdline ; do
1125
- case " $word " in
1126
- \! gitk|gitk)
1127
- echo " gitk"
1128
- return
1129
- ;;
1130
- \! * ) : shell command alias ;;
1131
- -* ) : option ;;
1132
- * =* ) : setting env ;;
1133
- git) : git itself ;;
1134
- \(\) ) : skip parens of shell function definition ;;
1135
- {) : skip start of shell helper function ;;
1136
- :) : skip null command ;;
1137
- \' * ) : skip opening quote after sh -c ;;
1138
- * )
1139
- echo " $word "
1123
+ local cur=$1 last list word cmdline
1124
+
1125
+ while [[ -n " $cur " ]]; do
1126
+ if [[ " $list " == * " $cur " * ]]; then
1127
+ # loop detected
1140
1128
return
1141
- esac
1129
+ fi
1130
+
1131
+ cmdline=$( __git config --get " alias.$cur " )
1132
+ list=" $cur $list "
1133
+ last=$cur
1134
+ cur=
1135
+
1136
+ for word in $cmdline ; do
1137
+ case " $word " in
1138
+ \! gitk|gitk)
1139
+ cur=" gitk"
1140
+ break
1141
+ ;;
1142
+ \! * ) : shell command alias ;;
1143
+ -* ) : option ;;
1144
+ * =* ) : setting env ;;
1145
+ git) : git itself ;;
1146
+ \(\) ) : skip parens of shell function definition ;;
1147
+ {) : skip start of shell helper function ;;
1148
+ :) : skip null command ;;
1149
+ \' * ) : skip opening quote after sh -c ;;
1150
+ * )
1151
+ cur=" $word "
1152
+ break
1153
+ esac
1154
+ done
1142
1155
done
1156
+
1157
+ cur=$last
1158
+ if [[ " $cur " != " $1 " ]]; then
1159
+ echo " $cur "
1160
+ fi
1143
1161
}
1144
1162
1145
1163
# Check whether one of the given words is present on the command line,
Original file line number Diff line number Diff line change @@ -2195,6 +2195,25 @@ test_expect_success 'complete files' '
2195
2195
test_completion "git add mom" "momified"
2196
2196
'
2197
2197
2198
+ test_expect_success " simple alias" '
2199
+ test_config alias.co checkout &&
2200
+ test_completion "git co m" <<-\EOF
2201
+ master Z
2202
+ mybranch Z
2203
+ mytag Z
2204
+ EOF
2205
+ '
2206
+
2207
+ test_expect_success " recursive alias" '
2208
+ test_config alias.co checkout &&
2209
+ test_config alias.cod "co --detached" &&
2210
+ test_completion "git cod m" <<-\EOF
2211
+ master Z
2212
+ mybranch Z
2213
+ mytag Z
2214
+ EOF
2215
+ '
2216
+
2198
2217
test_expect_success " completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
2199
2218
test_config alias.co "!sh -c ' " '" ' git checkout ...' " '" ' " &&
2200
2219
test_completion "git co m" <<-\EOF
You can’t perform that action at this time.
0 commit comments