fix: bad remote replacement

This commit is contained in:
2024-08-14 00:56:12 +03:00
parent 01841402a2
commit 55a4b761eb
3 changed files with 9 additions and 5 deletions

View File

@@ -19,5 +19,5 @@ jobs:
sudo apt update
sudo apt install zsh -y
- name: Test
- name: Run Tests
run: ./test/git-open.test.zsh

View File

@@ -26,11 +26,12 @@ git_get_repo_path() {
repo_path=''
if [[ $remote =~ ^git@ ]]; then
repo_path=$(echo "$remote" | sed -E 's/^git@[^:]+:([^:]+)\.git$/\1/')
repo_path=$(echo "$remote" | sed -E 's|^git@[^:]+:([^:]+)\.git$|\1|')
repo_path=$(echo "$repo_path" | sed -E 's|^git@[^:]+:([^:]+)$|\1|')
elif [[ $remote =~ ^https?:// ]]; then
repo_path=$(echo "$remote" | sed -E 's|^https?://[^/]+/([^\.]+)\.git$|\1|')
repo_path=$(echo "$remote" | sed -E 's|^https?://[^/]+/([^\.]+)\.git$|\1|')
repo_path=$(echo "$repo_path" | sed -E 's|^https?://[^/]+/([^\.]+)$|\1|')
fi
echo $repo_path
}

View File

@@ -30,15 +30,18 @@ describe() {
describe "git_open_project"
assert_value "https:/i/github.com/chenasraf/git-open" $(git_open_project)
assert_value "https://github.com/chenasraf/git-open" $(git_open_project)
describe "git_get_remote"
assert_value "git@github.com:chenasraf/git-open.git" $(git_get_remote)
describe "git_get_repo_path"
assert_value "chenasraf/git-open" $(git_get_repo_path $(git_get_remote))
assert_value "chenasraf/git-open" $(git_get_repo_path "https://gitlab.com/chenasraf/git-open")
assert_value "chenasraf/git-open" $(git_get_repo_path "https://gitlab.com/chenasraf/git-open.git")
assert_value "chenasraf/git-open" $(git_get_repo_path "https://bitbucket.org/chenasraf/git-open")
assert_value "chenasraf/git-open" $(git_get_repo_path "https://bitbucket.org/chenasraf/git-open.git")
assert_value "chenasraf/git-open" $(git_get_repo_path "git@gitlab.com:chenasraf/git-open")
assert_value "chenasraf/git-open" $(git_get_repo_path "git@gitlab.com:chenasraf/git-open.git")
assert_value "chenasraf/git-open" $(git_get_repo_path "git@bitbucket.org:chenasraf/git-open.git")