@@ -10,7 +10,10 @@ echo "$(tput setaf 4)Setting up...$(tput sgr0)"
1010snapshot=" ${0: A: h} /snapshot.txt"
1111current_branch=$( git branch --show-current)
1212current_ref=$( git rev-parse HEAD)
13- remote_url=$( git remote -v | grep " (push)" | awk ' {print $2}' )
13+ remote_url=$( git remote -v | grep " (push)" | grep " ^origin " | head -1 | awk ' {print $2}' )
14+ if [[ -z " $remote_url " ]]; then
15+ remote_url=$( git remote -v | grep " (push)" | head -1 | awk ' {print $2}' )
16+ fi
1417
1518__UTILS_PATH=" ${0: A: h} /utils.mock.zsh" \
1619__UNLOAD_PATH=" /dev/null" \
@@ -94,6 +97,39 @@ assert_value "https://github.com/chenasraf/git-open/actions" $(git_open_pipeline
9497describe " without args"
9598assert_value " $( cat $snapshot ) " " $( git_open) "
9699
100+ # ## Multi-remote tests
101+ echo " "
102+ echo " $( tput setaf 4) Setting up multi-remote tests...$( tput sgr0) "
103+ git remote add fake-upstream " https://github.com/fakeorg/git-open.git" 2> /dev/null
104+
105+ describe " git_get_remote prefers origin with multiple remotes"
106+ git_remote_name=" "
107+ assert_value " $remote_url " $( git_get_remote)
108+
109+ describe " git_get_remote with --remote flag"
110+ git_remote_name=" fake-upstream"
111+ assert_value " https://github.com/fakeorg/git-open.git" $( git_get_remote)
112+
113+ describe " git_open_project with --remote flag"
114+ git_remote_name=" fake-upstream"
115+ assert_value " https://github.com/fakeorg/git-open" $( git_open_project)
116+
117+ describe " git_open_branch with --remote flag"
118+ git_remote_name=" fake-upstream"
119+ assert_value " https://github.com/fakeorg/git-open/tree/$current_branch " $( git_open_branch)
120+
121+ describe " git_get_remote falls back to first when name not found"
122+ git_remote_name=" nonexistent"
123+ result=$( git_get_remote)
124+ assert_value 0 $( [[ -n " $result " ]] && echo 0 || echo 1)
125+
126+ # Reset remote name
127+ git_remote_name=" "
128+
129+ echo " "
130+ echo " $( tput setaf 4) Cleaning up multi-remote tests...$( tput sgr0) "
131+ git remote remove fake-upstream 2> /dev/null
132+
97133# ## Teardown
98134echo ' '
99135echo " $( tput setaf 2) All tests passed!$( tput sgr0) "
0 commit comments