From 6d70f5cd412209b2cd8cd951f9a5ce97a379ae74 Mon Sep 17 00:00:00 2001 From: ymikhailenko Date: Thu, 29 Dec 2022 19:51:14 -0800 Subject: [PATCH] #891: Pass start_branch param in RepositoryFileApi.updateFile form When committing to non-existent branch on a project with other branches, API throws 400 Bad Request with {message: "You can only create or edit files when you are on a branch"}. To avoid it you need to pass start_branch param. --- src/main/java/org/gitlab4j/api/RepositoryFileApi.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gitlab4j/api/RepositoryFileApi.java b/src/main/java/org/gitlab4j/api/RepositoryFileApi.java index 4fd5e6e3b..812b495b0 100644 --- a/src/main/java/org/gitlab4j/api/RepositoryFileApi.java +++ b/src/main/java/org/gitlab4j/api/RepositoryFileApi.java @@ -451,6 +451,7 @@ protected Form createForm(RepositoryFile file, String branchName, String commitM } else { addFormParam(form, "branch", branchName, true); } + addFormParam(form, "start_branch", file.getRef(), false); addFormParam(form, "encoding", file.getEncoding(), false); @@ -515,4 +516,4 @@ public Pager getBlame(Object projectIdOrPath, String filePath, String ref public Stream getBlameStream(Object projectIdOrPath, String filePath, String ref) throws GitLabApiException { return (getBlame(projectIdOrPath, filePath, ref, getDefaultPerPage()).stream()); } -} \ No newline at end of file +}