yegomo
yegomo

Reputation: 297

how to set http as the project default url in gitlab

when opening a project in gitlab, you will see SSH and HTTP(or HTTPS) url on the top of project home page, the SSH url is as default, but I want to set HTTP(or HTTPS) as default, so how should I do? Thanks

Upvotes: 15

Views: 4868

Answers (4)

eulersexception
eulersexception

Reputation: 51

I stumbled over this problem while running several Gitlab accounts on the same machine which required different settings concerning the access protocol but every post I saw related to changes in the settings globally. To avoid configuration problems I looked for a way to change the settings for every project locally. Following steps fixed my problems:

  1. Open the terminal and change into your projects .git folder.

cd my_project/.git

  1. Open the browser. Navigate to the Gitlab repo. Click blue "Clone" button. Copy the URL for cloning via https.

  2. Switch to the terminal again. Edit the file named "config" located int the .git folder. I used "Vim" for editing.

vi config

  1. Change line with the existing url in the [remote "origin"] block to:

url = "paste copied url"

Upvotes: 1

Eirik Lygre
Eirik Lygre

Reputation: 310

If this is still important to you, consider commenting on https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/1811 or https://gitlab.com/gitlab-org/gitlab-ce/issues/3504. If this request is approved, it will solve your problem in the standard product. The merge request is being considered "as we speak".

Upvotes: -1

VonC
VonC

Reputation: 1326994

The app/views/shared/_clone_panel.html.haml file does show:

.git-clone-holder.input-group
  .input-group-btn
    %button{class: "btn #{ 'active' if default_clone_protocol == 'ssh' }", :"data-clone" => project.ssh_url_to_repo} SSH
    %button{class: "btn #{ 'active' if default_clone_protocol == 'http' }", :"data-clone" => project.http_url_to_repo}= gitlab_config.protocol.upcase

And that default_clone_protocol is defined in app/helpers/projects_helper.rb

def default_clone_protocol
    current_user ? "ssh" : "http"
end

So you could change that code, or add a setting in config/gitlab.yml.example in order to make it a parameter.

As mentioned by Mosi Wang's answer, the function default_url_to_repo also plays a role in the definition of that order, since it returns project.url_to_repo : project.http_url_to_repo.
Reversing the order can help too.

Upvotes: 8

Mosi Wang
Mosi Wang

Reputation: 101

infact, you have to modify 2 other lines above the default_clone_protocol.

def default_url_to_repo(project = nil)
  project = project || @project
  current_user ? project.http_url_to_repo : project.url_to_repo
end

def default_clone_protocol
  current_user ? "http" : "ssh"
end

Upvotes: 10

Related Questions