Atlassian Stash uses repo URLs for cloning/pushing/pulling in the form of
https://mystashserver/scm/myproject/myrepo.git
How can I transform this URL into the one used by Stash's web UI in the form of
https://mystashserver/projects/myproject/repos/myrepo
Opening the first URL in the browser automatically forwards to the latter, but you can't add additional parameters, eg for selecting a specific branch.
I'm looking for a way to transform URLs of the first kind to the latter, ideally for use in a Bash script.
The following works in a Bash script, using Bash's built-in regular expression support:
giturl=https://mystashserver/scm/myproject/myrepo.git
re='(.*)/scm/(.*)/(.*)\.git'
if [[ $giturl =~ $re ]]; then
newgiturl=${BASH_REMATCH[1]}/projects/${BASH_REMATCH[2]}/repos/${BASH_REMATCH[3]}
echo $newgiturl
fi
The regular expression splits up the original URL into several parts:
.git
suffix In the above example, the newgiturl
variable then reassembles the URL, injecting the projects
and repos
part in the desired locations.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.