Throw NoChangesMadeException for empty commits in SVN repositories

Committed-by: Florian Scholdei <florian.scholdei@cloudogu.com>
This commit is contained in:
Eduard Heimbuch
2023-08-07 23:17:25 +02:00
parent 8cafeefc74
commit 33e8d30b62
4 changed files with 17 additions and 1 deletions

View File

@@ -29,7 +29,6 @@ import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tmatesoft.svn.core.ISVNLogEntryHandler;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNLogEntry;
import org.tmatesoft.svn.core.io.SVNRepository;

View File

@@ -35,6 +35,7 @@ import org.tmatesoft.svn.core.wc.SVNWCClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
import sonia.scm.ConcurrentModificationException;
import sonia.scm.ContextEntry;
import sonia.scm.NoChangesMadeException;
import sonia.scm.repository.InternalRepositoryException;
import sonia.scm.repository.Repository;
import sonia.scm.repository.SvnWorkingCopyFactory;
@@ -112,6 +113,9 @@ public class SvnModifyCommand implements ModifyCommand {
true,
SVNDepth.INFINITY
);
if (svnCommitInfo.toString().equals("EMPTY COMMIT")) {
throw new NoChangesMadeException(repository);
}
return String.valueOf(svnCommitInfo.getNewRevision());
} catch (SVNException e) {
throw withPattern(SVN_ERROR_PATTERN).forMessage(repository, e.getErrorMessage().getRootErrorMessage().getFullMessage());

View File

@@ -35,6 +35,7 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import sonia.scm.AlreadyExistsException;
import sonia.scm.ConcurrentModificationException;
import sonia.scm.NoChangesMadeException;
import sonia.scm.ScmConstraintViolationException;
import sonia.scm.repository.Person;
import sonia.scm.repository.api.FileLock;
@@ -124,6 +125,16 @@ public class SvnModifyCommandTest extends AbstractSvnCommandTestBase {
assertThat(new File(workingCopy.getWorkingRepository(), "Test123")).exists();
}
@Test
public void shouldThrowNoChangesMadeExceptionIfEmptyCommit() throws IOException {
File testfile = temporaryFolder.newFile("Test123");
ModifyCommandRequest request = prepareModifyCommandRequest();
request.addRequest(new ModifyCommandRequest.ModifyFileRequest("g/h/j.txt", testfile));
assertThrows(NoChangesMadeException.class, () -> svnModifyCommand.execute(request));
}
@Test
public void shouldAddNewFileInDefaultPath() throws IOException {
File testfile = temporaryFolder.newFile("Test123");