]> git.ipfire.org Git - thirdparty/git.git/commitdiff
completion: support excluding full refs
authorSZEDER Gábor <szeder.dev@gmail.com>
Thu, 23 Mar 2017 15:29:15 +0000 (16:29 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 23 Mar 2017 18:18:22 +0000 (11:18 -0700)
Commit 49416ad22 (completion: support excluding refs, 2016-08-24) made
possible to complete short refs with a '^' prefix.

Extend the support to full refs to make completing '^refs/...' work.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-completion.bash
t/t9902-completion.sh

index 067dff823da9744980ee47c232cfd89ff05b2139..882635f97ab1642b0b6ac93c9fc54e0dfaeda6be 100644 (file)
@@ -387,6 +387,10 @@ __git_refs ()
        fi
 
        if [ "$list_refs_from" = path ]; then
+               if [[ "$cur_" == ^* ]]; then
+                       pfx="^"
+                       cur_=${cur_#^}
+               fi
                case "$cur_" in
                refs|refs/*)
                        format="refname"
@@ -394,10 +398,6 @@ __git_refs ()
                        track=""
                        ;;
                *)
-                       if [[ "$cur_" == ^* ]]; then
-                               pfx="^"
-                               cur_=${cur_#^}
-                       fi
                        for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
                                if [ -e "$dir/$i" ]; then echo $pfx$i; fi
                        done
index f641d99ecf1b73432ed0b26cea8ddf3610290f1f..e2b45f62519c7929ad3b3ba99c60a618f36f4693 100755 (executable)
@@ -806,6 +806,37 @@ test_expect_success '__git_refs - after --opt= - full refs' '
        test_cmp expected "$actual"
 '
 
+test_expect_success '__git refs - exluding refs' '
+       cat >expected <<-EOF &&
+       ^HEAD
+       ^master
+       ^matching-branch
+       ^other/branch-in-other
+       ^other/master-in-other
+       ^matching-tag
+       EOF
+       (
+               cur=^ &&
+               __git_refs >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
+test_expect_success '__git refs - exluding full refs' '
+       cat >expected <<-EOF &&
+       ^refs/heads/master
+       ^refs/heads/matching-branch
+       ^refs/remotes/other/branch-in-other
+       ^refs/remotes/other/master-in-other
+       ^refs/tags/matching-tag
+       EOF
+       (
+               cur=^refs/ &&
+               __git_refs >"$actual"
+       ) &&
+       test_cmp expected "$actual"
+'
+
 test_expect_success '__git_complete_refs - simple' '
        sed -e "s/Z$//" >expected <<-EOF &&
        HEAD Z