Skip to content

Commit 18d875e

Browse files
committed
fix 🐛 (git): change get module path (#51)
Signed-off-by: Luis Mayta <[email protected]>
1 parent 04cddb8 commit 18d875e

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

internal/git.zsh

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,39 @@
22
# -*- coding: utf-8 -*-
33
#
44
function core::internal::git::get_module_path {
5+
local basename
56
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
6-
echo "unknown/unknown/$(basename "$(pwd)")"
7-
return
7+
basename="$(basename "$(pwd)")"
8+
core::internal::message::error "not git repository → ${basename}"
9+
return 0
810
fi
911

1012
local remote_url
1113
remote_url="$(git config --get remote.origin.url)"
1214

13-
if [[ "$remote_url" =~ ^git@([^:]+):(.+)\.git$ ]]; then
14-
# [email protected]:hadenlabs/zsh-core.git → github.com/hadenlabs/zsh-core
15-
echo "${BASH_REMATCH[1]}/${BASH_REMATCH[2]}"
16-
elif [[ "$remote_url" =~ ^https?://([^/]+)/(.+)\.git$ ]]; then
17-
# https://github.com/hadenlabs/zsh-core.git → github.com/hadenlabs/zsh-core
18-
echo "${BASH_REMATCH[1]}/${BASH_REMATCH[2]}"
19-
else
20-
echo "unknown/unknown/$(basename "$(pwd)")"
21-
fi
15+
echo "$remote_url" | awk '
16+
{
17+
if ($0 ~ /^git@/) {
18+
sub(/^git@/, "", $0)
19+
split($0, a, ":")
20+
host = a[1]
21+
path = a[2]
22+
}
23+
else if ($0 ~ /^https?:\/\//) {
24+
sub(/^https?:\/\//, "", $0)
25+
split($0, a, "/")
26+
host = a[1]
27+
path = substr($0, length(host) + 2)
28+
}
29+
else {
30+
print "unknown/unknown/" ENVIRON["PWD"]
31+
exit
32+
}
33+
34+
if (path ~ /\.git$/) {
35+
sub(/\.git$/, "", path)
36+
}
37+
38+
print host "/" path
39+
}'
2240
}

0 commit comments

Comments
 (0)