default_branch value is ignored when creating a project via API
Summary
default_branch
value is ignored when creating a project via Projects API
Steps to reproduce
Create a project via API using the similar command:
curl --request POST --header "PRIVATE-TOKEN: ***" -d '{ "name": "project-test001", "initialize_with_readme": "true", "default_branch": "stable" }' -H "Content-Type: application/json" "https://gitlabhostname.tld/api/v4/projects/"
What is the current bug behavior?
Default branch defined via default_branch
is not created and selected as default.
What is the expected correct behavior?
Default branch defined via default_branch
should be created and selected as default.
Relevant logs and/or screenshots
n/a
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
System information System: Debian 8.10 Proxy: no Current User: git Using RVM: no Ruby Version: 2.5.3p105 Gem Version: 2.7.6 Bundler Version:1.16.6 Rake Version: 12.3.1 Redis Version: 3.2.12 Git Version: 2.18.1 Sidekiq Version:5.2.3 Go Version: unknown
GitLab information Version: 11.6.3-ee Revision: 76c33c6 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: postgresql DB Version: 9.6.11 URL: https://gitlabhost.tld HTTP Clone URL: https://gitlabhost.tld/some-group/some-project.git SSH Clone URL: git@gitlabhost.tld:some-group/some-project.git Elasticsearch: no Geo: no Using LDAP: no Using Omniauth: yes Omniauth Providers: google_oauth2, gitlab
GitLab Shell Version: 8.4.3 Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks Git: /opt/gitlab/embedded/bin/git
Results of GitLab application Check
Expand for output related to the GitLab application check
Checking GitLab subtasks ...
Checking GitLab Shell ...
GitLab Shell: ... GitLab Shell version >= 8.4.3 ? ... OK (8.4.3) Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Check GitLab API access: OK Redis available via internal API: OK
Access to /var/opt/gitlab/.ssh/authorized_keys: OK gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Gitaly ...
Gitaly: ... default ... OK
Checking Gitaly ... Finished
Checking Sidekiq ...
Sidekiq: ... Running? ... yes Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Checking Incoming Email ...
... Checking Reply by email ... Finished
Checking Incoming Email ... Finished
Checking LDAP ...
LDAP: ... LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab App ...
Git configured correctly? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Init script exists? ... skipped (omnibus-gitlab has no init script) Init script up-to-date? ... skipped (omnibus-gitlab has no init script) Projects have namespace: ... 1/13 ... yes 1/15 ... yes 1/17 ... yes 1/19 ... yes 8/28 ... yes 1/33 ... yes 1/38 ... yes 1/48 ... yes 15/49 ... yes 1/50 ... yes 1/51 ... yes 27/52 ... yes 1/53 ... yes 1/57 ... yes 1/69 ... yes 15/71 ... yes 27/72 ... yes 2/73 ... yes 1/74 ... yes 1/75 ... yes 1/77 ... yes 15/78 ... yes 1/79 ... yes 1/80 ... yes 1/81 ... yes 1/82 ... yes 1/83 ... yes 1/84 ... yes Redis version >= 2.8.0? ... yes Ruby version >= 2.3.5 ? ... yes (2.5.3) Git version >= 2.18.0 ? ... yes (2.18.1) Git user has default SSH configuration? ... yes Active users: ... 7 Elasticsearch version 5.6 - 6.x? ... skipped (elasticsearch is disabled)
Checking GitLab App ... Finished
Checking GitLab subtasks ... Finished
Possible fixes
The workaround is to use 3 API requests:
- create a project:
curl --request POST --header "PRIVATE-TOKEN: ***" -d '{ "name": "project-test001", "initialize_with_readme": "true"}' -H "Content-Type: application/json" "https://gitlabhostname.tld/api/v4/projects/"
create a new branch:
- create a branch:
curl --request POST --header "PRIVATE-TOKEN: ***" -H "Content-Type: application/json" "https://gitlabhostname.tld/api/v4/projects/ID/repository/branches?branch=new-branch&ref=master"
change the default branch to the newly created branch:
- update default branch:
curl --request PUT --header "PRIVATE-TOKEN: ***" -H "Content-Type: application/json" "https://gitlabhostname.tld/api/v4/projects/ID?default_branch=new-branch"
Basically, it looks like a doc bug, and probably we should not specify default_branch
in the list of allowed parameters for create project API as a new project does not have any branches expect the default master
branch.