You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description of the problem, including code/CLI snippet
I've spent a couple hours on this, but basically when creating a project from the python package or from CLI, the default_branch (in SDK) and --default-branch settings are ignored,
After creation as described, the project object should show default_branch == "master" and the branch should show as protected.
Regardless of being created from CLI or SDK.
Actual Behavior
The CLI and SDK both show that the default branch is "main". The console says that a default branch cannot be set on an empty repo.
If this is not possible because of how the gitlab package is a thin wrapper over gitlab REST API, the readme in this repo should at least mention such discrepencies between the docs (auto generated from the REST API, shown in the CLI --help output) and actual behavior.
Workaround (possibly a hack)
Call these 2 functions, in order:
def gitlab_project_repo_setup_content(project):
try:
project.files.get('README.md', ref='main')
except GitlabGetError:
print('Creating file in repo')
project.files.create(
{
'file_path': 'README.md',
'branch': 'main',
'content': '# Placeholder file',
'commit_message': 'Add README to initialize repository',
}
)
def gitlab_project_set_default_branch(project):
"""
Workaround for gitlab default branch can only be changed after there is content added:
if you set default_branch in the project.create(), it gets ignored, ie project.default_branch will
still be 'main'. Same goes for command line. It appears that there HAS to be at least one
file in the reop for the default branch to be changed.
"""
# verify that that readme exists, this will raise exception if not:
project.files.get('README.md', ref='main')
project.branches.create({'branch': 'master', 'ref': 'main'})
project.default_branch = 'master'
project.save()
project.protectedbranches.create({'name': 'master'})
project.protectedbranches.delete('main')
project.branches.delete('main')
After running these 2, the git repo will have only master branch, and gitlab console will show this and that it is default and protected,
Specifications
python-gitlab version: 5.6.0
Gitlab server version (or gitlab.com): gitlab.com
The text was updated successfully, but these errors were encountered:
I'm thinking that could be the cause here, since the gitlab account is part of an organization where there could be such rules in place, is there a way that I can verify whether that's the case?
Description of the problem, including code/CLI snippet
I've spent a couple hours on this, but basically when creating a project from the python package or from CLI, the
default_branch
(in SDK) and--default-branch
settings are ignored,The same thing happens from CLI:
Expected Behavior
After creation as described, the project object should show
default_branch
== "master" and the branch should show as protected.Regardless of being created from CLI or SDK.
Actual Behavior
The CLI and SDK both show that the default branch is "main". The console says that a default branch cannot be set on an empty repo.
If this is not possible because of how the gitlab package is a thin wrapper over gitlab REST API, the readme in this repo should at least mention such discrepencies between the docs (auto generated from the REST API, shown in the CLI --help output) and actual behavior.
Workaround (possibly a hack)
Call these 2 functions, in order:
After running these 2, the git repo will have only master branch, and gitlab console will show this and that it is default and protected,
Specifications
The text was updated successfully, but these errors were encountered: