Skip to content

Commit 5db08d8

Browse files
committed
refactor: Modify 'util.construct_clone_url' to give info about domain
1 parent 46a5aa3 commit 5db08d8

File tree

6 files changed

+149
-27
lines changed

6 files changed

+149
-27
lines changed

pkg/lib/commands/do-add.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ do-add() {
2222
for repoSpec in "${pkgs[@]}"; do
2323
util.construct_clone_url "$repoSpec" "$with_ssh"
2424
local uri="$REPLY1"
25-
local package="$REPLY2"
26-
local ref="$REPLY3"
25+
local site="$REPLY2"
26+
local package="$REPLY3"
27+
local ref="$REPLY4"
2728

2829
log.info "Installing '$repoSpec'"
2930
do-plumbing-clone "$uri" "$package" $ref

pkg/lib/commands/do-plumbing-remove-deps.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ do-plumbing-remove-deps() {
2525
for dep in "${deps[@]}"; do
2626
util.construct_clone_url "$repoSpec" "$with_ssh"
2727
local uri="$REPLY1"
28-
local package="$REPLY2"
28+
local site="$REPY2"
29+
local package="$REPLY3"
30+
local ref="$REPLY4"
2931

3032
rm -rf "${BPM_PACKAGES_PATH:?}/$package"
3133
done

pkg/lib/util/util.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ util.construct_clone_url() {
4343
REPLY1=
4444
REPLY2=
4545
REPLY3=
46+
REPLY4=
4647

4748
local repoSpec="$1"
4849
local with_ssh="$2"
@@ -63,17 +64,19 @@ util.construct_clone_url() {
6364
IFS='/' read -r site package <<< "$repoSpec"
6465

6566
REPLY1="$http://$repoSpec.git"
66-
REPLY2="$package"
67-
REPLY3=
67+
REPLY2="$site"
68+
REPLY3="$package"
69+
REPLY4=
6870
elif [[ "$repoSpec" =~ $regex2 ]]; then
6971
repoSpec="${repoSpec#git@}"
7072
repoSpec="${repoSpec%.git}"
7173

7274
IFS=':' read -r site package <<< "$repoSpec"
7375

74-
REPLY1="git@$repoSpec.git"
75-
REPLY2="$package"
76-
REPLY3=
76+
REPLY1="git@$repoSpec"
77+
REPLY2="$site"
78+
REPLY3="$package"
79+
REPLY4=
7780
else
7881
repoSpec="${repoSpec%.git}"
7982

@@ -91,12 +94,13 @@ util.construct_clone_url() {
9194
fi
9295

9396
if [ "$with_ssh" = yes ]; then
94-
REPLY1="git@$site:$package.git"
97+
REPLY1="git@$site:$package"
9598
else
9699
REPLY1="https://$site/$package.git"
97100
fi
98-
REPLY2="$package"
99-
REPLY3="$ref"
101+
REPLY2="$site"
102+
REPLY3="$package"
103+
REPLY4="$ref"
100104
fi
101105
}
102106

tests/do-install.bats

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ load 'util/init.sh'
120120
run do-add --ssh username/package
121121

122122
assert_success
123-
assert_line "do-plumbing-clone git@github.com:username/package.git username/package"
123+
assert_line "do-plumbing-clone git@github.com:username/package username/package"
124124
}
125125

126126
@test "uses ssh protocol, when specified (at end)" {
@@ -133,7 +133,7 @@ load 'util/init.sh'
133133
run do-add username/package --ssh
134134

135135
assert_success
136-
assert_line "do-plumbing-clone git@github.com:username/package.git username/package"
136+
assert_line "do-plumbing-clone git@github.com:username/package username/package"
137137
}
138138

139139
@test "uses ssh protocol raw, when specified" {
@@ -146,7 +146,7 @@ load 'util/init.sh'
146146
run do-add git@github.com:username/package
147147

148148
assert_success
149-
assert_line "do-plumbing-clone git@github.com:username/package.git username/package"
149+
assert_line "do-plumbing-clone git@github.com:username/package username/package"
150150
}
151151

152152
@test "uses custom version, when specified" {

tests/util-construct-clone-url.bats

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/usr/bin/env bats
2+
3+
load 'util/init.sh'
4+
5+
6+
@test "fails on no arguments" {
7+
run util.construct_clone_url
8+
9+
assert_failure
10+
assert_line -p "Must supply a repository"
11+
}
12+
13+
@test "parses with full https url" {
14+
util.construct_clone_url 'https://gitlab.com/eankeen/proj'
15+
16+
assert [ "$REPLY1" = 'https://gitlab.com/eankeen/proj.git' ]
17+
assert [ "$REPLY2" = 'gitlab.com' ]
18+
assert [ "$REPLY3" = 'eankeen/proj' ]
19+
assert [ "$REPLY4" = '' ]
20+
}
21+
22+
@test "parses with full http url" {
23+
util.construct_clone_url 'http://gitlab.com/eankeen/proj'
24+
25+
assert [ "$REPLY1" = 'http://gitlab.com/eankeen/proj.git' ]
26+
assert [ "$REPLY2" = 'gitlab.com' ]
27+
assert [ "$REPLY3" = 'eankeen/proj' ]
28+
assert [ "$REPLY4" = '' ]
29+
}
30+
31+
@test "parses with full https url with .git ending" {
32+
util.construct_clone_url 'https://gitlab.com/eankeen/proj'
33+
34+
assert [ "$REPLY1" = 'https://gitlab.com/eankeen/proj.git' ]
35+
assert [ "$REPLY2" = 'gitlab.com' ]
36+
assert [ "$REPLY3" = 'eankeen/proj' ]
37+
assert [ "$REPLY4" = '' ]
38+
}
39+
40+
@test "parses with full http url with .git ending" {
41+
util.construct_clone_url 'http://gitlab.com/eankeen/proj.git'
42+
43+
assert [ "$REPLY1" = 'http://gitlab.com/eankeen/proj.git' ]
44+
assert [ "$REPLY2" = 'gitlab.com' ]
45+
assert [ "$REPLY3" = 'eankeen/proj' ]
46+
assert [ "$REPLY4" = '' ]
47+
}
48+
49+
@test "parses with full ssh url" {
50+
util.construct_clone_url 'git@gitlab.com:eankeen/proj.git'
51+
52+
assert [ "$REPLY1" = 'git@gitlab.com:eankeen/proj' ]
53+
assert [ "$REPLY2" = 'gitlab.com' ]
54+
assert [ "$REPLY3" = 'eankeen/proj' ]
55+
assert [ "$REPLY4" = '' ]
56+
}
57+
58+
@test "parses with package and domain" {
59+
util.construct_clone_url 'gitlab.com/eankeen/proj'
60+
61+
assert [ "$REPLY1" = 'https://gitlab.com/eankeen/proj.git' ]
62+
assert [ "$REPLY2" = 'gitlab.com' ]
63+
assert [ "$REPLY3" = 'eankeen/proj' ]
64+
assert [ "$REPLY4" = '' ]
65+
}
66+
67+
@test "parses with package and domain and ref" {
68+
util.construct_clone_url 'gitlab.com/eankeen/proj@v0.1.0'
69+
70+
assert [ "$REPLY1" = 'https://gitlab.com/eankeen/proj.git' ]
71+
assert [ "$REPLY2" = 'gitlab.com' ]
72+
assert [ "$REPLY3" = 'eankeen/proj' ]
73+
assert [ "$REPLY4" = 'v0.1.0' ]
74+
}
75+
76+
@test "parses with package and domain with ssh" {
77+
util.construct_clone_url 'gitlab.com/eankeen/proj' 'yes'
78+
79+
assert [ "$REPLY1" = 'git@gitlab.com:eankeen/proj' ]
80+
assert [ "$REPLY2" = 'gitlab.com' ]
81+
assert [ "$REPLY3" = 'eankeen/proj' ]
82+
assert [ "$REPLY4" = '' ]
83+
}
84+
85+
@test "parses with package and domain and ref with ssh" {
86+
util.construct_clone_url 'gitlab.com/eankeen/proj@v0.1.0' 'yes'
87+
88+
assert [ "$REPLY1" = 'git@gitlab.com:eankeen/proj' ]
89+
assert [ "$REPLY2" = 'gitlab.com' ]
90+
assert [ "$REPLY3" = 'eankeen/proj' ]
91+
assert [ "$REPLY4" = 'v0.1.0' ]
92+
}
93+
94+
@test "parses with package" {
95+
util.construct_clone_url 'eankeen/proj'
96+
97+
assert [ "$REPLY1" = 'https://github.com/eankeen/proj.git' ]
98+
assert [ "$REPLY2" = 'github.com' ]
99+
assert [ "$REPLY3" = 'eankeen/proj' ]
100+
assert [ "$REPLY4" = '' ]
101+
}
102+
103+
@test "parses with package and ref" {
104+
util.construct_clone_url 'eankeen/proj@v0.2.0'
105+
106+
assert [ "$REPLY1" = 'https://github.com/eankeen/proj.git' ]
107+
assert [ "$REPLY2" = 'github.com' ]
108+
assert [ "$REPLY3" = 'eankeen/proj' ]
109+
assert [ "$REPLY4" = 'v0.2.0' ]
110+
}
111+
112+
@test "parses with package with ssh" {
113+
util.construct_clone_url 'eankeen/proj' 'yes'
114+
115+
assert [ "$REPLY1" = 'git@github.com:eankeen/proj' ]
116+
assert [ "$REPLY2" = 'github.com' ]
117+
assert [ "$REPLY3" = 'eankeen/proj' ]
118+
assert [ "$REPLY4" = '' ]
119+
}
120+
121+
@test "parses with package with ssh and ref" {
122+
util.construct_clone_url 'eankeen/proj@v0.2.0' 'yes'
123+
124+
assert [ "$REPLY1" = 'git@github.com:eankeen/proj' ]
125+
assert [ "$REPLY2" = 'github.com' ]
126+
assert [ "$REPLY3" = 'eankeen/proj' ]
127+
assert [ "$REPLY4" = 'v0.2.0' ]
128+
}

tests/util-parse-package.bats

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)