Skip to content

Commit 7d6f6e3

Browse files
committed
Merge branch 'sg/completion-remote' into maint
Code simplification. * sg/completion-remote: completion: simplify __git_remotes() completion: add a test for __git_remotes() helper function
2 parents ffac625 + 53e53c7 commit 7d6f6e3

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

contrib/completion/git-completion.bash

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,9 @@ __git_refs_remotes ()
411411

412412
__git_remotes ()
413413
{
414-
local i IFS=$'\n' d="$(__gitdir)"
414+
local d="$(__gitdir)"
415415
test -d "$d/remotes" && ls -1 "$d/remotes"
416-
for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
417-
i="${i#remote.}"
418-
echo "${i/.url*/}"
419-
done
416+
git --git-dir="$d" remote
420417
}
421418

422419
__git_list_merge_strategies ()

t/t9902-completion.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,25 @@ test_expect_success '__gitcomp_nl - doesnt fail because of invalid variable name
351351
__gitcomp_nl "$invalid_variable_name"
352352
'
353353

354+
test_expect_success '__git_remotes - list remotes from $GIT_DIR/remotes and from config file' '
355+
cat >expect <<-EOF &&
356+
remote_from_file_1
357+
remote_from_file_2
358+
remote_in_config_1
359+
remote_in_config_2
360+
EOF
361+
test_when_finished "rm -rf .git/remotes" &&
362+
mkdir -p .git/remotes &&
363+
>.git/remotes/remote_from_file_1 &&
364+
>.git/remotes/remote_from_file_2 &&
365+
test_when_finished "git remote remove remote_in_config_1" &&
366+
git remote add remote_in_config_1 git://remote_1 &&
367+
test_when_finished "git remote remove remote_in_config_2" &&
368+
git remote add remote_in_config_2 git://remote_2 &&
369+
__git_remotes >actual &&
370+
test_cmp expect actual
371+
'
372+
354373
test_expect_success 'basic' '
355374
run_completion "git " &&
356375
# built-in

0 commit comments

Comments
 (0)