Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
c13236a1
Commit
c13236a1
authored
Jun 13, 2018
by
Greg Messner
Browse files
Now allows for empty content when creating or updating a file (#197).
parent
69f26d01
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/RepositoryFileApi.java
View file @
c13236a1
...
@@ -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
);
}
}
...
...
src/test/java/org/gitlab4j/api/TestRepositoryApi.java
View file @
c13236a1
...
@@ -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
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment