Merge branch 'ab/completion-push-delete-ref'
authorJunio C Hamano <gitster@pobox.com>
Wed, 26 Apr 2017 06:39:09 +0000 (15:39 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 26 Apr 2017 06:39:09 +0000 (15:39 +0900)
The completion script (in contrib/) learned to complete "git push
--delete b<TAB>" to complete branch name to be deleted.

* ab/completion-push-delete-ref:
completion: expand "push --delete <remote> <ref>" for refs on that <remote>

contrib/completion/git-completion.bash
t/t9902-completion.sh
index 1150164d5ce0e7396191a192189b43444883f739..b6170190759eed9f5af336985c0ee70f3fcb42df 100644 (file)
@@ -709,6 +709,7 @@ __git_complete_remote_or_refspec ()
                i="${words[c]}"
                case "$i" in
                --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
+               -d|--delete) [ "$cmd" = "push" ] && lhs=0 ;;
                --all)
                        case "$cmd" in
                        push) no_complete_refspec=1 ;;
index 5ed28135bea13a6c4082413044d8dcb205449c38..2cb999ecfab69eb7825ad05c79a874114f921716 100755 (executable)
@@ -1457,4 +1457,38 @@ test_expect_failure 'complete with tilde expansion' '
        test_completion "git add ~/tmp/" "~/tmp/file"
 '
 
+test_expect_success 'setup other remote for remote reference completion' '
+       git remote add other otherrepo &&
+       git fetch other
+'
+
+for flag in -d --delete
+do
+       test_expect_success "__git_complete_remote_or_refspec - push $flag other" '
+               sed -e "s/Z$//" >expected <<-EOF &&
+               master-in-other Z
+               EOF
+               (
+                       words=(git push '$flag' other ma) &&
+                       cword=${#words[@]} cur=${words[cword-1]} &&
+                       __git_complete_remote_or_refspec &&
+                       print_comp
+               ) &&
+               test_cmp expected out
+       '
+
+       test_expect_failure "__git_complete_remote_or_refspec - push other $flag" '
+               sed -e "s/Z$//" >expected <<-EOF &&
+               master-in-other Z
+               EOF
+               (
+                       words=(git push other '$flag' ma) &&
+                       cword=${#words[@]} cur=${words[cword-1]} &&
+                       __git_complete_remote_or_refspec &&
+                       print_comp
+               ) &&
+               test_cmp expected out
+       '
+done
+
 test_done