From 4e3aa0ad514cc07118262b04ded39da0cdf60846 Mon Sep 17 00:00:00 2001 From: Martin Delille Date: Fri, 10 Feb 2017 18:13:47 +0100 Subject: [PATCH] Add http protocol for Gitlab custom host (#60) * Add http protocol for Gitlab custom host * default to https * Revert "default to https" This reverts commit b25190b5d11945f73b97155d8ad23f9b7add981c. * Revert "Merge branch 'master' into http" This reverts commit 18573f8b29fa33ae1b948cf4eb7fee39c9d7067d, reversing changes made to 88a9e254aea74e1ba36734fada9b9d9abd9df9d9. * Revert "Revert "Merge branch 'master' into http"" This reverts commit fa0e6d1f21e10113961fe94d99d597cdfdbc9adf. * Revert "Revert "default to https"" This reverts commit d754476010f58e77aabafd6847921997a2f73fc2. --- README.md | 6 ++++++ git-open | 12 +++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c1b091a..9ef6d35 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,12 @@ git config [--global] gitopen.gitlab.ssh.domain [value] git config [--global] gitopen.gitlab.ssh.port [value] ``` +If your Gitlab custom hosted is serving `http` you can also specify this: +```sh +# use --global to set across all repos, instead of just the local one +git config [--global] gitopen.gitlab.protocol http +``` + ## Related projects / alternatives See [hub](https://github.com/github/hub) for complete GitHub opening support. diff --git a/git-open b/git-open index a84fbb8..e8c4c74 100755 --- a/git-open +++ b/git-open @@ -95,14 +95,20 @@ else gitlab_ssh_domain=$(git config --get gitopen.gitlab.ssh.domain) gitlab_ssh_domain=${gitlab_ssh_domain:-$gitlab_domain} gitlab_ssh_port=$(git config --get gitopen.gitlab.ssh.port) - if [ -n "$gitlab_domain" ]; then + + gitlab_protocol=$(git config --get gitopen.gitlab.protocol) + if [ -z "$gitlab_protocol" ]; then + gitlab_protocol=https + fi + +if [ -n "$gitlab_domain" ]; then if egrep -q "${gitlab_domain}|${gitlab_ssh_domain}" <<<$giturl; then # Handle GitLab's default SSH notation (like git@gitlab.domain.com:user/repo) - giturl=${giturl/git\@${gitlab_ssh_domain}\:/https://${gitlab_domain}/} + giturl=${giturl/git\@${gitlab_ssh_domain}\:/${gitlab_protocol}://${gitlab_domain}/} # handle SSH protocol (links like ssh://git@gitlab.domain.com/user/repo) - giturl=${giturl/#ssh\:\/\//https://} + giturl=${giturl/#ssh\:\/\//${gitlab_protocol}://} # remove git@ from the domain giturl=${giturl/git\@${gitlab_ssh_domain}/${gitlab_domain}/}