Skip to content

Commit 91c75bf

Browse files
committed
git-gitlab: use inline python script to robustly get gitlab_id corresponding to the git remote
1 parent 5526479 commit 91c75bf

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

git-gitlab.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,19 @@ select_remote () {
2323
instance_name() {
2424
host=$1
2525
pyglab_conf=$2
26-
grep -B 5 "^\s*url\s*=\s*http\(s\)*://$host" $pyglab_conf | grep "^\[" | tail -n 1 | sed -e 's#\[\(.\+\)\]#\1#'
26+
python3 -c "import re
27+
import sys
28+
from configparser import ConfigParser
29+
30+
confparser = ConfigParser(allow_no_value=True)
31+
confparser.read(sys.argv[1])
32+
proto=re.compile(r'http(s)*://')
33+
for section in confparser.sections():
34+
url=confparser.get(section,'url',fallback=None)
35+
if url: url=proto.sub('',url)
36+
if url==sys.argv[2]:
37+
print(section)
38+
break" $pyglab_conf $host
2739
}
2840

2941
remote=$(git config gitlab.remote)

0 commit comments

Comments
 (0)