Skip to content

Commit 1001d93

Browse files
nickbroonJohnVillalovos
authored andcommitted
fix: file save start_branch as a body attribute
Passing `start_branch` as kwargs results in it being passed as query argument to the API: ``` send: b'PUT /api/v4/projects/12345678/repository/files/readme.txt?start_branch=main send: b'{"file_path": "readme.txt", "branch": "new_branch", "content": "Modified contents", "commit_message": "File was modified for this new branch"}' ``` which results in error being returned: ``` {"message":"You can only create or edit files when you are on a branch"} ``` It should instead be sent a body attribute, which succeeds in creating the branch during the save. To be sent as body attribute it must be specified as concrete function argument and class attribute instead of just using kwargs Closes: #3318
1 parent 4a8d82b commit 1001d93

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

gitlab/v4/objects/files.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ProjectFile(SaveMixin, ObjectDeleteMixin, RESTObject):
2929
file_path: str
3030
manager: ProjectFileManager
3131
content: str # since the `decode()` method uses `self.content`
32+
start_branch: str | None = None
3233

3334
def decode(self) -> bytes:
3435
"""Returns the decoded content of the file.
@@ -41,7 +42,11 @@ def decode(self) -> bytes:
4142
# NOTE(jlvillal): Signature doesn't match SaveMixin.save() so ignore
4243
# type error
4344
def save( # type: ignore[override]
44-
self, branch: str, commit_message: str, **kwargs: Any
45+
self,
46+
branch: str,
47+
commit_message: str,
48+
start_branch: str | None = None,
49+
**kwargs: Any,
4550
) -> None:
4651
"""Save the changes made to the file to the server.
4752
@@ -50,6 +55,7 @@ def save( # type: ignore[override]
5055
Args:
5156
branch: Branch in which the file will be updated
5257
commit_message: Message to send with the commit
58+
start_branch: Name of the branch to start the new branch from
5359
**kwargs: Extra options to send to the server (e.g. sudo)
5460
5561
Raises:
@@ -58,6 +64,7 @@ def save( # type: ignore[override]
5864
"""
5965
self.branch = branch
6066
self.commit_message = commit_message
67+
self.start_branch = start_branch
6168
self.file_path = utils.EncodedId(self.file_path)
6269
super().save(**kwargs)
6370

0 commit comments

Comments
 (0)