Commit c13236a1 authored by Greg Messner's avatar Greg Messner
Browse files

Now allows for empty content when creating or updating a file (#197).

parent 69f26d01
...@@ -226,7 +226,14 @@ public class RepositoryFileApi extends AbstractApi { ...@@ -226,7 +226,14 @@ public class RepositoryFileApi extends AbstractApi {
} }
addFormParam(form, "encoding", file.getEncoding(), false); addFormParam(form, "encoding", file.getEncoding(), false);
addFormParam(form, "content", file.getContent(), true);
// Cannot use addFormParam() as it does not accept an empty or whitespace only string
String content = file.getContent();
if (content == null) {
throw new IllegalArgumentException("content cannot be null");
}
form.param("content", content);
addFormParam(form, "commit_message", commitMessage, true); addFormParam(form, "commit_message", commitMessage, true);
return (form); return (form);
} }
......
...@@ -236,6 +236,21 @@ public class TestRepositoryApi { ...@@ -236,6 +236,21 @@ public class TestRepositoryApi {
gitLabApi.getRepositoryFileApi().deleteFile(TEST_FILEPATH, project.getId(), TEST_BRANCH_NAME, "Testing deleteFile()."); gitLabApi.getRepositoryFileApi().deleteFile(TEST_FILEPATH, project.getId(), TEST_BRANCH_NAME, "Testing deleteFile().");
} }
@Test
public void testCreateFileWithEmptyContent() throws GitLabApiException {
Project project = gitLabApi.getProjectApi().getProject(TEST_NAMESPACE, TEST_PROJECT_NAME);
assertNotNull(project);
RepositoryFile file = new RepositoryFile();
file.setFilePath(TEST_FILEPATH);
file.setContent("");
RepositoryFile createdFile = gitLabApi.getRepositoryFileApi().createFile(file, project.getId(), TEST_BRANCH_NAME, "Testing createFile().");
assertNotNull(createdFile);
gitLabApi.getRepositoryFileApi().deleteFile(TEST_FILEPATH, project.getId(), TEST_BRANCH_NAME, "Testing deleteFile().");
}
@Test @Test
public void testProtectBranch() throws GitLabApiException { public void testProtectBranch() throws GitLabApiException {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment