]> git.wh0rd.org - home.git/blobdiff - .bin/vcs-url
crostini-vapier-setup: helper for setting up new installs
[home.git] / .bin / vcs-url
index f2cd3c9a3bd187eeeb8c2343cdcec7b6e8cf0fd5..8b05986768b33db107af0abf1bdf8d106d588e74 100755 (executable)
@@ -64,6 +64,16 @@ git_url() {
 
        local repo url
        local remote=$(git config remote.origin.url)
+
+       if [[ -z ${remote} ]] ; then
+               # Maybe the repo doesn't use "origin".  Try harder.
+               local branch=$(git rev-parse --abbrev-ref HEAD)
+               remote=$(git config "branch.${branch}.remote")
+               if [[ -n ${remote} ]] ; then
+                       remote=$(git config "remote.${remote}.url")
+               fi
+       fi
+
        case ${remote} in
        *://uclibc.org/*|*://git.uclibc.org/*|\
        *://busybox.net/*|*://git.busybox.net/*|\
@@ -88,10 +98,19 @@ git_url() {
                repo=$(echo "${remote}" | sed -e 's,^git@github.com[:/],,' -e 's,^https://github.com/,,' -e 's,^git://github.com/,,' -e 's:[.]git$::')
                url="https://github.com/${repo}/commit/"
                ;;
+       git@gitlab.com[:/]*|\
+       *://gitlab.com/*)
+               repo=$(echo "${remote}" | sed -e 's,^git@gitlab.com[:/],,' -e 's,^https://gitlab.com/,,' -e 's,^git://gitlab.com/,,' -e 's:[.]git$::')
+               url="https://gitlab.com/${repo}/commit/"
+               ;;
        git://git.sv.gnu.org/*|git://git.savannah.gnu.org/*)
                repo=$(echo "${remote}" | sed -r -e 's,^git://git.(sv|savannah).gnu.org/,,' -e 's:[.]git$::')
                url="http://git.savannah.gnu.org/cgit/${repo}.git/commit/?h="
                ;;
+       git://git.sv.nongnu.org/*|git://git.savannah.nongnu.org/*)
+               repo=$(echo "${remote}" | sed -r -e 's,^git://git.(sv|savannah).nongnu.org/,,' -e 's:[.]git$::')
+               url="http://git.savannah.nongnu.org/cgit/${repo}.git/commit/?h="
+               ;;
        git://git.code.sf.net/p/*|ssh://*@git.code.sf.net/p/*)
                repo=$(echo "${remote}" | sed -r -e 's,(git://|ssh://([^@]*@)?)git.code.sf.net/p/([^/]*)/.*,\3,')
                url="https://sourceforge.net/p/${repo}/code/ci/"
@@ -109,7 +128,11 @@ git_url() {
                ;;
        *://git.qemu.org/*)
                repo=$(echo "${remote}" | sed -e 's,^[^/]*//[^/]*/,,' -e 's,[.]git$,,')
-               url="http://git.qemu.org/?p=${repo}.git;a=commit;h="
+               url="https://git.qemu.org/?p=${repo}.git;a=commit;h="
+               ;;
+       *://git.kernel.org/*)
+               repo=$(echo "${remote}" | sed -e 's,^[^/]*//[^/]*/,,' -e 's,[.]git$,,')
+               url="https://git.kernel.org/${repo}.git/commit/?id="
                ;;
        *)
                echo "Unknown remote: ${remote}"
@@ -125,7 +148,7 @@ svn_url() {
                svn info | \
                awk '{
                        if ($1 == "URL:") {
-                               URL = "http://sources.gentoo.org/" gensub(/.*svnroot\/([^/]*).*/,"\\1","");
+                               URL = "http://sources.gentoo.org/" gensub(/.*svnroot\/([^/]*).*/, "\\1", 1);
                        } else if ($1 == "Revision:") {
                                rev = $2
                                URL = URL "?rev=" (rev + 1) "&view=rev"