From 87a4fa8b74609d21144550940614e1e304e68e3a Mon Sep 17 00:00:00 2001 From: Rene Pfeuffer Date: Wed, 11 Sep 2019 10:51:26 +0200 Subject: [PATCH 1/2] Remove leading slashes when changing files in git --- .../scm/repository/spi/GitModifyCommand.java | 17 ++++++++++++++--- .../repository/spi/GitModifyCommandTest.java | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitModifyCommand.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitModifyCommand.java index 9a8cf7e16a..0f7c9296a7 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitModifyCommand.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitModifyCommand.java @@ -88,7 +88,7 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman } } try { - getClone().add().addFilepattern(toBeCreated).call(); + addFileToGit(toBeCreated); } catch (GitAPIException e) { throwInternalRepositoryException("could not add new file to index", e); } @@ -103,12 +103,16 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman } Files.move(file.toPath(), targetFile, REPLACE_EXISTING); try { - getClone().add().addFilepattern(path).call(); + addFileToGit(path); } catch (GitAPIException e) { throwInternalRepositoryException("could not add new file to index", e); } } + private void addFileToGit(String toBeCreated) throws GitAPIException { + getClone().add().addFilepattern(removeStartingPathSeparators(toBeCreated)).call(); + } + @Override public void delete(String toBeDeleted) throws IOException { Path fileToBeDeleted = new File(workDir, toBeDeleted).toPath(); @@ -118,12 +122,19 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman throw notFound(createFileContext(toBeDeleted)); } try { - getClone().rm().addFilepattern(toBeDeleted).call(); + getClone().rm().addFilepattern(removeStartingPathSeparators(toBeDeleted)).call(); } catch (GitAPIException e) { throwInternalRepositoryException("could not remove file from index", e); } } + private String removeStartingPathSeparators(String path) { + while (path.startsWith(File.separator)) { + path = path.substring(1); + } + return path; + } + private void createDirectories(Path targetFile) throws IOException { try { Files.createDirectories(targetFile.getParent()); diff --git a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitModifyCommandTest.java b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitModifyCommandTest.java index 0e0447f1fa..4fbf7eaf02 100644 --- a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitModifyCommandTest.java +++ b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitModifyCommandTest.java @@ -97,6 +97,24 @@ public class GitModifyCommandTest extends AbstractGitCommandTestBase { assertInTree(assertions); } + @Test + public void shouldCreateNewFileWhenPathStartsWithSlash() throws IOException, GitAPIException { + File newFile = Files.write(temporaryFolder.newFile().toPath(), "new content".getBytes()).toFile(); + + GitModifyCommand command = createCommand(); + + ModifyCommandRequest request = new ModifyCommandRequest(); + request.setCommitMessage("test commit"); + request.addRequest(new ModifyCommandRequest.CreateFileRequest("/new_file", newFile, false)); + request.setAuthor(new Person("Dirk Gently", "dirk@holistic.det")); + + command.execute(request); + + TreeAssertions assertions = canonicalTreeParser -> assertThat(canonicalTreeParser.findFile("new_file")).isTrue(); + + assertInTree(assertions); + } + @Test(expected = AlreadyExistsException.class) public void shouldFailIfOverwritingExistingFileWithoutOverwriteFlag() throws IOException { File newFile = Files.write(temporaryFolder.newFile().toPath(), "new content".getBytes()).toFile(); From df78c90510377273a31a6117a70e6fd4af91a4ce Mon Sep 17 00:00:00 2001 From: Rene Pfeuffer Date: Wed, 11 Sep 2019 11:21:50 +0200 Subject: [PATCH 2/2] Fix german texts in english resource file --- scm-ui/public/locales/en/admin.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scm-ui/public/locales/en/admin.json b/scm-ui/public/locales/en/admin.json index 7c9adff4f9..99febb68fc 100644 --- a/scm-ui/public/locales/en/admin.json +++ b/scm-ui/public/locales/en/admin.json @@ -70,13 +70,13 @@ "submit": "Save" }, "delete": { - "button": "Löschen", - "subtitle": "Berechtigungsrolle löschen", + "button": "Delete", + "subtitle": "Delete permission role", "confirmAlert": { - "title": "Berechtigungsrolle löschen", - "message": "Soll die Berechtigungsrolle wirklich gelöscht werden? Alle Nutzer dieser Rolle verlieren Ihre Berechtigungen.", - "submit": "Ja", - "cancel": "Nein" + "title": "Delete permission role", + "message": "Do you really want to delete this permission role? All users will lose their corresponding permissions.", + "submit": "Yes", + "cancel": "No" } } }